public async Task Successful_Execution_With_Expected_ExecutionResult_And_Method_Invocations_When_All_Rules_Pass_Async() { var doerOfThings = new Mock <IDoThings>(); var command = new CommandStub(doerOfThings.Object, new IRule[] { new TrueRule(), new TrueRule() }); var result = await command.ExecuteAsync(); result.Success.ShouldBeTrue(); result.Errors.ShouldBeNull(); 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); }
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"); 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); }
public async Task Fails_Execution_With_Expected_ExecutionResult_And_Method_Invocations_When_Any_Rules_Fail_Async() { var doerOfThings = new Mock <IDoThings>(); var rules = new IRule[] { new TrueRule(), new FalseRule1() }; var command = new CommandStub(doerOfThings.Object, rules); var result = await command.ExecuteAsync(); result.Success.ShouldBeFalse(); result.Errors.Count().ShouldBe(1); result.Errors.First().ErrorMessage.ShouldBe("FalseRule1 failed validation"); 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.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); }