public void MovieTagsController_DeleteByTagId_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.DeleteByTagId(It.IsAny <int>())).Throws(dbUpdateException); //Act var result = movieTagsController.DeleteByTagId(_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_DeleteByTagId_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.DeleteByTagId(It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByTagId(_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_DeleteByTagId_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.DeleteByTagId(It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.DeleteByTagId(_movieTagDomainModel.TagId).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)); }