public void itShouldCallCleanupOnFILOBasis() { var commands = new List <BaseCommand>(); var command1 = new MockCommandWithCleanup(); commands.Add(command1); var command2 = new MockCommandWithCleanup(); commands.Add(command2); var failingCmd = new MockFailingCommand(); commands.Add(failingCmd); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); var firstCommandCleanupReport = runner.Reports.First(r => r.ReportType.IsCleanupReport() && r.Reporter.Id == command1.Id); var latestCleanupReportTimestamp = runner.Reports.Max(r => r.ReportedOn); var earliestCleanupReport = runner.Reports.Where(r => r.ReportType.IsCleanupReport()) .OrderBy(r => r.ReportedOn) .First(); Assert.IsTrue(firstCommandCleanupReport.ReportedOn > earliestCleanupReport.ReportedOn); Assert.AreEqual(firstCommandCleanupReport.ReportedOn, latestCleanupReportTimestamp); }
public void itShouldCallUndoOnCommandsThatRanOnly() { var commands = new List <BaseCommand>(); var undoableCommand1 = new MockUndoableCommand(); commands.Add(undoableCommand1); var failingCmd = new MockFailingCommand(); commands.Add(failingCmd); var undoableCommand2 = new MockUndoableCommand(); commands.Add(undoableCommand2); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); Assert.AreEqual(1, runner.Reports .Where(r => r.Reporter.Id == undoableCommand1.Id && r.ReportType.IsUndoReport()) .Count()); Assert.AreEqual(1, runner.Reports .Where(r => r.Reporter.Id == failingCmd.Id && r.ReportType.IsUndoReport()) .Count()); Assert.AreEqual(0, runner.Reports .Where(r => r.Reporter.Id == undoableCommand2.Id && r.ReportType.IsUndoReport()) .Count()); }
public void itShouldReturnFalseWhenThereAreErrors() { var failingCmd = new MockFailingCommand(); var commands = new List <BaseCommand>(); commands.Add(failingCmd); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); }
public void itShouldCallCleanupOfInvokedCommandsOnFailure() { var commands = new List <BaseCommand>(); var command1 = new MockCommandWithCleanup(); commands.Add(command1); var command2 = new MockFailingCommand(); commands.Add(command2); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); Assert.IsTrue(runner.Reports.Any(r => r.ReportType.IsCleanupReport() && r.Reporter.Id == command1.Id)); }
public void itShouldDiscontinueWhenCommandFails() { var commands = new List <BaseCommand>(); var successfulCmd1 = new MockSucceedingCommand(); commands.Add(successfulCmd1); var failingCmd = new MockFailingCommand(); commands.Add(failingCmd); var successfulCmd2 = new MockSucceedingCommand(); commands.Add(successfulCmd2); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); // There should be no report from successfulCmd2 whatsoever because of failingCmd. Assert.IsFalse(runner.WasCommandStarted(successfulCmd2)); }
public void itShouldContinueUndoEvenWhenOneUndoFails() { var commands = new List <BaseCommand>(); var undoableCommand1 = new MockUndoableCommand(); commands.Add(undoableCommand1); var undoableCommand2 = new MockUndoThrowingExceptionCommand(); commands.Add(undoableCommand2); var failingCmd = new MockFailingCommand(); commands.Add(failingCmd); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); Assert.AreEqual(3, runner.Reports.Where(r => r.ReportType.IsUndoReport()).Count()); }
public void itShouldSetWasCommandStartedOnRanCommandsOnly() { var commands = new List <BaseCommand>(); var command1 = new MockSucceedingCommand(); commands.Add(command1); var failingCmd = new MockFailingCommand(); commands.Add(failingCmd); var command2 = new MockUndoableCommand(); commands.Add(command2); var runner = new CommandsRunner(commands); var result = runner.Run(); Assert.IsFalse(result); Assert.IsTrue(runner.WasCommandStarted(command1)); Assert.IsTrue(runner.WasCommandStarted(failingCmd)); Assert.IsFalse(runner.WasCommandStarted(command2)); }