Exemple #1
0
        public void WhenGettingSuccessfulSubmitNotification_ThenNavigatesToQuestionnaireListView()
        {
            Action <IOperationResult> callback = null;

            Mock <IOperationResult> submitResultMock = new Mock <IOperationResult>();

            submitResultMock.Setup(sr => sr.Error).Returns <Exception>(null);

            var questionnaireRepositoryMock = new Mock <IQuestionnaireRepository>(MockBehavior.Strict);

            questionnaireRepositoryMock
            .Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >((q, a) => { callback = a; });

            string requestedViewName = null;
            var    uiServiceMock     = new Mock <ISingleViewUIService>();

            uiServiceMock
            .Setup(svc => svc.ShowView(ViewNames.QuestionnaireTemplatesList))
            .Callback <string>(viewName => requestedViewName = viewName);

            var viewModel =
                new QuestionnaireViewModel(
                    CreateStateMock(CreateQuestionnaireTemplate()).Object,
                    questionnaireRepositoryMock.Object,
                    uiServiceMock.Object);;

            CompleteQuestionnaire(viewModel);

            viewModel.Submit();

            callback(submitResultMock.Object);

            Assert.AreEqual(ViewNames.QuestionnaireTemplatesList, requestedViewName);
        }
Exemple #2
0
 public ActionResult Index(string questionAnswerFor0, string questionAnswerFor1, string questionAnswerFor2, string questionAnswerFor3)
 {
     _questionnaireVm.Submit(new List <string> {
         questionAnswerFor0, questionAnswerFor1, questionAnswerFor2, questionAnswerFor3
     });
     return(PartialView("_Answers", _questionnaireVm));
 }
        public void AfterSubmittingQuestionnaire_ThenChangeDataRelatedNotificationsAreFired()
        {
            Action <IOperationResult <Questionnaire> > callback = null;
            Action <IOperationResult> submitCallback            = null;

            var repository = new Mock <IQuestionnaireRepository>();

            repository.Setup(r => r.GetQuestionnaireAsync(It.IsAny <Action <IOperationResult <Questionnaire> > >()))
            .Callback <Action <IOperationResult <Questionnaire> > >(c => callback = c);
            repository.Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >(
                (q, sc) => submitCallback = sc);

            var viewModel = new QuestionnaireViewModel(repository.Object);

            callback(CreateQuestionnaireResult());

            var tracker = new PropertyChangeTracker(viewModel);

            viewModel.Questionnaire.Name = "TestName";
            viewModel.Questionnaire.Age  = 25;
            AnswerAllQuestions(viewModel);

            viewModel.Submit();
            submitCallback(new Mock <IOperationResult>().Object);
            callback(CreateQuestionnaireResult());

            Assert.IsTrue(tracker.ChangedProperties.Contains("Questionnaire"));
        }
        public void AfterSubmitting_ANewQuestionnaireIsCreated()
        {
            QuestionViewModel[] originalQuestions = null;
            Action <IOperationResult <Questionnaire> > callback = null;
            Action <IOperationResult> submitCallback            = null;

            var repository = new Mock <IQuestionnaireRepository>();

            repository.Setup(r => r.GetQuestionnaireAsync(It.IsAny <Action <IOperationResult <Questionnaire> > >()))
            .Callback <Action <IOperationResult <Questionnaire> > >(c => callback = c);
            repository.Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >(
                (q, sc) => submitCallback = sc);

            var viewModel = new QuestionnaireViewModel(repository.Object);

            callback(CreateQuestionnaireResult());

            originalQuestions = viewModel.Questions.ToArray();

            viewModel.Questionnaire.Name = "TestName";
            viewModel.Questionnaire.Age  = 14;
            AnswerAllQuestions(viewModel);

            viewModel.Submit();
            submitCallback(new Mock <IOperationResult>().Object);
            callback(CreateQuestionnaireResult());

            CollectionAssert.AreNotEquivalent(originalQuestions, viewModel.Questions.ToArray());
        }
        public void WhenServiceIsDoneSubmitting_ThenStateIsSetToNormal()
        {
            Action <IOperationResult <Questionnaire> > callback = null;
            Action <IOperationResult> submitCallback            = null;

            var repository = new Mock <IQuestionnaireRepository>();

            repository.Setup(r => r.GetQuestionnaireAsync(It.IsAny <Action <IOperationResult <Questionnaire> > >()))
            .Callback <Action <IOperationResult <Questionnaire> > >(c => callback = c);
            repository.Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >(
                (q, sc) => submitCallback = sc);

            var viewModel = new QuestionnaireViewModel(repository.Object);

            callback(CreateQuestionnaireResult());

            viewModel.Submit();
            Assert.AreEqual("Submitting", viewModel.CurrentState);

            var tracker = new PropertyChangeTracker(viewModel);

            // Responds as the service would.
            submitCallback(new Mock <IOperationResult>().Object);
            callback(CreateQuestionnaireResult());

            Assert.AreEqual("Normal", viewModel.CurrentState);
            CollectionAssert.Contains(tracker.ChangedProperties, "CanSubmit");
        }
Exemple #6
0
        public void ShouldReturnAllFalseAsOnlyOneAnswerEntered()
        {
            //Arrange
            List <string> answ = new List <string>();

            answ.Add("Havana");
            var questionnaireViewModel = new QuestionnaireViewModel();

            questionnaireViewModel.Submit(answ);

            var res = questionnaireViewModel.Results;

            //Assert
            Assert.That(res[0], Is.EqualTo(false));
            Assert.That(res[1], Is.EqualTo(false));
            Assert.That(res[2], Is.EqualTo(false));
            Assert.That(res[3], Is.EqualTo(false));
        }
Exemple #7
0
        public void ShouldGetAnswersWrong()
        {
            //Arrange
            List <string> answ = new List <string>();

            answ.Add("AAAAAAAAA");
            answ.Add("6534");
            answ.Add(" ");
            answ.Add("");
            var questionnaireViewModel = new QuestionnaireViewModel();

            questionnaireViewModel.Submit(answ);

            var res = questionnaireViewModel.Results;

            //Assert
            Assert.That(res[0], Is.EqualTo(false));
            Assert.That(res[1], Is.EqualTo(false));
            Assert.That(res[2], Is.EqualTo(false));
            Assert.That(res[3], Is.EqualTo(false));
        }
Exemple #8
0
        public void ShouldGetThreeWrongButOneRight()
        {
            //Arrange
            List <string> answ = new List <string>();

            answ.Add("Havasdana");
            answ.Add("PARIS");
            answ.Add(" ");
            answ.Add("");
            var questionnaireViewModel = new QuestionnaireViewModel();

            questionnaireViewModel.Submit(answ);

            var res = questionnaireViewModel.Results;

            //Assert
            Assert.That(res[0], Is.EqualTo(false));
            Assert.That(res[1], Is.EqualTo(true));
            Assert.That(res[2], Is.EqualTo(false));
            Assert.That(res[3], Is.EqualTo(false));
        }
Exemple #9
0
        public void ShouldGetAnswersCorrect()
        {
            //Arrange
            List <string> answ = new List <string>();

            answ.Add("Havana");
            answ.Add("paris");
            answ.Add("WARSAW");
            answ.Add("BeRlIn");
            var questionnaireViewModel = new QuestionnaireViewModel();

            questionnaireViewModel.Submit(answ);

            var res = questionnaireViewModel.Results;

            //Assert
            Assert.That(res[0], Is.EqualTo(true));
            Assert.That(res[1], Is.EqualTo(true));
            Assert.That(res[2], Is.EqualTo(true));
            Assert.That(res[3], Is.EqualTo(true));
        }
Exemple #10
0
        public void WhenGettingFailedSubmitNotification_ThenRaisesNotification()
        {
            Action <IOperationResult> callback = null;
            Exception error = new InvalidOperationException();

            Mock <IOperationResult> submitResultMock = new Mock <IOperationResult>();

            submitResultMock.Setup(sr => sr.Error).Returns(error);

            var questionnaireRepositoryMock = new Mock <IQuestionnaireRepository>(MockBehavior.Strict);

            questionnaireRepositoryMock
            .Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >((q, a) => { callback = a; });

            var uiServiceMock = new Mock <ISingleViewUIService>(MockBehavior.Strict);

            var viewModel =
                new QuestionnaireViewModel(
                    CreateStateMock(CreateQuestionnaireTemplate()).Object,
                    questionnaireRepositoryMock.Object,
                    uiServiceMock.Object);

            CompleteQuestionnaire(viewModel);

            InteractionRequestedEventArgs notificationArgs = null;

            viewModel.SubmitErrorInteractionRequest.Raised += (o, e) => notificationArgs = e;

            viewModel.Submit();

            callback(submitResultMock.Object);

            Assert.IsNotNull(notificationArgs);
            Assert.IsInstanceOfType(notificationArgs.Context, typeof(Notification));

            questionnaireRepositoryMock.VerifyAll();
            uiServiceMock.VerifyAll();
        }
Exemple #11
0
        public void WhenAcceptingFailedSubmitNotification_ThenStaysOnSameView()
        {
            Action <IOperationResult> callback = null;
            Exception error = new InvalidOperationException();

            Mock <IOperationResult> submitResultMock = new Mock <IOperationResult>();

            submitResultMock.Setup(sr => sr.Error).Returns(error);

            var questionnaireRepositoryMock = new Mock <IQuestionnaireRepository>(MockBehavior.Strict);

            questionnaireRepositoryMock
            .Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback <Questionnaire, Action <IOperationResult> >((q, a) => { callback = a; });

            var uiServiceMock = new Mock <ISingleViewUIService>(MockBehavior.Strict);

            var viewModel =
                new QuestionnaireViewModel(
                    CreateStateMock(CreateQuestionnaireTemplate()).Object,
                    questionnaireRepositoryMock.Object,
                    uiServiceMock.Object);

            CompleteQuestionnaire(viewModel);

            Action notificationCallback = null;

            viewModel.SubmitErrorInteractionRequest.Raised += (o, e) => notificationCallback = e.Callback;

            viewModel.Submit();

            callback(submitResultMock.Object);

            notificationCallback();

            questionnaireRepositoryMock.VerifyAll();
            uiServiceMock.VerifyAll();
        }
        public void WhenQuestionnaireIsSubmitted_ThenSubmitsToService()
        {
            Action <IOperationResult <Questionnaire> > callback = null;

            var repository = new Mock <IQuestionnaireRepository>();

            repository.Setup(r => r.GetQuestionnaireAsync(It.IsAny <Action <IOperationResult <Questionnaire> > >()))
            .Callback <Action <IOperationResult <Questionnaire> > >(c => callback = c);

            repository.Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Verifiable("SubmitQuestionnaireAsync not called");

            var viewModel = new QuestionnaireViewModel(repository.Object);

            callback(CreateQuestionnaireResult());

            viewModel.Questionnaire.Name = "Name";
            viewModel.Questionnaire.Age  = 21;
            AnswerAllQuestions(viewModel);
            viewModel.Submit();

            repository.Verify();
        }
Exemple #13
0
        public void WhenValidQuestionnaireIsSubmitted_ThenSubmitsChanges()
        {
            bool beginSubmitInvoked          = false;
            var  questionnaireRepositoryMock = new Mock <IQuestionnaireRepository>(MockBehavior.Strict);

            questionnaireRepositoryMock
            .Setup(r => r.SubmitQuestionnaireAsync(It.IsAny <Questionnaire>(), It.IsAny <Action <IOperationResult> >()))
            .Callback(() => { beginSubmitInvoked = true; });

            var uiServiceMock = new Mock <ISingleViewUIService>();

            var viewModel =
                new QuestionnaireViewModel(
                    CreateStateMock(CreateQuestionnaireTemplate()).Object,
                    questionnaireRepositoryMock.Object,
                    uiServiceMock.Object);;

            CompleteQuestionnaire(viewModel);

            viewModel.Submit();

            Assert.AreEqual("Submitting", viewModel.CurrentState);
            Assert.IsTrue(beginSubmitInvoked);
        }