コード例 #1
0
        public async Task Operation_Can_Complete_If_Rules_Pass_Validation_And_Complete_Validation_With_Successful_Validation_Results()
        {
            var doerOfThings = new Mock <IDoThings>();

            doerOfThings.Setup(d => d.GetValue()).Returns("You shall pass");
            var rules   = new IRule[] { new TrueRule(), new TrueRule() };
            var command = new CommandStub(doerOfThings.Object, rules);

            var validationResult = await command.ValidateAsync();

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

            var executionResult = await validationResult.CompleteCommandExecutionAsync();

            executionResult.Success.ShouldBeTrue();
            executionResult.Value.ShouldBe("You shall pass");
        }
コード例 #2
0
        public async Task 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 IRule[] { new TrueRule(), new TrueRule() };
            var command = new CommandStub(doerOfThings.Object, rules);

            var validationResult = await command.ValidateAsync();

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

            var executionResult = await validationResult.CompleteCommandExecutionAsync();

            executionResult.Success.ShouldBeFalse();
            executionResult.Errors.Count().ShouldBe(1);
            executionResult.Errors.First().ErrorMessage.ShouldBe("You shall not pass");
        }
コード例 #3
0
        public async Task Fails_Execution_With_Expected_ExecutionResult_And_Method_Invocations_When_Any_Validation_Results_Exist_Async()
        {
            var doerOfThings     = new Mock <IDoThings>();
            var validationResult = new ValidationResult("You shall not pass");
            var command          = new CommandStub(doerOfThings.Object, new [] { validationResult });

            var result = await command.ExecuteAsync();

            result.Success.ShouldBeFalse();
            result.Errors.Count().ShouldBe(1);
            result.Errors.First().ErrorMessage.ShouldBe("You shall not pass");
            result.Value.ShouldBeNull();

            doerOfThings.Verify(d => d.Log("OnInitializationAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnValidateAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnGetRulesAsync"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnCompleteAsync"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnExecuteAsync"), 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);
        }
コード例 #4
0
        public async Task Successful_Execution_With_Expected_ExecutionResult_And_Method_Invocations_When_All_Rules_Pass_Async()
        {
            var doerOfThings = new Mock <IDoThings>();

            doerOfThings.Setup(d => d.GetValue()).Returns("You shall pass");
            var command = new CommandStub(doerOfThings.Object, new IRule[] { new TrueRule(), new TrueRule() });

            var result = await command.ExecuteAsync();

            result.Success.ShouldBeTrue();
            result.Errors.ShouldBeNull();
            result.Value.ShouldBe("You shall pass");

            doerOfThings.Verify(d => d.Log("OnInitializationAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnValidateAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnGetRulesAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnCompleteAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnExecuteAsync"), Times.Once);
            doerOfThings.Verify(d => d.Log("OnFailedExecution"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnPeasyExceptionHandled"), Times.Never);
            doerOfThings.Verify(d => d.Log("OnSuccessfulExecution"), Times.Once);
        }