public void Allows_Retrieval_Of_Configured_Rules()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousFalseRule1() };
            var command      = new SynchronousCommandStub(doerOfThings.Object, rules);

            command.GetRules().ShouldBe(rules);
        }
        public void Allows_Execution_Of_Configured_Rules()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousFalseRule1() };
            var command      = new SynchronousCommandStub(doerOfThings.Object, rules);

            var errors = command.Validate().Errors.ToArray();

            errors.Count().ShouldBe(1);
            errors.First().ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Esempio n. 3
0
        public void GetRules_Supports_ISynchronousCommand_Of_T()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousFalseRule1() };
            var command      = new SynchronousCommandBaseTestsOfT.SynchronousCommandStub(doerOfThings.Object, rules) as ISynchronousCommand <string>;
            var results      = command.GetRules();

            results.Count().ShouldBe(2);
            results.First().ShouldBeOfType <SynchronousTrueRule>();
            results.Second().ShouldBeOfType <SynchronousFalseRule1>();
        }
        public void Operation_Cannot_Complete_If_Any_Rules_Fail_Validation()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousFalseRule1() };
            var command      = new SynchronousCommandStub(doerOfThings.Object, rules);

            var result = command.Validate();

            result.CanContinue.ShouldBe(false);
            result.Errors.Count().ShouldBe(1);
            result.Errors.First().ErrorMessage.ShouldBe("FalseRule1 failed validation");
        }
Esempio n. 5
0
        public void SupportsProperEnumerator_Synchronous()
        {
            var rules = new ISynchronousRule[]
            {
                new SynchronousTrueRule(), new SynchronousFalseRule1(), new SynchronousTrueRule()
            };

            var successor = new RuleSuccessor <ISynchronousRule>(rules);
            var results   = successor.Select(r => r);

            results.Count().ShouldBe(3);
        }
Esempio n. 6
0
        public void Intializes_With_Synchronous_Rules_Appropriately()
        {
            var rules = new ISynchronousRule[]
            {
                new SynchronousTrueRule(), new SynchronousFalseRule1(), new SynchronousTrueRule()
            };

            var successor = new RuleSuccessor <ISynchronousRule>(rules);

            successor.Rules.Count().ShouldBe(3);
            successor.Rules.First().ShouldBeOfType <SynchronousTrueRule>();
            successor.Rules.Second().ShouldBeOfType <SynchronousFalseRule1>();
            successor.Rules.Third().ShouldBeOfType <SynchronousTrueRule>();
        }
        public void Operation_Can_Complete_If_Rules_Pass_Validation_And_Complete_Validation_With_Successful_Validation_Results()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousTrueRule() };
            var command      = new SynchronousCommandStub(doerOfThings.Object, rules);

            var validationResult = command.Validate();

            validationResult.CanContinue.ShouldBeTrue();
            validationResult.Errors.Count().ShouldBe(0);

            var executionResult = validationResult.CompleteCommandExecution();

            executionResult.Success.ShouldBeTrue();
        }
        public void Completion_Properly_Handles_Caught_Peasy_Exception()
        {
            var doerOfThings = new Mock <IDoThings>();

            doerOfThings.Setup(d => d.GetValue()).Throws(new PeasyException("You shall not pass"));
            var rules   = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousTrueRule() };
            var command = new SynchronousCommandStub(doerOfThings.Object, rules);

            var validationResult = command.Validate();

            validationResult.CanContinue.ShouldBeTrue();
            validationResult.Errors.Count().ShouldBe(0);

            var executionResult = validationResult.CompleteCommandExecution();

            executionResult.Success.ShouldBeFalse();
            executionResult.Errors.Count().ShouldBe(1);
            executionResult.Errors.First().ErrorMessage.ShouldBe("You shall not pass");
        }
        public void Fails_Execution_With_Expected_ExecutionResult_And_Method_Invocations_When_Any_Rules_Fail()
        {
            var doerOfThings = new Mock <IDoThings>();
            var rules        = new ISynchronousRule[] { new SynchronousTrueRule(), new SynchronousFalseRule1() };
            var command      = new SynchronousCommandStub(doerOfThings.Object, rules);

            var result = command.Execute();

            result.Success.ShouldBeFalse();
            result.Errors.Count().ShouldBe(1);
            result.Errors.First().ErrorMessage.ShouldBe("FalseRule1 failed validation");

            doerOfThings.Verify(d => d.Log("OnInitialization"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnValidate"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnGetRules"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnComplete"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnExecute"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnFailedExecution"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnPeasyExceptionHandled"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnSuccessfulExecution"), Times.Never);
        }
Esempio n. 10
0
 /// <summary>
 /// Wraps the rule in an array
 /// </summary>
 /// <returns>
 /// An array with a single rule of type <see cref="ISynchronousRule"/>
 /// </returns>
 /// <param name="rule">The rule of type <see cref="ISynchronousRule"/> to wrap in array.</param>
 public static IEnumerable <ISynchronousRule> ToArray(this ISynchronousRule rule)
 {
     return(new[] { rule });
 }
Esempio n. 11
0
 /// <summary>
 /// Synchronously invokes the rule.
 /// </summary>
 /// <returns>
 /// List of <see cref="System.ComponentModel.DataAnnotations.ValidationResult"/> if the rule fails execution.
 /// </returns>
 /// <param name="businessRule">A rule that implements <see cref="ISynchronousRule"/>.</param>
 /// <typeparam name="T">A type that inherits from <see cref="System.ComponentModel.DataAnnotations.ValidationResult"/>.</typeparam>
 public static IEnumerable <T> Validate <T>(this ISynchronousRule businessRule) where T : ValidationResult
 {
     return(ValidateAll <T>(businessRule.ToArray(), null));
 }
Esempio n. 12
0
 /// <summary>
 /// Synchronously invokes the rule.
 /// </summary>
 /// <returns>
 /// List of <see cref="System.ComponentModel.DataAnnotations.ValidationResult"/> if the rule fails execution.
 /// </returns>
 /// <param name="businessRule">A rule that implements <see cref="ISynchronousRule"/>.</param>
 public static IEnumerable <ValidationResult> Validate(this ISynchronousRule businessRule)
 {
     return(IRuleExtensions.ValidateAll(new [] { businessRule }, null));
 }