public void MovieTagsController_DeleteByMovieId_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.DeleteByMovieId(It.IsAny <Guid>())).Throws(dbUpdateException); //Act var result = movieTagsController.DeleteByMovieId(_movieTagDomainModel.MovieId).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_DeleteByMovieId_ServiceReturnsNull() { //Arrange IEnumerable <MovieTagsDomainModel> movieTags = null; Task <IEnumerable <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.DeleteByMovieId(It.IsAny <Guid>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByMovieId(_movieTagDomainModel.MovieId).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_DeleteByMovieId_ReturnsDeletedMovieTags() { //Arrange //Arrange List <MovieTagsDomainModel> movieTagsList = new List <MovieTagsDomainModel>(); movieTagsList.Add(_movieTagDomainModel); IEnumerable <MovieTagsDomainModel> movieTags = movieTagsList; Task <IEnumerable <MovieTagsDomainModel> > responseTask = Task.FromResult(movieTags); int expectedCount = 1; int expectedStatusCode = 202; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.DeleteByMovieId(It.IsAny <Guid>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByMovieId(_movieTagDomainModel.MovieId).ConfigureAwait(false).GetAwaiter().GetResult(); var resultMessage = ((AcceptedResult)result).Value; var resultModel = (IEnumerable <MovieTagsDomainModel>)resultMessage; //Assert Assert.IsNotNull(resultMessage); Assert.AreEqual(expectedStatusCode, ((AcceptedResult)result).StatusCode); Assert.IsInstanceOfType(resultModel.ToList()[0], typeof(MovieTagsDomainModel)); }