public async Task Details_When_Id_Is_Null_Returns_NotFound_Result() { // Arrange // Act var result = await _quizzesController.Details(null); // Assert Assert.IsInstanceOf <NotFoundResult>(result); }
public async Task Quiz_returned_by_details_view_has_all_associated_questions() { using (var context = new ApplicationDbContext(_dbContextOptions)) { var sut = new QuizzesController(context); var actionResult = await sut.Details(1); var viewResult = actionResult as ViewResult; var quiz = viewResult.Model as Quiz; quiz.Questions.Count.Should().Be(QuestionsPerQuiz); } }
public async Task Questions_returned_with_quiz_all_have_correct_quiz_id() { using (var context = new ApplicationDbContext(_dbContextOptions)) { var sut = new QuizzesController(context); var actionResult = await sut.Details(1); var viewResult = actionResult as ViewResult; var quiz = viewResult.Model as Quiz; quiz.Questions.Should().OnlyContain(question => question.QuizId == quiz.QuizId); } }
public async Task Details_action_result_method_should_return_BadRequest_when_quiz_id_is_null() { // Arrange var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object); // Act var result = await controller.Details(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 Details_returns_view_result_with_correct_quiz() { using (var context = new ApplicationDbContext(_dbContextOptions)) { var sut = new QuizzesController(context); var actionResult = await sut.Details(1); actionResult.Should().BeOfType(typeof(ViewResult)); var viewResult = actionResult as ViewResult; var quiz = viewResult.Model as Quiz; quiz.QuizId.Should().Be(1); } }
public async Task Questions_returned_with_quiz_have_all_associated_answers() { using (var context = new ApplicationDbContext(_dbContextOptions)) { var sut = new QuizzesController(context); var actionResult = await sut.Details(1); var viewResult = actionResult as ViewResult; var quiz = viewResult.Model as Quiz; var questions = quiz.Questions; foreach (var question in questions) { question.AnswerOptions.Count.Should().Be(AnswersPerQuestion); question.AnswerOptions.Should().OnlyContain(answer => answer.QuestionId == question.QuestionId); } } }
public async Task Details_action_result_method_should_return_ViewResult_with_correct_Model_type() { // Arrange var id = 1; var expectedQuiz = _testData.GetTestQuizzes().FirstOrDefault(q => q.QuizId == id); _quizRepository.Setup(repo => repo.GetById(id)).ReturnsAsync(expectedQuiz); var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object); // Act var result = await controller.Details(id); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <DetailsQuizViewModel>(viewResult.ViewData.Model); Assert.NotNull(result); Assert.Equal(expectedQuiz.QuizId, model.Quiz.QuizId); }
public async Task Details_action_result_method_should_return_NotFound_when_no_quiz_found_for_id() { // Arrange var id = 0; var expectedQuiz = _testData.GetTestQuizzes().FirstOrDefault(q => q.QuizId == id); _quizRepository.Setup(repo => repo.GetById(id)).ReturnsAsync(expectedQuiz); var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object); // Act var result = await controller.Details(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); }