public void EvaluateShouldReturnSuccessForNonNullValue() { // arrange var rule = new RequiredRule<object>(); var property = new Property<object>( "Object", new object() ); var expected = ValidationResult.Success; // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual ); }
public void EvaluateShouldReturnSuccessForEmptyString() { // arrange var rule = new RequiredRule<string>() { AllowEmptyStrings = true }; var property = new Property<string>( "Text", "" ); var expected = ValidationResult.Success; // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual ); }
public void EvaluateShouldReturnExpectedResultForNullValue() { // arrange var rule = new RequiredRule<object>(); var property = new Property<object>( "Object", null ); // act var actual = rule.Evaluate( property ); // assert Assert.Equal( "The Object field is required.", actual.ErrorMessage ); Assert.Equal( 1, actual.MemberNames.Count() ); Assert.Equal( "Object", actual.MemberNames.Single() ); }
public void EvaluateShouldReturnExpectedResultForNullOrEmptyString( string value ) { // arrange var rule = new RequiredRule<string>(); var property = new Property<string>( "Text", value ); // act var actual = rule.Evaluate( property ); // assert Assert.Equal( "The Text field is required.", actual.ErrorMessage ); Assert.Equal( 1, actual.MemberNames.Count() ); Assert.Equal( "Text", actual.MemberNames.Single() ); }
public void EvaluateShouldReturnResultWithCustomErrorMessageForString() { // arrange var expected = "Invalid"; var rule = new RequiredRule<string>( expected ); var property = new Property<string>( "Text", null ); // act var actual = rule.Evaluate( property ); // assert Assert.Equal( expected, actual.ErrorMessage ); }