private static bool IsValid(Action <IPropertyRuleBuilder <TestDataObject, double> > setupRule, double floatValue) { var validator = new TestDataObjectValidator(v => setupRule(v.RuleFor(x => x.FloatValue))); var testData = new TestDataObject { FloatValue = floatValue }; var validationResult = validator.Validate(testData); return(validationResult.IsValid); }
public void Validate_StrValueNotNull_StrValueNullReturnsInvalid() { var validator = new TestDataObjectValidator(v => v.RuleFor(x => x.StrValue).IsNotNull()); var testData = new TestDataObject(); var validationResult = validator.Validate(testData); Assert.False(validationResult.IsValid); Assert.Single(validationResult.Faults); Assert.Equal("StrValue", validationResult.Faults.First().PropertyName); }
private static bool IsValid(Action <IPropertyRuleBuilder <TestDataObject, string> > setupRule, string strValue) { var validator = new TestDataObjectValidator(v => setupRule(v.RuleFor(x => x.StrValue))); var testData = new TestDataObject { StrValue = strValue }; var validationResult = validator.Validate(testData); return(validationResult.IsValid); }
private static bool IsValidList(Action <IPropertyRuleBuilder <TestDataObject, IList <string> > > setupRule, IEnumerable <string> strItems) { var validator = new TestDataObjectValidator(v => setupRule(v.RuleFor(x => x.StrList))); var testData = new TestDataObject { StrList = strItems.ToList() }; var validationResult = validator.Validate(testData); return(validationResult.IsValid); }
private static bool IsValidObjects(Action <IPropertyRuleBuilder <TestDataObject, IEnumerable> > setupRule, IEnumerable items) { var validator = new TestDataObjectValidator(v => setupRule(v.RuleFor(x => x.ObjItems))); var testData = new TestDataObject { ObjItems = items }; var validationResult = validator.Validate(testData); return(validationResult.IsValid); }
public void ValidateNoneGeneric_StrValueNotNull_StrValueNotNullReturnsValid() { var validator = new TestDataObjectValidator(v => v.RuleFor(x => x.StrValue).IsNotNull()); var testData = new TestDataObject { StrValue = "Test" } as object; var validationResult = validator.Validate(testData); Assert.True(validationResult.IsValid); Assert.Empty(validationResult.Faults); }
public void Validate_StrValueNotNullIfThenFalse_StrValueNullReturnsInvalid() { var validator = new TestDataObjectValidator(v => v .RuleFor(x => x.StrValue) .IfThen(_ => false) .IsNotNull()); var testData = new TestDataObject(); var validationResult = validator.Validate(testData); Assert.True(validationResult.IsValid); Assert.Empty(validationResult.Faults); }
public void ValidateStrValue_StrValueNotNullIntValueGreater100_StrValueNullIntValue0ReturnsInvalid() { var validator = new TestDataObjectValidator(v => { v.RuleFor(x => x.StrValue).IsNotNull(); v.RuleFor(x => x.IntValue).Must((_, i) => i > 100); }); var testData = new TestDataObject(); var validationResult = validator.Validate(testData, "StrValue"); Assert.False(validationResult.IsValid); Assert.Single(validationResult.Faults); Assert.Equal("StrValue", validationResult.Faults.First().PropertyName); }
public void PropertyValue_StrProperty_ReturnsStrValue() { var testData = new TestDataObject { StrValue = "Test text" }; var validationContext = A.Fake <IValidationContext <TestDataObject> >(); A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); var propertyValidationContext = new PropertyValidationContext <TestDataObject, string>(x => x.StrValue, validationContext); var value = propertyValidationContext.PropertyValue; Assert.Equal("Test text", value); }
public void InstanceForValidation_Get_ReturnCorrectValue() { var testData = new TestDataObject { StrValue = "Test text" }; var validationContext = A.Fake <IValidationContext <TestDataObject> >(); A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); var propertyValidationContext = new PropertyValidationContext <TestDataObject, string>(x => x.StrValue, validationContext); var instanceForValidation = propertyValidationContext.InstanceForValidation; Assert.Equal(testData, instanceForValidation); }
public void ValidateStrValue_StrValueNotNullIntValueGreater100_StrValueNotNullIntValue0ReturnsValid() { var validator = new TestDataObjectValidator(v => { v.RuleFor(x => x.StrValue).IsNotNull(); v.RuleFor(x => x.IntValue).Must((_, i) => i > 100); }); var testData = new TestDataObject { StrValue = "Test" }; var validationResult = validator.Validate(testData, "StrValue"); Assert.True(validationResult.IsValid); Assert.Empty(validationResult.Faults); }
public void ValidateWithBreakRuleFalse_StrValueNotNullIntValueGreater100_StrValueNullIntValue0ReturnsInvalid() { var validator = new TestDataObjectValidator(v => { v.RuleFor(x => x.StrValue).IsNotNull().HasMinimumLength(10); v.RuleFor(x => x.IntValue).Must((_, i) => i > 100); }); var testData = new TestDataObject { IntValue = 101 }; var validationResult = validator.Validate(testData, false); Assert.False(validationResult.IsValid); Assert.Equal(2, validationResult.Faults.Count()); Assert.Equal("StrValue", validationResult.Faults.First().PropertyName); Assert.Equal("StrValue", validationResult.Faults.Last().PropertyName); }
public void PropertyValue_GetStrPropertyMultipleTimes_ReturnsAlwaysTheSameResult() { var testData = new TestDataObject { StrValue = "Test text" }; var validationContext = A.Fake <IValidationContext <TestDataObject> >(); A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); var propertyValidationContext = new PropertyValidationContext <TestDataObject, string>(x => x.StrValue, validationContext); var value = propertyValidationContext.PropertyValue; Assert.Equal("Test text", value); var value1 = propertyValidationContext.PropertyValue; Assert.Equal(value, value1); }