-
Notifications
You must be signed in to change notification settings - Fork 3
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 tgharold/tests-tests-tests-1
Remove generics, add tests, address a Rider warning, refactoring
- Loading branch information
Showing
9 changed files
with
152 additions
and
18 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
examples/OptionsPatternMvc.Example/Settings/ExampleAppSettings.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
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
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
58 changes: 58 additions & 0 deletions
58
test/RecursiveDataAnnotationsValidation.Tests/RecursiveDataAnnotationValidatorTests.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,58 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using RecursiveDataAnnotationsValidation.Tests.TestModels; | ||
using Xunit; | ||
|
||
namespace RecursiveDataAnnotationsValidation.Tests | ||
{ | ||
public class RecursiveDataAnnotationValidatorTests | ||
{ | ||
/// <summary>Tests that use the method which takes a ValidationContext.</summary> | ||
public class ValidationContextTests | ||
{ | ||
private readonly IRecursiveDataAnnotationValidator _validator = new RecursiveDataAnnotationValidator(); | ||
|
||
[Fact] | ||
public void Pass_all_validation() | ||
{ | ||
var sut = new SimpleExample | ||
{ | ||
IntegerA = 100, | ||
StringB = "test-100", | ||
BoolC = true, | ||
ExampleEnumD = ExampleEnum.ValueB | ||
}; | ||
|
||
var validationContext = new ValidationContext(sut); | ||
var validationResults = new List<ValidationResult>(); | ||
var result = _validator.TryValidateObjectRecursive(sut, validationContext, validationResults); | ||
|
||
Assert.True(result); | ||
Assert.Empty(validationResults); | ||
} | ||
|
||
[Fact] | ||
public void Indicate_that_IntegerA_is_missing() | ||
{ | ||
var sut = new SimpleExample | ||
{ | ||
IntegerA = null, | ||
StringB = "test-101", | ||
BoolC = false, | ||
ExampleEnumD = ExampleEnum.ValueC | ||
}; | ||
|
||
const string fieldName = nameof(SimpleExample.IntegerA); | ||
var validationContext = new ValidationContext(sut); | ||
var validationResults = new List<ValidationResult>(); | ||
var result = _validator.TryValidateObjectRecursive(sut, validationContext, validationResults); | ||
|
||
Assert.False(result); | ||
Assert.NotEmpty(validationResults); | ||
Assert.NotNull(validationResults | ||
.FirstOrDefault(x => x.MemberNames.Contains(fieldName))); | ||
} | ||
} | ||
} | ||
} |
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