public void WhenSettingTheResponseTextPropertyOnTheModel_ThenAChangeOnAvailableLengthIsNotifiedOnTheViewModel() { var question = new OpenQuestionTemplate { QuestionText = "Question", MaxLength = 25 }.CreateNewQuestion() as OpenQuestion; var viewModel = new OpenQuestionViewModel(question); var changeTracker = new PropertyChangeTracker(viewModel); question.Response = "1234567890"; Assert.IsTrue(changeTracker.ChangedProperties.Contains("AvailableLength")); }
public void WhenSelectedTemplateIsSetToNonNull_ThenSummaryIsRequestedAndStatusChangesToUpdatingSummary() { var questionnaireRepositoryMock = new Mock<IQuestionnaireRepository>(); var requestedSummary = false; questionnaireRepositoryMock .Setup(qs => qs.GetQuestionnaireTemplateSummaryAsync(It.IsAny<QuestionnaireTemplate>(), It.IsAny<Action<IOperationResult<QuestionnaireTemplateSummary>>>())) .Callback<QuestionnaireTemplate, Action<IOperationResult<QuestionnaireTemplateSummary>>>((qt, ac) => { requestedSummary = true; }); var viewModel = new QuestionnaireTemplateSummaryViewModel(questionnaireRepositoryMock.Object); var tracker = new PropertyChangeTracker(viewModel); viewModel.CurrentlySelectedQuestionnaireTemplate = new QuestionnaireTemplate(); Assert.IsTrue(requestedSummary); Assert.IsNull(viewModel.QuestionnaireTemplateSummary); Assert.AreEqual("RequestingSummary", viewModel.CurrentState); CollectionAssert.Contains(tracker.ChangedProperties, "CurrentState"); }
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"); }