public void WhenViewModelIsCreated_ThenItRequestsAvailableTemplates()
        {
            bool loadRequested = false;

            var repository = new Mock<IQuestionnaireRepository>();
            repository.Setup(r =>
                    r.GetQuestionnaireTemplatesAsync(It.IsAny<Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>>>()))
                .Callback<Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>>>(c => loadRequested = true);

            var uiService = new Mock<ISingleViewUIService>();

            var viewModel = new AvailableQuestionnaireTemplatesListViewModel(repository.Object, uiService.Object);

            Assert.IsTrue(loadRequested);
            Assert.AreEqual(0, viewModel.QuestionnaireTemplates.Count);
        }
        public void WhenInitialLoadOperationIscompleted_ThenViewModelPopulatesTheCollectionOfQuestionnaireTemplates()
        {
            Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>> callback = null;

            var repository = new Mock<IQuestionnaireRepository>();
            repository.Setup(r =>
                    r.GetQuestionnaireTemplatesAsync(It.IsAny<Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>>>()))
                .Callback<Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>>>(c => callback = c);

            var uiService = new Mock<ISingleViewUIService>();

            var viewModel = new AvailableQuestionnaireTemplatesListViewModel(repository.Object, uiService.Object);

            Assert.AreEqual(0, viewModel.QuestionnaireTemplates.Count);

            callback(CreateQuestionnaireTemplates());

            Assert.AreEqual("Questionnaire #1", viewModel.QuestionnaireTemplates[0].Title);
            Assert.AreEqual("Questionnaire #2", viewModel.QuestionnaireTemplates[1].Title);
        }
        public void WhenExecutingTheTakeSurveyCommand_ThenRequestsTransitionToQuestionnaireView()
        {
            var repository = new Mock<IQuestionnaireRepository>();
            repository
                .Setup(r => r.GetQuestionnaireTemplatesAsync(It.IsAny<Action<IOperationResult<IEnumerable<QuestionnaireTemplate>>>>()));


            QuestionnaireTemplate templateRequested = null;
            var uiServiceMock = new Mock<ISingleViewUIService>();
            uiServiceMock
                .Setup(svc => svc.ShowView(ViewNames.CompleteQuestionnaire, It.IsAny<QuestionnaireTemplate>()))
                .Callback<string, QuestionnaireTemplate>((vn, qt) => templateRequested = qt);

            var template = new QuestionnaireTemplate();

            var templateViewModel =
                new AvailableQuestionnaireTemplatesListViewModel(repository.Object, uiServiceMock.Object);

            templateViewModel.TakeSurveyCommand.Execute(template);

            Assert.AreSame(template, templateRequested);
        }