public void TraverseToRoot() { //Arrange int position = 0; List <Quest> children = new List <Quest>() { new FakeQuest(), }; Quest parent = new FakeQuest { Children = children }; Quest childToTraverse = children[position]; childToTraverse.Parent = parent; IQuestTree tree = MockRepository.GenerateStrictMock <IQuestTree>(); tree.Expect(tr => tr.IsInitialized()). Repeat.Once(). Return(true); tree.Expect(tr => tr.Initialize()). Repeat.Never(); tree.Expect(tr => tr.Root). Repeat.Times(7). Return(parent); tree.Expect(tr => tr.LoadChildren(Arg <Quest> .Is.Equal(childToTraverse))). Repeat.Once(); tree.Expect(tr => tr.UnloadChildren(Arg <Quest> .Is.Equal(childToTraverse))). Repeat.Once(); QuestListModelTopChildrenPredicate list = new QuestListModelTopChildrenPredicate(tree, q => true); //Act list.Initialize(); bool traverseResult = list.TraverseToLeaf(position); bool traverseToRootResult = list.TraverseToRoot(); Quest listParent = list.Parent; List <Quest> listChildren = list.Leaves; //Assert Assert.AreEqual(parent, listParent); Assert.AreEqual(children, listChildren); Assert.IsTrue(traverseResult); Assert.IsTrue(traverseToRootResult); tree.VerifyAllExpectations(); }
public void TraverseToRootInTheRootAlreadyTest() { //Arrange List <Quest> children = new List <Quest>() { new FakeQuest(), new FakeQuest(), new FakeQuest(), new FakeQuest() }; Quest parent = new FakeQuest { Children = children }; IQuestTree tree = MockRepository.GenerateStrictMock <IQuestTree>(); tree.Expect(tr => tr.IsInitialized()). Repeat.Once(). Return(true); tree.Expect(tr => tr.Initialize()). Repeat.Never(); tree.Expect(tr => tr.Root). Repeat.Times(3). Return(parent); QuestListModelTopChildrenPredicate list = new QuestListModelTopChildrenPredicate(tree, q => true); //Act list.Initialize(); bool traverseResult = list.TraverseToRoot(); //Assert Assert.IsFalse(traverseResult); tree.VerifyAllExpectations(); }