public async Task NullViewModelReturnsBadRequest()
        {
            QuestionGetRequestViewModel viewModel = null;
            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <BadRequestResult>(actionResponse);
        }
        public async Task QuestionsMustBeAnsweredInOrder()
        {
            var viewModel = new QuestionGetRequestViewModel()
            {
                QuestionNumber = 2, AssessmentType = "name1"
            };
            var expectedQuestion = new GetQuestionResponse()
            {
                MaxQuestionsCount = 3, QuestionNumber = 1
            };
            var expectedAssessment = new GetAssessmentResponse()
            {
                CurrentQuestionNumber = 1
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(viewModel.AssessmentType, viewModel.QuestionNumber)).Returns(expectedQuestion);
            A.CallTo(() => ApiService.GetAssessment()).Returns(expectedAssessment);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <RedirectResult>(actionResponse);

            var redirectResult = actionResponse as RedirectResult;

            Assert.Equal($"~/{RouteName.Prefix}/assessment/name1/1", redirectResult.Url);
        }
        public async Task IfAnswerIsValidMovesToNextQuestion()
        {
            var answerRequest = new QuestionPostRequestViewModel()
            {
                QuestionNumber = 3, AssessmentType = "short", Answer = "answer1"
            };
            var currentQuestion = new GetQuestionResponse()
            {
                MaxQuestionsCount = 10, CurrentQuestionNumber = 3, NextQuestionNumber = 4
            };
            var answerResponse = new PostAnswerResponse()
            {
                IsSuccess = true, NextQuestionNumber = 4
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(answerRequest.AssessmentType, answerRequest.QuestionNumber)).Returns(currentQuestion);
            A.CallTo(() => ApiService.AnswerQuestion(answerRequest.AssessmentType, answerRequest.QuestionNumber, answerRequest.QuestionNumber, answerRequest.Answer)).Returns(answerResponse);

            var actionResponse = await AssessmentController.Index(answerRequest).ConfigureAwait(false);

            Assert.IsType <RedirectResult>(actionResponse);
            var redirectResult = actionResponse as RedirectResult;

            Assert.Equal($"~/{RouteName.Prefix}/assessment/short/4", redirectResult.Url);
        }
        public async Task IfNoAnswerIsProvidedReturnsView()
        {
            var viewModel = new QuestionPostRequestViewModel()
            {
                QuestionNumber = 3, AssessmentType = "short"
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <ViewResult>(actionResponse);
        }
        public async Task IfNoSessionExistsRedirectedToRoot()
        {
            var viewModel = A.Fake <QuestionGetRequestViewModel>();

            A.CallTo(() => Session.HasValidSession()).Returns(false);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <RedirectResult>(actionResponse);

            var redirectResult = actionResponse as RedirectResult;

            Assert.Equal($"~/{RouteName.Prefix}/", redirectResult.Url);
        }
        public async Task IfQuestionDoesNotExistsReturnsBadRequest()
        {
            var viewModel = new QuestionGetRequestViewModel()
            {
                AssessmentType = "at1", QuestionNumber = 1
            };
            GetQuestionResponse expectedQuestion = null;

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(viewModel.AssessmentType, viewModel.QuestionNumber)).Returns(expectedQuestion);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <BadRequestResult>(actionResponse);
        }
        public async Task GetAssessmentWhenAssessmentDoesntExistReturnsBadResponse()
        {
            var viewModel = new QuestionGetRequestViewModel()
            {
                QuestionNumber = 2, AssessmentType = "name1"
            };
            var expectedQuestion = new GetQuestionResponse();
            GetAssessmentResponse expectedAssessment = null;

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(viewModel.AssessmentType, viewModel.QuestionNumber)).Returns(expectedQuestion);
            A.CallTo(() => ApiService.GetAssessment()).Returns(expectedAssessment);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <BadRequestResult>(actionResponse);
        }
        public async Task IfQuestionNumberIsGreaterThanMaxMaxQuestionsCountReturnsBadRequest()
        {
            var viewModel = new QuestionGetRequestViewModel()
            {
                QuestionNumber = 3, AssessmentType = "name1"
            };
            var expectedQuestion = new GetQuestionResponse()
            {
                MaxQuestionsCount = 2
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(viewModel.AssessmentType, 1)).Returns(expectedQuestion);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <BadRequestResult>(actionResponse);
        }
        public async Task IfAssessmentIsCompleteRedirectsToResults()
        {
            var viewModel = new QuestionGetRequestViewModel()
            {
                QuestionNumber = 2, AssessmentType = "name1"
            };
            var expectedQuestion = new GetQuestionResponse()
            {
                MaxQuestionsCount = 2, IsComplete = true
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(viewModel.AssessmentType, viewModel.QuestionNumber)).Returns(expectedQuestion);

            var actionResponse = await AssessmentController.Index(viewModel).ConfigureAwait(false);

            Assert.IsType <RedirectResult>(actionResponse);

            var redirectResult = actionResponse as RedirectResult;

            Assert.Equal($"~/{RouteName.Prefix}/results", redirectResult.Url);
        }
        public async Task WhenAllAnswersAreProvidedAssessmentIsCompleted()
        {
            var answerRequest = new QuestionPostRequestViewModel()
            {
                QuestionNumber = 3, AssessmentType = "name1", Answer = "answer1"
            };
            var currentQuestion = new GetQuestionResponse();
            var answerResponse  = new PostAnswerResponse()
            {
                IsSuccess = true, IsComplete = true
            };

            A.CallTo(() => Session.HasValidSession()).Returns(true);
            A.CallTo(() => ApiService.GetQuestion(answerRequest.AssessmentType, answerRequest.QuestionNumber)).Returns(currentQuestion);
            A.CallTo(() => ApiService.AnswerQuestion(answerRequest.AssessmentType, answerRequest.QuestionNumber, answerRequest.QuestionNumber, answerRequest.Answer)).Returns(answerResponse);

            var actionResponse = await AssessmentController.Index(answerRequest).ConfigureAwait(false);

            Assert.IsType <RedirectResult>(actionResponse);
            var redirectResult = actionResponse as RedirectResult;

            Assert.Equal($"~/{RouteName.Prefix}/assessment/complete", redirectResult.Url);
        }
Ejemplo n.º 11
0
        public void Index_NoParameterProvided_ShouldReturnIndexView()
        {
            var result = _controller.Index((Guid?)null) as RedirectToRouteResult;

            result.ShouldBeEquivalentTo(null);
        }
Ejemplo n.º 12
0
        public void IndexGET_DefaultViewShouldBeReturned()
        {
            var result = _assessmentController.Index(Guid.NewGuid()) as ViewResult;

            result.ViewName.Should().BeEmpty();
        }