public void Validate_TwoStepsWithBreak_DoesStepsValidationOnlyForFirstStep() { var validationContext = A.Fake <IValidationContext <TestDataObject> >(); var validationStep = A.Fake <IPropertyValidationStep <TestDataObject, string> >(); var validationStep2 = A.Fake <IPropertyValidationStep <TestDataObject, string> >(); var testData = A.Fake <TestDataObject>(); testData.StrValue = "Test"; A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); A.CallTo(() => validationContext.BreakRuleValidationAfterFirstFailedValidation).Returns(true); var rule = new PropertyValidationRule <TestDataObject, string>(x => x.StrValue); rule.AddValidationStep(validationStep); rule.AddValidationStep(validationStep2); rule.Validate(validationContext); A.CallTo(() => validationStep.Validate( A <IPropertyValidationContext <TestDataObject, string> > .That.Matches(x => x.InstanceForValidation == testData))) .MustHaveHappenedOnceExactly(); A.CallTo(() => validationStep2.Validate( A <IPropertyValidationContext <TestDataObject, string> > ._)) .MustNotHaveHappened(); }
public void Validate_OneStep_AddFaults() { var validationContext = A.Fake <IValidationContext <TestDataObject> >(); var validationStep = A.Fake <IPropertyValidationStep <TestDataObject, string> >(); var testData = A.Fake <TestDataObject>(); testData.StrValue = "Test"; var validationFault = A.Fake <IValidationFault>(); A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); A.CallTo(() => validationStep.Validate(A <IPropertyValidationContext <TestDataObject, string> > ._)) .Invokes((IPropertyValidationContext <TestDataObject, string> context) => context.AddFault(validationFault)) .Returns(false); var rule = new PropertyValidationRule <TestDataObject, string>(x => x.StrValue); rule.AddValidationStep(validationStep); rule.Validate(validationContext); A.CallTo(() => validationContext.AddFaults(A <IEnumerable <IValidationFault> > .That.IsSameSequenceAs(validationFault))) .MustHaveHappenedOnceExactly(); }
public void Validate_OneStepWithTrueCondition_DoesStepValidation() { var validationContext = A.Fake <IValidationContext <TestDataObject> >(); var validationStep = A.Fake <IPropertyValidationStep <TestDataObject, string> >(); var testData = A.Fake <TestDataObject>(); testData.StrValue = "Test"; A.CallTo(() => validationContext.InstanceForValidation).Returns(testData); var rule = new PropertyValidationRule <TestDataObject, string>(x => x.StrValue); rule.AddValidationStep(validationStep); rule.SetCondition(_ => true); rule.Validate(validationContext); A.CallTo(() => validationStep.Validate( A <IPropertyValidationContext <TestDataObject, string> > ._)) .MustHaveHappenedOnceExactly(); }