/// <summary> /// Receives quest to operate on and command, that represents operation on quest. /// </summary> /// <param name="quest"></param> /// <param name="questCommand"></param> public CurrentQuestCommand(Quest quest, IQuestCommand questCommand) { quest.ThrowIfNull(nameof(quest)); questCommand.ThrowIfNull(nameof(questCommand)); QuestRef = quest; QuestCommand = questCommand; }
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 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(); }
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 UpToRootQuestCommand(IQuestTree questTree, IQuestCommand innerCommand) { questTree.ThrowIfNull(nameof(questTree)); innerCommand.ThrowIfNull(nameof(innerCommand)); _questTree = questTree; _innerCommand = innerCommand; }
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 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 IfEachChildMatchQuestCommand(Predicate <Quest> predicate, IQuestCommand innerCommand) { predicate.ThrowIfNull(nameof(predicate)); innerCommand.ThrowIfNull(nameof(innerCommand)); _predicate = predicate; _inner = innerCommand; }
/// <summary> /// Receives quest to traverse and quest tree. /// </summary> /// <param name="quest"></param> /// <param name="questCommand"></param> protected UpHierarchyQuestCommand(Quest quest, IQuestCommand questCommand) { quest.ThrowIfNull(nameof(quest)); questCommand.ThrowIfNull(nameof(questCommand)); _target = quest; _command = questCommand; }
public IfElseQuestCommand(IQuestCommand ifCommand, IQuestCommand elseCommand) { ifCommand.ThrowIfNull(nameof(ifCommand)); elseCommand.ThrowIfNull(nameof(elseCommand)); _ifCommand = ifCommand; _elseCommand = elseCommand; }
/// <summary> /// Receives quest to traverse. /// </summary> /// <param name="quest"></param> /// <param name="beforeTraverseCommand"></param> /// <param name="afterTraverseCommand"></param> public DownHierarchyQuestCommand(Quest quest, IQuestCommand beforeTraverseCommand, IQuestCommand afterTraverseCommand) { quest.ThrowIfNull(nameof(quest)); beforeTraverseCommand.ThrowIfNull(nameof(beforeTraverseCommand)); afterTraverseCommand.ThrowIfNull(nameof(afterTraverseCommand)); _target = quest; _beforeTraverseCommand = beforeTraverseCommand; _afterTraverseCommand = afterTraverseCommand; }
public void CtorNullTest() { //Arrange IQuestCommand questCommand = MockRepository.GenerateStrictMock <IQuestCommand>(); Quest targer = QuestHelper.CreateQuest(); //Act ArgumentNullException treeEx = Assert.Throws <ArgumentNullException>(() => new UpToRootQuestCommand(targer, null, questCommand)); //Assert Assert.IsNotNull(treeEx); Assert.AreEqual("questTree", treeEx.ParamName); }
public void CtorNullTest() { //Arrange IQuestCommand questCommand = MockRepository.GenerateStrictMock <IQuestCommand>(); Quest targer = QuestHelper.CreateQuest(); //Act ArgumentNullException targetEx = Assert.Throws <ArgumentNullException>(() => new UpHierarchyQuestCommandMock(null, questCommand)); ArgumentNullException questCommandEx = Assert.Throws <ArgumentNullException>(() => new UpHierarchyQuestCommandMock(targer, null)); //Assert Assert.IsNotNull(targetEx); Assert.AreEqual("quest", targetEx.ParamName); Assert.IsNotNull(questCommandEx); Assert.AreEqual("questCommand", questCommandEx.ParamName); }
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(); }
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(); }
public void CtorNullTest() { //Arrange IQuestCommand questCommand = MockRepository.GenerateStrictMock <IQuestCommand>(); Quest targer = QuestHelper.CreateQuest(); //Act ArgumentNullException targetEx = Assert.Throws <ArgumentNullException>(() => new DownHierarchyQuestCommand(null, questCommand, questCommand)); ArgumentNullException beforeQuestCommand = Assert.Throws <ArgumentNullException>(() => new DownHierarchyQuestCommand(targer, null, questCommand)); ArgumentNullException afterQuestCommand = Assert.Throws <ArgumentNullException>(() => new DownHierarchyQuestCommand(targer, questCommand, null)); //Assert Assert.IsNotNull(targetEx); Assert.AreEqual("quest", targetEx.ParamName); Assert.IsNotNull(beforeQuestCommand); Assert.AreEqual("beforeTraverseCommand", beforeQuestCommand.ParamName); Assert.IsNotNull(afterQuestCommand); Assert.AreEqual("afterTraverseCommand", afterQuestCommand.ParamName); }
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(); }
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(); }
/// <summary> /// Receives quest target, quest tree and quest command. /// </summary> /// <param name="quest"></param> /// <param name="questTree"></param> /// <param name="questCommand"></param> public UpToRootQuestCommand(Quest quest, IQuestTree questTree, IQuestCommand questCommand) : base(quest, questCommand) { questTree.ThrowIfNull(nameof(questTree)); _questTree = questTree; }
public UpHierarchyQuestCommandMock(Quest quest, IQuestCommand questCommand) : base(quest, questCommand) { }