public void MovieTagsController_DeleteByMovieIdTagId_ThrowsDbUpdateException() { //Arrange string expectedMessage = "Inner exception error message."; int expectedStatusCode = 400; Exception exception = new Exception("Inner exception error message."); DbUpdateException dbUpdateException = new DbUpdateException("Error.", exception); MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.DeleteByMovieIdTagId(It.IsAny <Guid>(), It.IsAny <int>())).Throws(dbUpdateException); //Act var result = movieTagsController.DeleteByMovieIdTagId(_movieTagDomainModel.MovieId, _movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult(); var resultResponse = ((BadRequestObjectResult)result); var badObjectResult = ((BadRequestObjectResult)result).Value; var errorResult = (ErrorResponseModel)badObjectResult; //Assert Assert.IsNotNull(resultResponse); Assert.AreEqual(expectedMessage, errorResult.ErrorMessage); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode); }
public void MovieTagsController_DeleteByMovieIdTagId_ServiceReturnsNull() { //Arrange MovieTagsDomainModel movieTags = null; Task <MovieTagsDomainModel> responseTask = Task.FromResult(movieTags); string expectedMessage = Messages.MOVIETAG_DOES_NOT_EXIST; int expectedStatusCode = 500; ErrorResponseModel errorResponseModel = new ErrorResponseModel(); errorResponseModel.ErrorMessage = expectedMessage; errorResponseModel.StatusCode = System.Net.HttpStatusCode.InternalServerError; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.DeleteByMovieIdTagId(It.IsAny <Guid>(), It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByMovieIdTagId(_movieTagDomainModel.MovieId, _movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult(); ObjectResult viewResult = (ObjectResult)result; //Assert Assert.IsNotNull(result); Assert.AreEqual(viewResult.Value.ToString(), errorResponseModel.ToString()); Assert.AreEqual(viewResult.StatusCode, expectedStatusCode); }
public void MovieTagsController_DeleteByMovieIdTagId_ReturnsDeletedMovieTags() { //Arrange Task <MovieTagsDomainModel> responseTask = Task.FromResult(_movieTagDomainModel); int expectedStatusCode = 202; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.DeleteByMovieIdTagId(It.IsAny <Guid>(), It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByMovieIdTagId(_movieTagDomainModel.MovieId, _movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult(); var resultMessage = ((AcceptedResult)result).Value; var resultModel = (MovieTagsDomainModel)resultMessage; //Assert Assert.IsNotNull(resultMessage); Assert.AreEqual(expectedStatusCode, ((AcceptedResult)result).StatusCode); Assert.IsInstanceOfType(resultModel, typeof(MovieTagsDomainModel)); Assert.AreEqual(resultModel.TagId, _movieTagDomainModel.TagId); Assert.AreEqual(resultModel.MovieId, _movieTagDomainModel.MovieId); }