Пример #1
0
        public void UpdateRevertUpdateQuestAndSaveTest()
        {
            //Arrange
            int updatedId = 42;

            Quest savedRoot = new FakeQuest()
            {
                Id = TopRootId
            };

            List <Quest> rootChildren = new List <Quest>()
            {
                new FakeQuest()
                {
                    Id = updatedId
                }
            };

            Quest toUpdate = rootChildren[0];

            IQuestFactory factory = MockRepository.GenerateStrictMock <IQuestFactory>();

            IQuestDataLayer dataLayer = MockRepository.GenerateStrictMock <IQuestDataLayer>();

            dataLayer.Expect(dl => dl.Open()).
            Repeat.Once();
            dataLayer.Expect(dl => dl.Get(Arg <int> .Is.Equal(TopRootId))).
            Repeat.Once().
            Return(savedRoot);
            dataLayer.Expect(dl => dl.IsClosed()).
            Repeat.Once().
            Return(false);
            dataLayer.Expect(dl => dl.GetAll(Arg <int> .Is.Equal(TopRootId))).
            Repeat.Once().
            Return(rootChildren);
            dataLayer.Expect(dl => dl.Dispose()).
            Repeat.Once();

            dataLayer.Expect(dl => dl.UpdateAll(Arg <IEnumerable <Quest> > .Is.Anything)).
            IgnoreArguments().
            Repeat.Never();

            QuestTreeInMemory tree = new QuestTreeInMemory(dataLayer, factory);

            //Act
            tree.Initialize();
            tree.Update(toUpdate);
            tree.RevertUpdate(toUpdate);
            tree.Save();

            //Assert
            dataLayer.VerifyAllExpectations();
            factory.VerifyAllExpectations();
        }