Exemplo n.º 1
0
        public void itShouldCallUndoOnFILOBasis()
        {
            var commands         = new List <BaseCommand>();
            var undoableCommand1 = new MockUndoableCommand();

            commands.Add(undoableCommand1);

            var undoableCommand2 = new MockUndoableCommandWithUndoDelay();

            commands.Add(undoableCommand2);

            var failingCmd = new MockFailingCommand();

            commands.Add(failingCmd);

            var runner = new CommandsRunner(commands);
            var result = runner.Run();

            Assert.IsFalse(result);
            var firstCommandUndoReport = runner.Reports.First(r => r.ReportType.IsUndoReport() &&
                                                              r.Reporter.Id == undoableCommand1.Id);
            var latestUndoReportTimestamp = runner.Reports.Max(r => r.ReportedOn);
            var earliestUndoReport        = runner.Reports.Where(r => r.ReportType.IsUndoReport())
                                            .OrderBy(r => r.ReportedOn)
                                            .First();

            Assert.IsTrue(firstCommandUndoReport.ReportedOn > earliestUndoReport.ReportedOn);
            Assert.AreEqual(firstCommandUndoReport.ReportedOn, latestUndoReportTimestamp);
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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));
        }