public void MovieTagsController_Post_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.AddMovieTag(It.IsAny <MovieTagsDomainModel>())).Throws(dbUpdateException);

            //Act

            var result          = movieTagsController.Post(_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_MovieTagServiceReturnsNull()
        {
            //Arrange
            MovieTagsDomainModel        nullDomainModel = null;
            Task <MovieTagsDomainModel> nullTask        = Task.FromResult(nullDomainModel);

            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.AddMovieTag(It.IsAny <MovieTagsDomainModel>())).Returns(nullTask);

            //Act
            var          result     = movieTagsController.Post(_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_Post_ReturnsInsertedMovieTag()
        {
            //Arrange
            Task <MovieTagsDomainModel> movieTagDomainModel = Task.FromResult(_movieTagDomainModel);
            int expectedStatusCode = 201;

            MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object);

            _mockMovieTagService.Setup(x => x.AddMovieTag(It.IsAny <MovieTagsDomainModel>())).Returns(movieTagDomainModel);

            //Act

            var result        = movieTagsController.Post(_movieTagDomainModel.MovieId, _movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult();
            var resultMessage = ((CreatedResult)result).Value;
            var resultModel   = (MovieTagsDomainModel)resultMessage;

            //Assert
            Assert.IsNotNull(resultMessage);
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
            Assert.IsInstanceOfType(resultModel, typeof(MovieTagsDomainModel));
            Assert.AreEqual(resultModel.MovieId, _movieTagDomainModel.MovieId);
        }