示例#1
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();
        }
示例#2
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();
        }
示例#3
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();
        }
示例#4
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();
        }
        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();
        }
        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();
        }
        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();
        }
示例#8
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();
        }
        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();
        }
        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();
        }
示例#12
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();
        }
示例#13
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();
        }
        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();
        }
        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();
        }
示例#16
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();
        }
        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();
        }