Beispiel #1
0
        public void ParentIdTest()
        {
            //Arrange
            int parentId = 42;

            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            IQuestTree questRepository = MockRepository.GenerateStrictMock <IQuestTree>();

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

            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            IQuestViewModelFactory questViewModelFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            QuestCreateViewModel viewModel = new QuestCreateViewModel(
                questViewModelFactory,
                questValidator,
                questRepository,
                factory);

            //Act
            viewModel.ParentId = parentId;
            int actualParentId = viewModel.ParentId;

            //Assert
            Assert.AreEqual(parentId, actualParentId);

            questViewModel.VerifyAllExpectations();
            questRepository.VerifyAllExpectations();
            factory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            questViewModelFactory.VerifyAllExpectations();
        }
Beispiel #2
0
        public void ActionTestWithStartTimeDeadlineTest(bool useStartTime, bool useDeadLine)
        {
            //Arrange
            Quest quest  = new FakeQuest();
            Quest parent = new FakeQuest();

            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            questViewModel.Expect(qvm => qvm.Model).
            Repeat.Once().
            Return(quest);

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

            addCommand.Expect(ac => ac.Execute()).
            Return(true).
            Repeat.Once();
            addCommand.Expect(ac => ac.Commit()).
            Return(true).
            Repeat.Once();

            IQuestTree questRepository = MockRepository.GenerateStrictMock <IQuestTree>();

            questRepository.Expect(qt => qt.Get(Arg <Predicate <Quest> > .Is.NotNull)).
            Repeat.Once().
            Return(parent);

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

            factory.Expect(f => f.AddQuest(Arg <Quest> .Is.Equal(parent), Arg <Quest> .Is.Equal(quest)))
            .Return(addCommand)
            .Repeat.Once();

            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            IQuestViewModelFactory questViewModelFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            questViewModelFactory.Expect(qc => qc.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            QuestCreateViewModel viewModel = new QuestCreateViewModel(
                questViewModelFactory,
                questValidator,
                questRepository,
                factory);

            //Act
            viewModel.Initialize();
            viewModel.Action();

            //Assert
            questViewModel.VerifyAllExpectations();
            addCommand.VerifyAllExpectations();
            questRepository.VerifyAllExpectations();
            factory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            questViewModelFactory.VerifyAllExpectations();
        }
Beispiel #3
0
        public void InitializeTest()
        {
            //Arrange
            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            IQuestViewModelFactory vmFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            vmFactory.Expect(vmf => vmf.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            IQuestValidator <ClarifiedResponse <int> > validator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            MockQuestAbstractActionViewModel viewModel = new MockQuestAbstractActionViewModel(vmFactory, validator);

            //Act
            viewModel.Initialize();

            //Assert
            Assert.AreEqual(questViewModel, viewModel.QuestViewModel);

            questViewModel.VerifyAllExpectations();
            validator.VerifyAllExpectations();
        }
Beispiel #4
0
        public void CtorNullTest()
        {
            //Arrange
            IQuestTree             questTree    = MockRepository.GenerateStrictMock <IQuestTree>();
            IQuestViewModelFactory questFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();
            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();
            ITreeCommandsFactory treeCommands =
                MockRepository.GenerateStrictMock <ITreeCommandsFactory>();

            //Act
            ArgumentNullException treeEx =
                Assert.Throws <ArgumentNullException>(
                    () => new QuestCreateViewModel(questFactory, questValidator, null, treeCommands));
            ArgumentNullException treeCommandsEx =
                Assert.Throws <ArgumentNullException>(
                    () => new QuestCreateViewModel(questFactory, questValidator, questTree, null));

            //Assert
            Assert.IsNotNull(treeEx);
            Assert.IsNotNull(treeCommandsEx);

            Assert.AreEqual("questTree", treeEx.ParamName);
            Assert.AreEqual("treeCommands", treeCommandsEx.ParamName);

            questFactory.VerifyAllExpectations();
            questTree.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            treeCommands.VerifyAllExpectations();
        }
Beispiel #5
0
        public void ValidateTest()
        {
            //Act
            Quest        quest    = new FakeQuest();
            StubResponse response = new StubResponse();

            IQuestValidator <StubResponse> firstValidator = MockRepository.GenerateStrictMock <IQuestValidator <StubResponse> >();

            firstValidator.
            Expect(v => v.Validate(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(response);

            IQuestValidator <StubResponse> secondValidator = MockRepository.GenerateStrictMock <IQuestValidator <StubResponse> >();

            secondValidator.
            Expect(v => v.Validate(Arg <Quest> .Is.Equal(quest))).
            Repeat.Once().
            Return(response);

            CompositeQuestValidator <StubResponse> validator = new CompositeQuestValidator <StubResponse>(new [] { firstValidator, secondValidator });

            //Arrange
            StubResponse returnedResponse = validator.Validate(quest);

            //Assert
            Assert.IsNotNull(returnedResponse);

            firstValidator.VerifyAllExpectations();
            secondValidator.VerifyAllExpectations();
        }
Beispiel #6
0
        public void QuestIdTest()
        {
            //Arrange
            int questId = 42;

            IQuestTree             questTree    = MockRepository.GenerateStrictMock <IQuestTree>();
            IQuestViewModelFactory questFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();
            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();
            ITreeCommandsFactory treeCommands =
                MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            QuestEditViewModel vm = new QuestEditViewModel(questFactory, questValidator, questTree, treeCommands)
            {
                QuestId = questId
            };

            //Act
            int expectedQuestId = vm.QuestId;

            //Assert
            Assert.AreEqual(questId, expectedQuestId);

            questTree.VerifyAllExpectations();
            questFactory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            treeCommands.VerifyAllExpectations();
        }
Beispiel #7
0
        public void InitializeRetrieveQuestWithoutStartDeadlineFromTreeByIdTest()
        {
            int questId = 42;

            Quest model = new FakeQuest()
            {
                StartTime = null,
                Deadline  = null
            };

            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            questViewModel.Expect(qvm => qvm.Model).
            SetPropertyWithArgument(model).
            Repeat.Once();
            questViewModel.Expect(qvm => qvm.UseStartTime).
            SetPropertyWithArgument(false).
            Repeat.Once();
            questViewModel.Expect(qvm => qvm.UseDeadline).
            SetPropertyWithArgument(false).
            Repeat.Once();

            IQuestTree questTree = MockRepository.GenerateStrictMock <IQuestTree>();

            questTree.Expect(qt => qt.Get(Arg <Predicate <Quest> > .Is.NotNull)).
            Repeat.Once().
            Return(model);

            IQuestViewModelFactory questFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            questFactory.Expect(qf => qf.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();
            ITreeCommandsFactory treeCommands =
                MockRepository.GenerateStrictMock <ITreeCommandsFactory>();


            QuestEditViewModel vm = new QuestEditViewModel(questFactory, questValidator, questTree, treeCommands)
            {
                QuestId = questId
            };

            //Act
            vm.Initialize();

            //Assert
            questViewModel.VerifyAllExpectations();
            questTree.VerifyAllExpectations();
            questFactory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            treeCommands.VerifyAllExpectations();
        }
Beispiel #8
0
        public void ActionWithModelNullTest()
        {
            //Arrange
            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            questViewModel.Expect(qvm => qvm.Model).
            Repeat.Once().
            Return(null);
            questViewModel.Expect(qvm => qvm.UseStartTime).
            Repeat.Never();
            questViewModel.Expect(qvm => qvm.UseDeadline).
            Repeat.Never();


            IQuestTree questRepository = MockRepository.GenerateStrictMock <IQuestTree>();

            questRepository.Expect(qt => qt.Get(Arg <Predicate <Quest> > .Is.NotNull)).
            Repeat.Never();

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

            factory.Expect(f => f.AddQuest(Arg <Quest> .Is.Anything, Arg <Quest> .Is.Anything))
            .Repeat.Never();

            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            IQuestViewModelFactory questViewModelFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            questViewModelFactory.Expect(qc => qc.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            QuestCreateViewModel viewModel = new QuestCreateViewModel(
                questViewModelFactory,
                questValidator,
                questRepository,
                factory);

            //Act
            viewModel.Initialize();
            viewModel.Action();

            //Assert
            questViewModel.VerifyAllExpectations();
            questRepository.VerifyAllExpectations();
            factory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            questViewModelFactory.VerifyAllExpectations();
        }
Beispiel #9
0
        public void ValidateTest()
        {
            //Arrange
            Quest model = new FakeQuest();
            ClarifiedResponse <int> response = new ClarifiedResponse <int>();

            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            questViewModel.Expect(qvm => qvm.Model).
            Repeat.Once().
            Return(model);

            IQuestViewModelFactory vmFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            vmFactory.Expect(vmf => vmf.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            IQuestValidator <ClarifiedResponse <int> > validator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            validator.Expect(v => v.Validate(Arg <Quest> .Is.Equal(model))).
            Repeat.Once().
            Return(response);

            MockQuestAbstractActionViewModel viewModel = new MockQuestAbstractActionViewModel(vmFactory, validator);

            //Act
            viewModel.Initialize();
            ClarifiedResponse <int> actualResponse = viewModel.Validate();

            //Assert
            Assert.IsNotNull(actualResponse);
            Assert.AreEqual(response, actualResponse);

            questViewModel.VerifyAllExpectations();
            vmFactory.VerifyAllExpectations();
            validator.VerifyAllExpectations();
        }
Beispiel #10
0
        public void CtorNullTest()
        {
            //Arrange
            IQuestViewModelFactory viewModelFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();
            IQuestValidator <ClarifiedResponse <int> > validator = MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

            //Act
            ArgumentNullException viewModelFactoryEx =
                Assert.Throws <ArgumentNullException>(() => new MockQuestAbstractActionViewModel(null, validator));
            ArgumentNullException validatorEx =
                Assert.Throws <ArgumentNullException>(() => new MockQuestAbstractActionViewModel(viewModelFactory, null));

            //Assert
            Assert.IsNotNull(viewModelFactoryEx);
            Assert.AreEqual("questViewModelFactory", viewModelFactoryEx.ParamName);

            Assert.IsNotNull(validatorEx);
            Assert.AreEqual("questValidator", validatorEx.ParamName);

            viewModelFactory.VerifyAllExpectations();
            validator.VerifyAllExpectations();
        }
Beispiel #11
0
        public void ActionTest(bool isCommandExecuted)
        {
            int questId = 42;

            Quest model = new FakeQuest()
            {
                StartTime = DateTime.Now,
                Deadline  = DateTime.Now
            };

            IQuestViewModel questViewModel = MockRepository.GenerateStrictMock <IQuestViewModel>();

            questViewModel.Expect(qvm => qvm.Model).
            SetPropertyWithArgument(model).
            Repeat.Once();
            questViewModel.Expect(qvm => qvm.Model).
            Repeat.Once().
            Return(model);
            questViewModel.Expect(qvm => qvm.UseStartTime).
            SetPropertyWithArgument(true).
            Repeat.Once();
            questViewModel.Expect(qvm => qvm.UseDeadline).
            SetPropertyWithArgument(true).
            Repeat.Once();

            IQuestTree questTree = MockRepository.GenerateStrictMock <IQuestTree>();

            questTree.Expect(qt => qt.Get(Arg <Predicate <Quest> > .Is.NotNull)).
            Repeat.Once().
            Return(model);

            IQuestViewModelFactory questFactory = MockRepository.GenerateStrictMock <IQuestViewModelFactory>();

            questFactory.Expect(qf => qf.CreateQuestViewModel()).
            Repeat.Once().
            Return(questViewModel);

            IQuestValidator <ClarifiedResponse <int> > questValidator =
                MockRepository.GenerateStrictMock <IQuestValidator <ClarifiedResponse <int> > >();

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

            updateCommand.Expect(uc => uc.Execute()).
            Repeat.Once().
            Return(isCommandExecuted);
            if (isCommandExecuted)
            {
                updateCommand.Expect(uc => uc.Commit()).
                Repeat.Once().
                Return(true);
            }

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

            treeCommands.Expect(tc => tc.UpdateQuest(Arg <Quest> .Is.Equal(model))).
            Repeat.Once().
            Return(updateCommand);

            QuestEditViewModel vm = new QuestEditViewModel(questFactory, questValidator, questTree, treeCommands)
            {
                QuestId = questId
            };

            //Act
            vm.Initialize();
            vm.Action();

            //Assert
            questViewModel.VerifyAllExpectations();
            questTree.VerifyAllExpectations();
            questFactory.VerifyAllExpectations();
            questValidator.VerifyAllExpectations();
            updateCommand.VerifyAllExpectations();
            treeCommands.VerifyAllExpectations();
        }