Example #1
0
        public void UndoWithParentsTest()
        {
            //Arrange
            Quest root    = new FakeQuest();
            Quest parent0 = new FakeQuest();
            Quest parent1 = new FakeQuest();
            Quest parent2 = new FakeQuest();

            root.Parent    = null;
            parent0.Parent = root;
            parent1.Parent = parent0;
            parent2.Parent = parent1;

            IQuestTree tree = MockRepository.GenerateStrictMock <IQuestTree>();

            tree.Expect(tr => tr.Root).Return(root).Repeat.Times(4);

            IQuestCommand innerCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            innerCommand.Expect(ic => ic.Undo(Arg <Quest> .Is.Equal(parent2))).Repeat.Once().Return(true);
            innerCommand.Expect(ic => ic.Undo(Arg <Quest> .Is.Equal(parent1))).Repeat.Once().Return(true);
            innerCommand.Expect(ic => ic.Undo(Arg <Quest> .Is.Equal(parent0))).Repeat.Once().Return(true);
            innerCommand.Expect(ic => ic.Undo(Arg <Quest> .Is.Equal(root))).Repeat.Never();

            UpToRootQuestCommand command = new UpToRootQuestCommand(parent2, tree, innerCommand);


            //Act
            bool result = command.Undo();

            //Assert
            Assert.IsTrue(result);

            innerCommand.VerifyAllExpectations();
        }
        public void CommitTestTest(bool beforeCommitResult, bool afterCommitResult)
        {
            //Arrange
            Quest quest = QuestHelper.CreateQuest();

            IQuestCommand beforeQuestCommanduestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            beforeQuestCommanduestCommand.Expect(bqc => bqc.Commit()).
            Repeat.Once().
            Return(beforeCommitResult);

            IQuestCommand afterQuestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            afterQuestCommand.Expect(aqc => aqc.Commit()).
            Repeat.Once().
            Return(afterCommitResult);

            DownHierarchyQuestCommand command = new DownHierarchyQuestCommand(quest, beforeQuestCommanduestCommand,
                                                                              afterQuestCommand);

            //Act
            bool result = command.Commit();

            //Assert
            Assert.AreEqual(beforeCommitResult && afterCommitResult, result);

            beforeQuestCommanduestCommand.VerifyAllExpectations();
            afterQuestCommand.VerifyAllExpectations();
        }
        public void ExecuteOnQuestWithoutChildrenTest(bool beforeCommandResult)
        {
            //Arrange
            Quest         quest = QuestHelper.CreateQuest();
            IQuestCommand beforeQuestCommanduestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            beforeQuestCommanduestCommand.Expect(bqc => bqc.Execute(Arg <Quest> .Is.Equal(quest)))
            .Repeat.Once()
            .Return(beforeCommandResult);

            IQuestCommand afterQuestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            afterQuestCommand.Expect(aqc => aqc.Execute(Arg <Quest> .Is.Equal(quest)))
            .Repeat.Never();

            DownHierarchyQuestCommand command = new DownHierarchyQuestCommand(quest, beforeQuestCommanduestCommand,
                                                                              afterQuestCommand);

            //Act
            bool result = command.Execute();

            //Assert
            Assert.IsTrue(result);

            beforeQuestCommanduestCommand.VerifyAllExpectations();
            afterQuestCommand.VerifyAllExpectations();
        }
Example #4
0
        public void UndoWithNullTest()
        {
            //Arrange
            Quest quest = null;

            IQuestCommand firstOne = MockRepository.GenerateStrictMock <IQuestCommand>();

            firstOne.Expect(c => c.Undo(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(true);

            IQuestCommand secondOne = MockRepository.GenerateStrictMock <IQuestCommand>();

            secondOne.Expect(c => c.Undo(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(true);

            CompositeQuestCommand composite = new CompositeQuestCommand(new[] { firstOne, secondOne });

            //Act
            Assert.DoesNotThrow(() => composite.Undo(quest));

            //Assert
            firstOne.VerifyAllExpectations();
            secondOne.VerifyAllExpectations();
        }
        public void ExecuteWithParentsOneReturnsFalseTest()
        {
            //Arrange
            Quest root    = new FakeQuest();
            Quest parent0 = new FakeQuest();
            Quest parent1 = new FakeQuest();
            Quest parent2 = new FakeQuest();

            root.Parent    = null;
            parent0.Parent = root;
            parent1.Parent = parent0;
            parent2.Parent = parent1;

            IQuestCommand innerCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            innerCommand.Expect(ic => ic.Execute(Arg <Quest> .Is.Equal(parent2))).Repeat.Once().Return(true);
            innerCommand.Expect(ic => ic.Execute(Arg <Quest> .Is.Equal(parent1))).Repeat.Once().Return(false);
            innerCommand.Expect(ic => ic.Execute(Arg <Quest> .Is.Equal(parent0))).Repeat.Once().Return(true);
            innerCommand.Expect(ic => ic.Execute(Arg <Quest> .Is.Equal(root))).Repeat.Once().Return(true);

            UpHierarchyQuestCommandMock command = new UpHierarchyQuestCommandMock(parent2, innerCommand);


            //Act
            bool result = command.Execute();

            //Assert
            Assert.IsTrue(result);

            innerCommand.VerifyAllExpectations();
        }
        public void IsValidTest()
        {
            //Arrange
            Quest quest = new FakeQuest();

            IQuestCommand innerCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            UpHierarchyQuestCommandMock command = new UpHierarchyQuestCommandMock(quest, innerCommand);

            //Act
            bool result = command.IsValid();

            //Assert
            Assert.IsTrue(result);

            innerCommand.VerifyAllExpectations();
        }
Example #7
0
        public void IsValidTest()
        {
            //Arrange
            Quest target = QuestHelper.CreateQuest();

            IQuestCommand questCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            CurrentQuestCommand command = new CurrentQuestCommand(target, questCommand);

            //Act
            bool result = command.IsValid();


            //Assert
            Assert.IsTrue(result);

            questCommand.VerifyAllExpectations();
        }
        public void UndoOnQuestWithChildrenTest(bool beforeCommandResult)
        {
            //Arrange
            Quest child = QuestHelper.CreateQuest();
            Quest quest = QuestHelper.CreateQuest();

            quest.Children = new List <Quest> {
                child
            };

            IQuestCommand beforeQuestCommanduestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            beforeQuestCommanduestCommand.Expect(bqc => bqc.Undo(Arg <Quest> .Is.Equal(quest)))
            .Repeat.Once()
            .Return(beforeCommandResult);
            if (beforeCommandResult)
            {
                beforeQuestCommanduestCommand.Expect(bqc => bqc.Undo(Arg <Quest> .Is.Equal(child)))
                .Repeat.Once()
                .Return(true);
            }

            IQuestCommand afterQuestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            if (beforeCommandResult)
            {
                afterQuestCommand.Expect(aqc => aqc.Undo(Arg <Quest> .Is.Equal(quest)))
                .Repeat.Once()
                .Return(true);
            }

            DownHierarchyQuestCommand command = new DownHierarchyQuestCommand(quest, beforeQuestCommanduestCommand,
                                                                              afterQuestCommand);

            //Act
            bool result = command.Undo();

            //Assert
            Assert.IsTrue(result);

            beforeQuestCommanduestCommand.VerifyAllExpectations();
            afterQuestCommand.VerifyAllExpectations();
        }
        public void CommitTest()
        {
            //Arrange
            Quest quest = new FakeQuest();

            IQuestCommand innerCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            innerCommand.Expect(ic => ic.Commit()).Repeat.Once().Return(true);

            UpHierarchyQuestCommandMock command = new UpHierarchyQuestCommandMock(quest, innerCommand);

            //Act
            bool result = command.Commit();

            //Assert
            Assert.IsTrue(result);

            innerCommand.VerifyAllExpectations();
        }
        public void IsValidTest()
        {
            //Arrange
            Quest quest = QuestHelper.CreateQuest();

            IQuestCommand beforeQuestCommanduestCommand = MockRepository.GenerateStrictMock <IQuestCommand>();
            IQuestCommand afterQuestCommand             = MockRepository.GenerateStrictMock <IQuestCommand>();

            DownHierarchyQuestCommand command = new DownHierarchyQuestCommand(quest, beforeQuestCommanduestCommand,
                                                                              afterQuestCommand);

            //Act
            bool result = command.IsValid();

            //Assert
            Assert.IsTrue(result);

            beforeQuestCommanduestCommand.VerifyAllExpectations();
            afterQuestCommand.VerifyAllExpectations();
        }
Example #11
0
        public void CommitTest()
        {
            //Arrange
            Quest target = QuestHelper.CreateQuest();

            IQuestCommand questCommand = MockRepository.GenerateStrictMock <IQuestCommand>();

            questCommand.Expect(qc => qc.Commit()).
            Repeat.Once().
            Return(true);

            CurrentQuestCommand command = new CurrentQuestCommand(target, questCommand);

            //Act
            bool result = command.Commit();


            //Assert
            Assert.IsTrue(result);

            questCommand.VerifyAllExpectations();
        }
Example #12
0
        public void UndoOrderTest()
        {
            //Arrange
            Stack <int> stack = new Stack <int>();
            Quest       quest = new FakeQuest();

            IQuestCommand firstOne = MockRepository.GenerateStrictMock <IQuestCommand>();

            firstOne.Expect(c => c.Undo(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Do(new Func <Quest, bool>((q) =>
            {
                stack.Push(1);
                return(true);
            }));

            IQuestCommand secondOne = MockRepository.GenerateStrictMock <IQuestCommand>();

            secondOne.Expect(c => c.Undo(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Do(new Func <Quest, bool>(q =>
            {
                stack.Push(2);
                return(true);
            }));

            CompositeQuestCommand composite = new CompositeQuestCommand(new[] { firstOne, secondOne });

            //Act
            composite.Undo(quest);

            //Assert
            Assert.AreEqual(1, stack.Pop());
            Assert.AreEqual(2, stack.Pop());

            firstOne.VerifyAllExpectations();
            secondOne.VerifyAllExpectations();
        }