예제 #1
0
 /// <summary>
 /// Receives references to repository, stateCommands and treeCommands factories.
 /// </summary>
 /// <param name="questListModel"></param>
 /// <param name="stateCommandsFactory"></param>
 /// <param name="treeCommandsFactory"></param>
 public AvailableQuestListViewModel(
     IQuestListModel questListModel,
     IStateCommandsFactory stateCommandsFactory,
     ITreeCommandsFactory treeCommandsFactory) :
     base(questListModel, stateCommandsFactory, treeCommandsFactory)
 {
 }
예제 #2
0
        public void QuestsListTitleNotInRootTestTest()
        {
            //Arrange
            const string expectedTitle = "fakeTitleOfFakeQuest";

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(mo => mo.IsInTheRoot).
            Repeat.Once().
            Return(false);
            model.Expect(mo => mo.Parent).
            Repeat.Once().
            Return(new FakeQuest {
                Title = expectedTitle
            });

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            string questsListTitle = viewModel.QuestsListTitle;

            //Assert
            Assert.IsNotNull(questsListTitle);
            Assert.AreEqual(expectedTitle, questsListTitle);
        }
예제 #3
0
        public void RestartQuestInvalidPositionTest()
        {
            //Arrange
            int position = 1;

            List <Quest> leaves = new List <Quest>();

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).
            Repeat.Once().
            Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();

            stateCommands.Expect(sc => sc.CancelQuest(Arg <Quest> .Is.Anything)).
            Repeat.Never();
            stateCommands.Expect(sc => sc.StartQuest(Arg <Quest> .Is.Anything)).
            Repeat.Never();


            ITreeCommandsFactory repoCommands = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            ResultsQuestListViewModel viewModel = new ResultsQuestListViewModel(model, stateCommands, repoCommands);

            //Act
            Task deleteTask = viewModel.RestartQuest(position);

            //Assert
            Assert.IsNull(deleteTask);

            model.VerifyAllExpectations();
            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
        }
 /// <summary>
 /// Receives references to list model, stateCommands and treeCommands factories.
 /// </summary>
 /// <param name="questListModel"></param>
 /// <param name="stateCommandsFactory"></param>
 /// <param name="treeCommandsFactory"></param>
 public ResultsQuestListViewModel(
     IQuestListModel questListModel,
     IStateCommandsFactory stateCommandsFactory,
     ITreeCommandsFactory treeCommandsFactory) :
     base(questListModel, stateCommandsFactory, treeCommandsFactory)
 {
 }
예제 #5
0
        public void CancelQuestWrongPositionTest()
        {
            //Arrange
            int position = 1;

            List <Quest> leaves = new List <Quest>();

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(m => m.Leaves).
            Repeat.Once().
            Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);


            //Act
            Task cancelTask = viewModel.CancelQuest(position);

            //Assert
            Assert.IsNull(cancelTask);

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #6
0
        public void CountProgressWrongPosition()
        {
            //Arrange
            int          expected = -1;
            int          position = 1;
            List <Quest> leaves   = new List <Quest>();

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(m => m.Leaves).
            Repeat.Once().
            Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);


            //Act
            int progressInt = viewModel.CountProgress(position);

            //Assert
            Assert.AreEqual(expected, progressInt);

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #7
0
        public void RestartQuestValidPositionTest()
        {
            //Arrange
            int   position  = 0;
            Quest toRestart = new FakeQuest();

            List <Quest> leaves = new List <Quest> {
                toRestart
            };

            ICommand startCommand = MockRepository.GenerateStrictMock <ICommand>();

            startCommand.Expect(dc => dc.Execute()).
            Repeat.Once().
            Return(true);
            startCommand.Expect(dc => dc.Commit()).
            Repeat.Once().
            Return(true);

            ICommand cancelCommand = MockRepository.GenerateStrictMock <ICommand>();

            cancelCommand.Expect(dc => dc.Execute()).
            Repeat.Once().
            Return(true);
            cancelCommand.Expect(dc => dc.Commit()).
            Repeat.Once().
            Return(true);

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).
            Repeat.Once().
            Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();

            stateCommands.Expect(sc => sc.CancelQuest(Arg <Quest> .Is.Equal(toRestart))).
            Repeat.Once().
            Return(cancelCommand);
            stateCommands.Expect(sc => sc.StartQuest(Arg <Quest> .Is.Equal(toRestart))).
            Repeat.Once().
            Return(startCommand);

            ITreeCommandsFactory repoCommands = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            ResultsQuestListViewModel viewModel = new ResultsQuestListViewModel(model, stateCommands, repoCommands);

            //Act
            Task startTask = viewModel.RestartQuest(position);

            //Assert
            Assert.IsNotNull(startTask);
            startTask.Wait();

            cancelCommand.VerifyAllExpectations();
            startCommand.VerifyAllExpectations();
            model.VerifyAllExpectations();
            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
        }
예제 #8
0
        public void RootIdTest()
        {
            //Arrange
            int questId = 42;

            Quest parent = new FakeQuest()
            {
                Id = questId
            };

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(mo => mo.Parent).
            Repeat.Once().
            Return(parent);



            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            int id = viewModel.RootId;

            //Assert
            Assert.AreEqual(questId, id);
            model.VerifyAllExpectations();
        }
예제 #9
0
        public void GetLeafIdValidPositionTest()
        {
            //Arrange
            int position = 0;
            int questId  = 42;

            List <Quest> leaves = new List <Quest>()
            {
                new FakeQuest()
                {
                    Id = questId
                }
            };

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).Repeat.Once().Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            int?id = viewModel.GetLeafId(position);

            //Assert
            Assert.AreEqual(questId, id);
            model.VerifyAllExpectations();
        }
예제 #10
0
        /// <summary>
        /// Default constructor. Resolves references to quest list model and command factories.
        /// </summary>
        public QuestListViewModel(
            IQuestListModel questListModel,
            IStateCommandsFactory stateCommandsFactory,
            ITreeCommandsFactory treeCommandsFactory)
        {
            questListModel.ThrowIfNull(nameof(questListModel));
            stateCommandsFactory.ThrowIfNull(nameof(stateCommandsFactory));
            treeCommandsFactory.ThrowIfNull(nameof(treeCommandsFactory));

            QuestListModel = questListModel;
            StateCommads   = stateCommandsFactory;
            TreeCommands   = treeCommandsFactory;
        }
예제 #11
0
        public void DeleteQuestValidPositionTest()
        {
            //Arrange
            int   position = 0;
            Quest parent   = new FakeQuest();
            Quest toDelete = new FakeQuest();

            List <Quest> leaves = new List <Quest> {
                toDelete
            };

            ICommand deleteCommand = MockRepository.GenerateStrictMock <ICommand>();

            deleteCommand.Expect(dc => dc.Execute()).
            Repeat.Once().
            Return(true);
            deleteCommand.Expect(dc => dc.Commit()).
            Repeat.Once().
            Return(true);

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).
            Repeat.Once().
            Return(leaves);
            model.Expect(m => m.Parent).
            Repeat.Once().
            Return(parent);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();

            ITreeCommandsFactory repoCommands = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            repoCommands.Expect(rc => rc.DeleteQuest(Arg <Quest> .Is.Equal(parent), Arg <Quest> .Is.Equal(toDelete))).
            Repeat.Once().
            Return(deleteCommand);

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            Task deleteTask = viewModel.DeleteQuest(position);

            //Assert
            Assert.IsNotNull(deleteTask);
            deleteTask.Wait();

            model.VerifyAllExpectations();
            deleteCommand.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
        }
예제 #12
0
        public void CancelQuestTest()
        {
            //Arrange
            int position = 0;

            Quest toFail = new FakeQuest();

            List <Quest> leaves = new List <Quest> {
                toFail
            };

            ICommand returnedCommand = MockRepository.GenerateStrictMock <ICommand>();

            returnedCommand.Expect(rc => rc.Execute()).
            Repeat.Once().
            Return(true);
            returnedCommand.Expect(rc => rc.Commit()).
            Repeat.Once().
            Return(true);

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(m => m.Leaves).
            Repeat.Once().
            Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();

            stateCommands.Expect(sc => sc.CancelQuest(Arg <Quest> .Is.Equal(toFail))).
            Repeat.Once().
            Return(returnedCommand);

            ITreeCommandsFactory repoCommands = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);


            //Act
            Task cancelTask = viewModel.CancelQuest(position);

            //Assert
            Assert.IsNotNull(cancelTask);
            cancelTask.Wait();

            returnedCommand.VerifyAllExpectations();
            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
        public void CtorNotThrowExceptionsTest()
        {
            //Arrange
            IQuestListModel       model         = MockRepository.GenerateStrictMock <IQuestListModel>();
            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            //Act && Assert
            Assert.DoesNotThrow(() => new AvailableQuestListViewModel(model, stateCommands, repoCommands));

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #14
0
        public void RefreshTest()
        {
            //Arrange
            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Refresh()).
            Repeat.Once();

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            viewModel.Refresh();

            //Assert
            model.VerifyAllExpectations();
        }
예제 #15
0
        public void QuestsListTitleModelInRootTest()
        {
            //Arrange
            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(mo => mo.IsInTheRoot).
            Repeat.Once().
            Return(true);
            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            string questsListTitle = viewModel.QuestsListTitle;

            //Assert
            Assert.IsNull(questsListTitle);
        }
예제 #16
0
        public void CtorNullTest()
        {
            //Arrange
            IQuestListModel       model         = MockRepository.GenerateStrictMock <IQuestListModel>();
            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            //Act
            ArgumentNullException modelNullEx          = Assert.Throws <ArgumentNullException>(() => new QuestListViewModel(null, stateCommands, repoCommands));
            ArgumentNullException stateCommandslNullEx = Assert.Throws <ArgumentNullException>(() => new QuestListViewModel(model, null, repoCommands));
            ArgumentNullException repoCommandsNullEx   = Assert.Throws <ArgumentNullException>(() => new QuestListViewModel(model, stateCommands, null));

            //Assert
            Assert.IsNotNull(modelNullEx);
            Assert.IsNotNull(stateCommandslNullEx);
            Assert.IsNotNull(repoCommandsNullEx);

            Assert.AreEqual("questListModel", modelNullEx.ParamName);
            Assert.AreEqual("stateCommandsFactory", stateCommandslNullEx.ParamName);
            Assert.AreEqual("treeCommandsFactory", repoCommandsNullEx.ParamName);
        }
예제 #17
0
        public void InTopRootTest()
        {
            //Arrange
            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.IsInTheRoot).
            Repeat.Once().
            Return(true);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            bool result = viewModel.InTopRoot;

            //Assert
            Assert.IsTrue(result);
            model.VerifyAllExpectations();
        }
예제 #18
0
        public void CountProgressTest(double progress)
        {
            //Arrange
            int expected = (int)Math.Floor(progress * 100);
            int position = 0;

            Quest quest = new Quest()
            {
                Progress = progress
            };

            List <Quest> leaves = new List <Quest>()
            {
                quest
            };

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(m => m.Leaves).
            Repeat.Once().
            Return(leaves);


            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);


            //Act
            int progressInt = viewModel.CountProgress(position);

            //Assert
            Assert.AreEqual(expected, progressInt);

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #19
0
        public void IsRootDoneInTopRootTest()
        {
            //Arrange
            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(mo => mo.IsInTheRoot).Repeat.Once().Return(true);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);

            //Act
            bool isRootDone = viewModel.IsRootHasState(State.Done);

            //Assert
            Assert.IsFalse(isRootDone);

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #20
0
        public void TraverseToLeafTest()
        {
            //Arrange
            int leaf = 42;

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.TraverseToLeaf(Arg <int> .Is.Equal(leaf))).
            Repeat.Once().
            Return(true);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            bool result = viewModel.TraverseToLeaf(leaf);

            //Assert
            Assert.IsTrue(result);
            model.VerifyAllExpectations();
        }
예제 #21
0
        public void DeleteQuestInvalidPositionTest()
        {
            //Arrange
            int position = 1;

            List <Quest> leaves = new List <Quest>();

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).Repeat.Once().Return(leaves);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            Task deleteTask = viewModel.DeleteQuest(position);

            //Assert
            Assert.IsNull(deleteTask);
            model.VerifyAllExpectations();
        }
예제 #22
0
        public void IsRootDoneTest()
        {
            //Arrange
            List <Quest> list = new List <Quest>()
            {
                new FakeQuest()
                {
                    State = State.Progress
                }
            };

            Quest root = list[0];

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(mo => mo.IsInTheRoot).Repeat.Twice().Return(false);
            model.Expect(mo => mo.Parent).Repeat.Twice().Return(root);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            ActiveQuestListViewModel viewModel = new ActiveQuestListViewModel(model, stateCommands, repoCommands);

            //Act
            bool isRootDoneBefore = viewModel.IsRootHasState(State.Done);

            root.State = State.Done;
            bool isRootDoneAfter = viewModel.IsRootHasState(State.Done);

            //Assert
            Assert.IsFalse(isRootDoneBefore);
            Assert.IsTrue(isRootDoneAfter);

            stateCommands.VerifyAllExpectations();
            repoCommands.VerifyAllExpectations();
            model.VerifyAllExpectations();
        }
예제 #23
0
        public void LeavesTest()
        {
            //Arrange
            List <Quest> expectedQuests = new List <Quest>();

            IQuestListModel model = MockRepository.GenerateStrictMock <IQuestListModel>();

            model.Expect(rep => rep.Leaves).
            Repeat.Once().
            Return(expectedQuests);

            IStateCommandsFactory stateCommands = MockRepository.GenerateStrictMock <IStateCommandsFactory>();
            ITreeCommandsFactory  repoCommands  = MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            QuestListViewModel viewModel = new QuestListViewModel(model, stateCommands, repoCommands);

            //Act
            List <Quest> quests = viewModel.Leaves;

            //Assert
            Assert.IsNotNull(quests);
            Assert.AreEqual(expectedQuests, quests);
            model.VerifyAllExpectations();
        }