public void RefreshAfterInitializeTest()
        {
            //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);

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

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

            QuestListModelTopChildrenPredicate list = new QuestListModelTopChildrenPredicate(tree, q => true)
            {
                OrderStrategy = strategy
            };

            //Act
            list.Initialize();
            list.Refresh();

            //Assert
            tree.VerifyAllExpectations();
            strategy.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();
        }