-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from /issues/10
Update unit test
- Loading branch information
Showing
7 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly:InternalsVisibleTo("PropertyValidator.Test")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/PropertyValidator.Test/Exceptions/PropertyException.test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using PropertyValidator.Models; | ||
|
||
namespace PropertyValidator.Test.Exceptions; | ||
|
||
public class PropertyException | ||
{ | ||
[Test, Description("Must be able to get the empty ValidationResultArgs.")] | ||
public void MustGetEmptyResultArgs() | ||
{ | ||
var exception = | ||
new PropertyValidator.Exceptions.PropertyException( | ||
new ValidationResultArgs( | ||
new Dictionary<string, IEnumerable<string?>>() | ||
) | ||
); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(exception.ValidationResultArgs.HasError, Is.EqualTo(false)); | ||
Assert.That(exception.ValidationResultArgs.FirstError, Is.Null); | ||
Assert.That(exception.ValidationResultArgs.ErrorMessages, Is.Null); | ||
Assert.That(exception.ValidationResultArgs.ErrorDictionary, Is.Empty); | ||
}); | ||
} | ||
|
||
[Test, Description("Must be able to get the non-empty ValidationResultArgs.")] | ||
[TestCase("A", new[] { "1st", "2nd" })] | ||
[TestCase("B", new[] { "1st", "2nd", "3rd" })] | ||
[TestCase("C", new[] { "1st", "2nd", "3rd", "4th" })] | ||
public void MustGetNonEmptyResultArgs(string propertyName, IEnumerable<string> errorMessages) | ||
{ | ||
var exception = | ||
new PropertyValidator.Exceptions.PropertyException( | ||
new ValidationResultArgs( | ||
new Dictionary<string, IEnumerable<string?>> | ||
{ | ||
{ propertyName, errorMessages } | ||
} | ||
) | ||
); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(exception.ValidationResultArgs.HasError, Is.EqualTo(true)); | ||
Assert.That(exception.ValidationResultArgs.FirstError, Is.Not.Null); | ||
Assert.That(exception.ValidationResultArgs.ErrorMessages, Is.Not.Null); | ||
Assert.That(exception.ValidationResultArgs.ErrorDictionary, Is.Not.Empty); | ||
Assert.That(exception.ValidationResultArgs.FirstError, Is.EqualTo("1st")); | ||
Assert.That(exception.ValidationResultArgs.ErrorMessages, Contains.Item("2nd")); | ||
Assert.That(exception.ValidationResultArgs.ErrorDictionary.Values.SelectMany(x => x), Contains.Item("2nd")); | ||
}); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
test/PropertyValidator.Test/Helpers/ReflectionHelper.test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace PropertyValidator.Test.Helpers; | ||
|
||
public class ReflectionHelper | ||
{ | ||
private class Dummy | ||
{ | ||
private readonly int x = 1; | ||
private readonly string y = "2"; | ||
|
||
public int GetX() => x; | ||
public string GetY() => y; | ||
} | ||
|
||
[Test, Description("Must retrieve the fields and set their values.")] | ||
public void GetFieldTest() | ||
{ | ||
var propX = PropertyValidator.Helpers.ReflectionHelper.GetField(typeof(Dummy), "x"); | ||
var propY = PropertyValidator.Helpers.ReflectionHelper.GetField(typeof(Dummy), "y"); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(propX, Is.Not.Null); | ||
Assert.That(propY, Is.Not.Null); | ||
}); | ||
|
||
Dummy dummy = new(); | ||
propX?.SetValue(dummy, 2); | ||
propY?.SetValue(dummy, "1"); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(dummy.GetX(), Is.EqualTo(2)); | ||
Assert.That(dummy.GetY(), Is.EqualTo("1")); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters