public void NotAlterTheExceptionStackTraceOnThrownExceptions() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <ExplodingTestCommand, UnitType>, ExplodingTestCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string ExpectedExceptionMessage = "Kaboom!"; try { mediator.Submit(new ExplodingTestCommand { ExceptionMessage = ExpectedExceptionMessage }); } catch (Exception ex) { var stackTrace = new StackTrace(ex); var topFrame = stackTrace.GetFrame(0); Assert.AreEqual(typeof(ExplodingTestCommandHandler), topFrame.GetMethod().DeclaringType); } }
public void ThrowCommandHandlerNotFoundExceptionGivenNoHandlerIsRegisteredAndThrowExceptionIsTrue() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandHandler <DebugWriteCommand>, DebugWriteCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string StringToWrite = "This is a test!"; // Act & Assert Assert.Throws <CommandHandlerNotFoundException>(() => mediator.Submit(new DebugWriteCommand { TextToWrite = StringToWrite })); }
public void ThrowExceptionForGivenCommandGivenCommandThrowsExceptionAndThrowExceptionsIsTrue() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <ExplodingTestCommand, UnitType>, ExplodingTestCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string ExpectedExceptionMessage = "Kaboom!"; // Act & Assert Assert.Throws <Exception>(() => mediator.Submit(new ExplodingTestCommand { ExceptionMessage = ExpectedExceptionMessage })); }
public void ReturnResponseWithExecutionResultSetToFailedGivenNoHandlerIsRegisteredAndThrowExceptionIsFalse() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandHandler <DebugWriteCommand>, DebugWriteCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve, false); const string StringToWrite = "This is a test!"; // Act var response = mediator.Submit(new DebugWriteCommand { TextToWrite = StringToWrite }); // Assert Assert.That(response.CommandExecutionResult.Equals(CommandExecutionResult.Failed)); }
public void ReturnResponseWithExecutionTime() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <DebugWriteCommand, UnitType>, DebugWriteCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string StringToWrite = "This is a test!"; // Act var response = mediator.Submit(new DebugWriteCommand { TextToWrite = StringToWrite }); // Assert Assert.GreaterOrEqual(response.ExecutionTimeInMilliseconds, 50); }
public void ReturnResponseForCommandGivenHandlerIsRegistered() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <DebugWriteCommand, UnitType>, DebugWriteCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string StringToWrite = "This is a test!"; // Act var response = mediator.Submit(new DebugWriteCommand { TextToWrite = StringToWrite }); // Assert Assert.NotNull(response); }
public void ReturnResponseWithExecutionResultSetToFailedGivenCommandThrowsException() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <ExplodingTestCommand, UnitType>, ExplodingTestCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve, false); const string ExpectedExceptionMessage = "Kaboom!"; // Act & Assert var response = mediator.Submit(new ExplodingTestCommand { ExceptionMessage = ExpectedExceptionMessage }); // Assert Assert.That(response.CommandExecutionResult.Equals(CommandExecutionResult.Failed)); }
public void ReturnResponseWithExceptionForCommandGivenCommandThrowsExceptionAndThrowExceptionIsFalse() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <ExplodingTestCommand, UnitType>, ExplodingTestCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve, false); const string ExpectedExceptionMessage = "Kaboom!"; // Act & Assert var response = mediator.Submit(new ExplodingTestCommand { ExceptionMessage = ExpectedExceptionMessage }); // Assert Assert.NotNull(response.Exception); Assert.That(response.Exception.Message.Equals(ExpectedExceptionMessage)); }
public void ReturnResponseWithValidationResultsGivenCommandFailsValidation() { // Arrange var ioc = new InversionOfControl(); ioc.Register <ICommandMediator, CommandMediator>(); ioc.Register <ICommandHandler <DebugWriteWithValidationCommand, UnitType>, DebugWriteWithValidationCommandHandler>(); var mediator = new CommandMediator(ioc.Resolve); const string ExpectedValidationMessage = "You must supply a value for TextToWrite!"; // Act & Assert var response = mediator.Submit(new DebugWriteWithValidationCommand() { TextToWrite = "Blarg" }); // Assert Assert.That(response.CommandExecutionResult.Equals(CommandExecutionResult.Failed)); Assert.That(response.ValidationResults.Any().IsTrue()); Assert.That(response.ValidationResults.First().ErrorMessage.Equals(ExpectedValidationMessage)); }