public void Valid_Parent_Fails_When_Successor_Fails_Validation() { var rule1 = new TrueRule().IfValidThenValidate(new FalseRule1()).Validate(); rule1.IsValid.ShouldBe(false); rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void Allows_access_to_successor_rules_via_IRulesContainer_interface() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new FalseRule2()) .IfValidThenValidate ( new TrueRule().IfValidThenValidate(new FalseRule1()), new FalseRule3() ); rule.GetSuccessors().Count().ShouldBe(2); var firstSuccessor = rule.GetSuccessors().First(); firstSuccessor.Rules.Count().ShouldBe(2); firstSuccessor.Rules.First().ShouldBeOfType <TrueRule>(); firstSuccessor.Rules.Second().ShouldBeOfType <FalseRule2>(); var secondSuccessor = rule.GetSuccessors().Second(); secondSuccessor.Rules.Count().ShouldBe(2); secondSuccessor.Rules.First().ShouldBeOfType <TrueRule>(); secondSuccessor.Rules.First().GetSuccessors().Count().ShouldBe(1); secondSuccessor.Rules.First().GetSuccessors().First().Rules.First().ShouldBeOfType <FalseRule1>(); secondSuccessor.Rules.Second().ShouldBeOfType <FalseRule3>(); }
public void Allows_access_to_successor_rules_via_IRulesContainer_interface() { var output = string.Empty; var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new FalseRule2()) .IfValidThenValidate ( new TrueRule().IfValidThenValidate(new FalseRule1()), new FalseRule3() ); var successors = (rule as IRulesContainer).Rules; successors.Count.ShouldBe(2); var firstSuccessors = successors.First(); firstSuccessors.Count().ShouldBe(2); firstSuccessors.First().ShouldBeOfType <TrueRule>(); (firstSuccessors.First() as IRulesContainer).Rules.Count().ShouldBe(0); firstSuccessors.Last().ShouldBeOfType <FalseRule2>(); (firstSuccessors.Last() as IRulesContainer).Rules.Count().ShouldBe(0); var lastSuccessors = successors.Last(); lastSuccessors.Count().ShouldBe(2); lastSuccessors.First().ShouldBeOfType <TrueRule>(); (lastSuccessors.First() as IRulesContainer).Rules.Count().ShouldBe(1); (lastSuccessors.First() as IRulesContainer).Rules.First().First().ShouldBeOfType <FalseRule1>(); lastSuccessors.Last().ShouldBeOfType <FalseRule3>(); }
public void Three_Rule_Chain_Executes_Successfully() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule() .IfValidThenValidate(new TrueRule())).Validate(); rule.IsValid.ShouldBe(true); }
public void ThreeRuleChainFailSkipsThirdInChainWhenSecondFails() { var rule = new TrueRule() .IfValidThenValidate(new FalseRule1() .IfValidThenValidate(new FalseRule2())).Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void Three_Rule_Chain_Hits_Third_In_Chain_And_Fails_Parent() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule() .IfValidThenValidate(new FalseRule1())).Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void All_Remaining_Successors_Skip_Validation_When_First_Successor_Fails() { var rule1 = new TrueRule() .IfValidThenValidate(new FalseRule1(), new FalseRule2(), new FalseRule3()) .Validate(); rule1.IsValid.ShouldBe(false); rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void AllRemainingSuccessorsSkipValidationWhenFirstSuccessorFails() { var rule1 = new TrueRule() .IfValidThenValidate(new FalseRule1(), new FalseRule2(), new FalseRule3()) .Validate(); rule1.IsValid.ShouldBe(false); rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public async Task The_Correct_Association_Is_Set_As_A_Result_Of_Failed_Successor_Async() { var rule = new TrueRule("Foo") .IfValidThenValidate(new TrueRule(), new FalseRuleWithAssociation("Address")); await rule.ValidateAsync(); rule.Association.ShouldBe("Address"); rule.ErrorMessage.ShouldBe("Address failed validation"); }
public void ThreeRuleChainHitsThirdInChainAndFailsParent() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule() .IfValidThenValidate(new FalseRule1())).Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void Three_Rule_Chain_Fail_Skips_Third_In_Chain_When_Second_Fails() { var rule = new TrueRule() .IfValidThenValidate(new FalseRule1() .IfValidThenValidate(new FalseRule2())).Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void Last_Successor_Validates_When_First_Successors_Pass() { var rule1 = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule(), new FalseRule1()) .Validate(); rule1.IsValid.ShouldBe(false); rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation"); }
public void Parent_Fails_When_Last_Successor_In_Chains_Fails_Validation() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new TrueRule(), new FalseRule3()) .Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule3 failed validation"); }
public void ParentFailsWhenLastSuccessorInChainsFailsValidation() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new TrueRule(), new FalseRule3()) .Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule3 failed validation"); }
public void LastSuccessorInSuccessorChainIsSkippedWhenFirstSuccessorsPass() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new FalseRule2(), new FalseRule3()) .Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule2 failed validation"); }
public void SecondInvalidRuleInSecondSuccessorChainShouldExecute() { var output = string.Empty; var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new TrueRule(), new FalseRule3().IfInvalidThenExecute(r => output = "pass")) .Validate(); output.ShouldBe("pass"); }
public void Last_Successor_In_Successor_Chain_Is_Skipped_When_First_Successors_Pass() { var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new FalseRule2(), new FalseRule3()) .Validate(); rule.IsValid.ShouldBe(false); rule.ErrorMessage.ShouldBe("FalseRule2 failed validation"); }
public void Second_Invalid_Rule_In_Second_Successor_Chain_Should_Execute() { var output = string.Empty; var rule = new TrueRule() .IfValidThenValidate(new TrueRule(), new TrueRule()) .IfValidThenValidate(new TrueRule(), new FalseRule3().IfInvalidThenExecute(r => output = "pass")) .Validate(); output.ShouldBe("pass"); }
public void FirstValidRuleInSecondSuccessorChainShouldExecuteButThirdFalseRuleShouldNot() { var output = string.Empty; var output2 = string.Empty; var rule = new TrueRule() .IfValidThenValidate(new TrueRule().IfValidThenExecute(r => output = "pass"), new TrueRule()) .IfValidThenValidate(new FalseRule2().IfValidThenExecute(r => output2 = "pass"), new FalseRule3()) .Validate(); output.ShouldBe("pass"); output2.ShouldBe(string.Empty); rule.ErrorMessage.ShouldBe("FalseRule2 failed validation"); }
public void First_Valid_Rule_In_Second_Successor_Chain_Should_Execute_But_Third_False_Rule_Should_Not() { var output = string.Empty; var output2 = string.Empty; var rule = new TrueRule() .IfValidThenValidate(new TrueRule().IfValidThenExecute(r => output = "pass"), new TrueRule()) .IfValidThenValidate(new FalseRule2().IfValidThenExecute(r => output2 = "pass"), new FalseRule3()) .Validate(); output.ShouldBe("pass"); output2.ShouldBe(string.Empty); rule.ErrorMessage.ShouldBe("FalseRule2 failed validation"); }
public void ValidRuleIsValidAfterValidation() { var rule = new TrueRule().Validate(); rule.IsValid.ShouldBe(true); }
public void ValidRuleDoesNotContainAnErrorMessageAfterValidation() { var rule = new TrueRule().Validate(); rule.ErrorMessage.ShouldBe(null); }
public void Valid_Rule_Does_Not_Contain_An_Error_Message_After_Validation() { var rule = new TrueRule().Validate(); rule.ErrorMessage.ShouldBe(null); }
public void Valid_Rule_Is_Valid_After_Validation() { var rule = new TrueRule().Validate(); rule.IsValid.ShouldBe(true); }