Ejemplo n.º 1
0
        public void Valid_Parent_Fails_When_Successor_Fails_Validation()
        {
            var rule1 = new SynchronousTrueRule().IfValidThenValidate(new SynchronousFalseRule1()).Execute();

            rule1.IsValid.ShouldBe(false);
            rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Ejemplo n.º 2
0
        public void Allows_access_to_successor_rules_via_IRulesContainer_interface()
        {
            var rule = new SynchronousTrueRule()
                       .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousFalseRule2())
                       .IfValidThenValidate
                       (
                new SynchronousTrueRule().IfValidThenValidate(new SynchronousFalseRule1()),
                new SynchronousFalseRule3()
                       );

            rule.GetSuccessors().Count().ShouldBe(2);

            var firstSuccessor = rule.GetSuccessors().First();

            firstSuccessor.Rules.Count().ShouldBe(2);
            firstSuccessor.Rules.First().ShouldBeOfType <SynchronousTrueRule>();
            firstSuccessor.Rules.Second().ShouldBeOfType <SynchronousFalseRule2>();

            var secondSuccessor = rule.GetSuccessors().Second();

            secondSuccessor.Rules.Count().ShouldBe(2);
            secondSuccessor.Rules.First().ShouldBeOfType <SynchronousTrueRule>();
            secondSuccessor.Rules.First().GetSuccessors().Count().ShouldBe(1);
            secondSuccessor.Rules.First().GetSuccessors().First().Rules.First().ShouldBeOfType <SynchronousFalseRule1>();
            secondSuccessor.Rules.Second().ShouldBeOfType <SynchronousFalseRule3>();
        }
Ejemplo n.º 3
0
        public void Three_Rule_Chain_Executes_Successfully()
        {
            var rule = new SynchronousTrueRule()
                       .IfValidThenValidate(new SynchronousTrueRule()
                                            .IfValidThenValidate(new SynchronousTrueRule())).Execute();

            rule.IsValid.ShouldBe(true);
        }
Ejemplo n.º 4
0
        public void Last_Successor_Validates_When_First_Successors_Pass()
        {
            var rule1 = new SynchronousTrueRule()
                        .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousTrueRule(), new SynchronousFalseRule1())
                        .Execute();

            rule1.IsValid.ShouldBe(false);
            rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Ejemplo n.º 5
0
        public void All_Remaining_Successors_Skip_Validation_When_First_Successor_Fails()
        {
            var rule1 = new SynchronousTrueRule()
                        .IfValidThenValidate(new SynchronousFalseRule1(), new SynchronousFalseRule2(), new SynchronousFalseRule3())
                        .Execute();

            rule1.IsValid.ShouldBe(false);
            rule1.ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Ejemplo n.º 6
0
        public void The_Correct_Association_Is_Set_As_A_Result_Of_Failed_Successor()
        {
            var rule = new SynchronousTrueRule("Foo")
                       .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousFalseRuleWithAssociation("Address"));

            rule.Execute();
            rule.Association.ShouldBe("Address");
            rule.ErrorMessage.ShouldBe("Address failed validation");
        }
Ejemplo n.º 7
0
        public void Three_Rule_Chain_Hits_Third_In_Chain_And_Fails_Parent()
        {
            var rule = new SynchronousTrueRule()
                       .IfValidThenValidate(new SynchronousTrueRule()
                                            .IfValidThenValidate(new SynchronousFalseRule1())).Execute();

            rule.IsValid.ShouldBe(false);
            rule.ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Ejemplo n.º 8
0
        public void Last_Successor_In_Successor_Chain_Is_Skipped_When_First_Successors_Pass()
        {
            var rule = new SynchronousTrueRule()
                       .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousTrueRule())
                       .IfValidThenValidate(new SynchronousFalseRule2(), new SynchronousFalseRule3())
                       .Execute();

            rule.IsValid.ShouldBe(false);
            rule.ErrorMessage.ShouldBe("FalseRule2 failed validation");
        }
Ejemplo n.º 9
0
        public void Second_Invalid_Rule_In_Second_Successor_Chain_Should_Execute()
        {
            var output = string.Empty;
            var rule   = new SynchronousTrueRule()
                         .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousTrueRule())
                         .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousFalseRule3().IfInvalidThenInvoke(r => output = "pass"))
                         .Execute();

            output.ShouldBe("pass");
        }
Ejemplo n.º 10
0
        public void Parent_Fails_When_Last_Successor_In_Chains_Fails_Validation()
        {
            var rule = new SynchronousTrueRule()
                       .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousTrueRule())
                       .IfValidThenValidate(new SynchronousTrueRule(), new SynchronousFalseRule3())
                       .Execute();

            rule.IsValid.ShouldBe(false);
            rule.ErrorMessage.ShouldBe("FalseRule3 failed validation");
        }
Ejemplo n.º 11
0
        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 SynchronousTrueRule()
                          .IfValidThenValidate(new SynchronousTrueRule().IfValidThenInvoke(r => output    = "pass"), new SynchronousTrueRule())
                          .IfValidThenValidate(new SynchronousFalseRule2().IfValidThenInvoke(r => output2 = "pass"), new SynchronousFalseRule3())
                          .Execute();

            output.ShouldBe("pass");
            output2.ShouldBe(string.Empty);
            rule.ErrorMessage.ShouldBe("FalseRule2 failed validation");
        }
Ejemplo n.º 12
0
        public void Valid_Rule_Does_Not_Contain_An_Error_Message_After_Validation()
        {
            var rule = new SynchronousTrueRule().Execute();

            rule.ErrorMessage.ShouldBe(null);
        }
Ejemplo n.º 13
0
        public void Valid_Rule_Is_Valid_After_Validation()
        {
            var rule = new SynchronousTrueRule().Execute();

            rule.IsValid.ShouldBe(true);
        }