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 TraverseToLeafOutOfBoundary(int position)
        {
            //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.Twice().
            Return(parent);

            QuestListModelTopChildrenPredicate list = new QuestListModelTopChildrenPredicate(tree, q => true);

            //Act
            list.Initialize();
            bool traverseResult = list.TraverseToLeaf(position);

            //Assert
            Assert.IsFalse(traverseResult);
            tree.VerifyAllExpectations();
        }
        public void TraverseToLeafWithOrderStrategy()
        {
            //Arrange
            int position = 0;
            Func <Quest, bool> predicate = q => true;
            List <Quest>       children  = new List <Quest>()
            {
                new FakeQuest(),
                new FakeQuest(),
                new FakeQuest(),
                new FakeQuest()
            };

            Quest        childToTraverse = children[position];
            List <Quest> childChildren   = new List <Quest>();

            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);
            tree.Expect(tr => tr.LoadChildren(Arg <Quest> .Is.Equal(childToTraverse))).
            Repeat.Once().
            Do(new Action <Quest>((q) =>
            {
                q.Children = childChildren;
            }));

            IQuestOrderStrategy strategy = MockRepository.GenerateStrictMock <IQuestOrderStrategy>();

            strategy.Expect(str => str.Order(Arg <IEnumerable <Quest> > .Is.Anything))
            .Repeat.Once()
            .Return(children.OrderBy(q => q.IsImportant));
            strategy.Expect(str => str.Order(Arg <IEnumerable <Quest> > .Is.Anything))
            .Repeat.Once()
            .Return(childChildren.OrderBy(q => q.IsImportant));

            QuestListModelTopChildrenPredicate list = new QuestListModelTopChildrenPredicate(tree, predicate)
            {
                OrderStrategy = strategy
            };

            //Act
            list.Initialize();
            bool traverseResult = list.TraverseToLeaf(position);

            Quest        listParent   = list.Parent;
            List <Quest> listChildren = list.Leaves;

            //Assert
            Assert.AreEqual(childToTraverse, listParent);
            Assert.AreEqual(childChildren, listChildren);

            Assert.IsTrue(traverseResult);

            tree.VerifyAllExpectations();
            strategy.VerifyAllExpectations();
        }