public async Task Delete_When_Id_Is_Null_Returns_NotFoundResult() { // Arrange // Act var result = await _quizzesController.Delete(null); // Assert Assert.IsInstanceOf <NotFoundResult>(result); }
public async Task Delete_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.Delete(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 DeleteThrowsException() { const int userId = 56; const int quizId = 56; var quizManager = new Mock <IQuizManager>(); quizManager.Setup(c => c.DeleteQuiz(userId, quizId)) .Returns(Task.FromResult(true)); var sut = new QuizzesController(quizManager.Object); var result = await sut.Delete(quizId); Assert.AreEqual(HttpStatusCode.OK, (HttpStatusCode)result.StatusCode); }
public async Task Delete_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.Delete(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 Delete_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.Delete(id); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <Quiz>(viewResult.ViewData.Model); Assert.NotNull(result); Assert.Equal(expectedQuiz.QuizId, model.QuizId); }
public async Task DeleteReturnsOk(HttpStatusCode expected, bool response) { const int userId = 56; const int quizId = 56; var quizManager = new Mock <IQuizManager>(); quizManager.Setup(c => c.DeleteQuiz(userId, quizId)) .Returns(Task.FromResult(response)); var sut = new QuizzesController(quizManager.Object); sut.Token = new AuthToken { Token = "token", UserId = userId, ValidUntil = DateTime.Now.AddDays(1), IsVerified = true }; var result = await sut.Delete(quizId); Assert.AreEqual(expected, (HttpStatusCode)result.StatusCode); }