public void WhenSummaryRequestOperationisCompleted_ThenUpdatesCurrentSummaryAndStatusChangesToNormal()
        {
            var questionnaireRepositoryMock = new Mock<IQuestionnaireRepository>();

            Action<IOperationResult<QuestionnaireTemplateSummary>> summaryCallback = null;
            var summary = new QuestionnaireTemplateSummary();
            questionnaireRepositoryMock
                .Setup(qs => qs.GetQuestionnaireTemplateSummaryAsync(It.IsAny<QuestionnaireTemplate>(), It.IsAny<Action<IOperationResult<QuestionnaireTemplateSummary>>>()))
                .Callback<QuestionnaireTemplate, Action<IOperationResult<QuestionnaireTemplateSummary>>>((qt, ac) => summaryCallback = ac);

            var viewModel = new QuestionnaireTemplateSummaryViewModel(questionnaireRepositoryMock.Object);

            viewModel.CurrentlySelectedQuestionnaireTemplate = new QuestionnaireTemplate();

            var summaryResult = new Mock<IOperationResult<QuestionnaireTemplateSummary>>();
            summaryResult.SetupGet(r => r.Result).Returns(summary);

            var tracker = new PropertyChangeTracker(viewModel);
            summaryCallback(summaryResult.Object);

            Assert.AreEqual("Normal", viewModel.CurrentState);
            Assert.AreSame(summary, viewModel.QuestionnaireTemplateSummary);
            CollectionAssert.Contains(tracker.ChangedProperties, "CurrentState");
            CollectionAssert.Contains(tracker.ChangedProperties, "QuestionnaireTemplateSummary");
        }
        public void WhenCurrentlySelectedTemplateChangesToNullBeforePreviousSummaryRequestOperationisCompleted_ThenStatusIsSetToNormalAndOriginalRequestOperationCompletionDoesNotCauseAnUpdate()
        {
            var questionnaireRepositoryMock = new Mock<IQuestionnaireRepository>();

            Action<IOperationResult<QuestionnaireTemplateSummary>> summaryCallback = null;
            var summary = new QuestionnaireTemplateSummary();
            questionnaireRepositoryMock
                .Setup(qs => qs.GetQuestionnaireTemplateSummaryAsync(It.IsAny<QuestionnaireTemplate>(), It.IsAny<Action<IOperationResult<QuestionnaireTemplateSummary>>>()))
                .Callback<QuestionnaireTemplate, Action<IOperationResult<QuestionnaireTemplateSummary>>>((qt, ac) => summaryCallback = ac);

            var viewModel = new QuestionnaireTemplateSummaryViewModel(questionnaireRepositoryMock.Object);

            viewModel.CurrentlySelectedQuestionnaireTemplate = new QuestionnaireTemplate();

            var originalSummaryCallback = summaryCallback;

            var summaryResult = new Mock<IOperationResult<QuestionnaireTemplateSummary>>();
            summaryResult.SetupGet(r => r.Result).Returns(summary);

            viewModel.CurrentlySelectedQuestionnaireTemplate = null;

            Assert.AreEqual("Normal", viewModel.CurrentState);
            Assert.IsNull(viewModel.QuestionnaireTemplateSummary);

            originalSummaryCallback(summaryResult.Object);

            Assert.AreEqual("Normal", viewModel.CurrentState);
            Assert.IsNull(viewModel.QuestionnaireTemplateSummary);
        }
Exemple #3
0
        private static QuestionnaireTemplateSummary CreateQuestionnaireTemplateSummary(QuestionnaireTemplate questionnaireTemplate)
        {
            var summary =
                new QuestionnaireTemplateSummary
                {
                    Title = questionnaireTemplate.Title,
                    Description = "Description",
                    EstimatedTime = questionnaireTemplate.Questions.Count * 2.5f,
                    NumberOfQuestions = questionnaireTemplate.Questions.Count,
                    TimesTaken = 0
                };

            return summary;
        }
        public void WhenQueryingForQuestionnareTemplateSummary_ThenProvidesQuestionnaireTemplateSummaryResult()
        {
            AsyncResult<QuestionnaireTemplateSummary> ar = null;
            QuestionnaireTemplateSummary suppliedQuestionnaireTemplateSummary = new QuestionnaireTemplateSummary();

            var serviceMock = new MockQuestionnaireService();

            serviceMock.HandleBeginGetQuestionnaireTemplateSummary = (r) => ar = r;


            var repository = new QuestionnaireRepository(serviceMock);

            IOperationResult<QuestionnaireTemplateSummary> getResult = null;
            repository.GetQuestionnaireTemplateSummaryAsync(new QuestionnaireTemplate(), (result) => getResult = result);

            serviceMock.ProceedGetQuestionnaireTemplateSummary(ar, suppliedQuestionnaireTemplateSummary);

            EnqueueConditional(() => getResult != null);
            EnqueueCallback(() =>
            {
                Assert.AreSame(suppliedQuestionnaireTemplateSummary, getResult.Result);
            });

            EnqueueTestComplete();
        }
 public void ProceedGetQuestionnaireTemplateSummary(AsyncResult<QuestionnaireTemplateSummary> result, QuestionnaireTemplateSummary questionnaireTemplateSummary)
 {
     result.SetComplete(questionnaireTemplateSummary, false);
 }