public void throws_exception_on_command_exception_when_enabled_in_settings() { var errorCommand = new ExceptionThrowingCommand(); var engine = CleeEngine.Create(cfg => { cfg.Settings(s => { s.ThrowOnExceptions = true; }); cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand))); cfg.Registry(r => r.Register("foo", errorCommand.GetType())); }); Assert.Throws <CustomCommandException>(() => engine.Execute("foo")); }
public void does_not_throw_exception_on_command_exception_when_disabled_in_settings() { var errorCommand = new ExceptionThrowingCommand(); var engine = CleeEngine.Create(cfg => { cfg.Settings(s => { s.ThrowOnExceptions = false; }); cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand))); cfg.Registry(r => r.Register("foo", errorCommand.GetType())); }); engine.Execute("foo"); }
public void ShouldWrapExceptionDetailsWhenExceptionIsThrown() { ExceptionThrowingCommand innerCmd = new ExceptionThrowingCommand(); MethodInfo method = typeof(ExceptionThrowingCommand).GetMethod("Execute"); var command = new ExceptionAndOutputCaptureCommand(innerCmd, Reflector.Wrap(method)); MethodResult result = command.Execute(null); FailedResult failed = Assert.IsType<FailedResult>(result); Assert.Equal(method.Name, failed.MethodName); Assert.Equal(method.DeclaringType.FullName, failed.TypeName); Assert.Equal(typeof(TargetInvocationException).FullName, failed.ExceptionType); Assert.Contains("ExceptionThrowingCommand.Execute", failed.StackTrace); }
public void RollbackYourTransaction() { ExceptionThrowingCommand command = new ExceptionThrowingCommand(); try { commandExecutor.Execute(command); Assert.Fail("We should have thrown an exception"); } catch (ApplicationException) { Assert.IsNull(TransactionManager.Transaction()); } }
public void ShouldWrapExceptionDetailsWhenExceptionIsThrown() { ExceptionThrowingCommand innerCmd = new ExceptionThrowingCommand(); MethodInfo method = typeof(ExceptionThrowingCommand).GetMethod("Execute"); var command = new ExceptionAndOutputCaptureCommand(innerCmd, Reflector.Wrap(method)); MethodResult result = command.Execute(null); FailedResult failed = Assert.IsType <FailedResult>(result); Assert.Equal(method.Name, failed.MethodName); Assert.Equal(method.DeclaringType.FullName, failed.TypeName); Assert.Equal(typeof(TargetInvocationException).FullName, failed.ExceptionType); Assert.Contains("ExceptionThrowingCommand.Execute", failed.StackTrace); }
public void DontRollbackMyTransaction() { SqlTransaction myTransaction = TransactionManager.Begin(Connection); ExceptionThrowingCommand command = new ExceptionThrowingCommand(); try { commandExecutor.Execute(command); Assert.Fail("We should have thrown an exception"); } catch (ApplicationException) { Assert.IsNotNull(TransactionManager.Transaction()); } TransactionManager.Rollback(); }
public void has_expected_exit_code_when_command_throws_exception() { var exitCode = 0; var errorCommand = new ExceptionThrowingCommand(); var engine = CleeEngine.Create(cfg => { cfg.Settings(s => { s.ThrowOnExceptions = false; }); cfg.Factory(f => f.Use(new StubCommandFactory(errorCommand))); cfg.Registry(r => r.Register("foo", errorCommand.GetType())); }); engine.SetExitCodeAssigner(code => exitCode = code); engine.Execute("foo"); Assert.Equal(-1, exitCode); }
public void ThrowCommand() { ExceptionThrowingCommand command = new ExceptionThrowingCommand(); commandExecutor.Execute(command); }