public void Create_Returns_View() { // Arrange var expected = "Create"; // Act var actual = _quizzesController.Create() as ViewResult; // Assert Assert.AreEqual(expected, actual.ViewName); }
public void Create_action_should_return_Create_View_with_correct_model() { // Arrange var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object); // act var result = controller.Create(); // assert Assert.IsType <ViewResult>(result); Assert.NotNull(result); }
public async Task Create_post_action_result_should_return_ViewResult_with_correct_Model_type_when_modelState_not_valid() { // Arrange var quiz = new Quiz { QuizId = 3 }; // Arrange var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object); controller.ModelState.AddModelError("Title", "Title is required"); // Act var result = await controller.Create(quiz); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <Quiz>(viewResult.ViewData.Model); }
public async Task Create_post_action_result_should_redirect_to_action_when_modelState_valid() { // Arrange var quiz = new Quiz { QuizId = 3, Title = "Test" }; var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); var controller = new QuizzesController(_quizRepository.Object, _questionRepository.Object) { TempData = tempData }; // Act var result = await controller.Create(quiz); // Assert Assert.IsType <RedirectToActionResult>(result); }