public async Task Edit_action_result_method_should_return_BadRequest_when_answer_id_is_null()
        {
            // Arrange
            var controller = new AnswersController(_answerRepository.Object);

            // Act
            var result = await controller.Edit(null);

            // Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var model = Assert.IsAssignableFrom <BadRequestObjectResult>(badRequestObjectResult);

            Assert.Equal(model.StatusCode, badRequestObjectResult.StatusCode);
            Assert.NotNull(result);
        }
        public async Task Edit_post_action_result_should_return_ViewResult_with_correct_Model_type_when_modelState_not_valid()
        {
            // Arrange
            var answer = new Answer()
            {
                AnswerId = 20,
            };

            // Arrange
            var controller = new AnswersController(_answerRepository.Object);

            controller.ModelState.AddModelError("Title", "Title is required");

            // Act
            var result = await controller.Edit(answer.AnswerId, answer);

            // Assert
            Assert.IsType <ViewResult>(result);
        }
        public async Task Edit_action_result_method_should_return_NotFound_when_no_answer_found_for_id()
        {
            // Arrange
            var id             = 0;
            var expectedAnswer = _testData.GetTestAnswers().FirstOrDefault(q => q.AnswerId == id);

            _answerRepository.Setup(repo => repo.GetByAnswerId(id)).ReturnsAsync(expectedAnswer);
            var controller = new AnswersController(_answerRepository.Object);

            // Act
            var result = await controller.Edit(id);

            // Assert
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);
            var model = Assert.IsAssignableFrom <NotFoundObjectResult>(notFoundObjectResult);

            Assert.Equal(model.StatusCode, notFoundObjectResult.StatusCode);
            Assert.Equal(model.Value, notFoundObjectResult.Value);
            Assert.NotNull(result);
        }
        public async Task Edit_action_result_method_should_return_ViewResult_with_correct_Model_type()
        {
            // Arrange
            var id = 1;

            var expectedAnswer = _testData.GetTestAnswers().FirstOrDefault(q => q.AnswerId == id);

            _answerRepository.Setup(repo => repo.GetByAnswerId(id)).ReturnsAsync(expectedAnswer);

            var controller = new AnswersController(_answerRepository.Object);

            // Act
            var result = await controller.Edit(id);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <Answer>(viewResult.ViewData.Model);

            Assert.NotNull(result);
        }
        public async Task Edit_post_action_result_should_redirect_to_action_when_modelState_valid()
        {
            var id = 1;

            var answer = _testData.GetTestAnswers().FirstOrDefault(q => q.AnswerId == id);

            _answerRepository.Setup(repo => repo.GetByAnswerId(id)).ReturnsAsync(answer);

            var httpContext = new DefaultHttpContext();

            var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            var controller = new AnswersController(_answerRepository.Object)
            {
                TempData = tempData
            };

            // Act
            var result = await controller.Edit(answer.AnswerId, answer);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
        }
        public async Task Edit_post_action_result_method_should_return_BadRequest_when_id_received_different_to_answerId()
        {
            // Arrange
            var id     = 0;
            var answer = new Answer()
            {
                AnswerId   = 1,
                AnswerText = "Test"
            };

            _answerRepository.Setup(repo => repo.GetByAnswerId(id)).ReturnsAsync(answer);

            var controller = new AnswersController(_answerRepository.Object);

            // Act
            var result = await controller.Edit(id, answer);

            // Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);
            var model = Assert.IsAssignableFrom <BadRequestObjectResult>(badRequestObjectResult);

            Assert.Equal(model.StatusCode, badRequestObjectResult.StatusCode);
            Assert.NotNull(result);
        }