Пример #1
0
        public void PatchAsync_MovieDoesNotExist_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = Messages.MOVIE_DOES_NOT_EXIST;
            int    expectedStatusCode = 400;

            MovieDomainModel        movieDomainModel = null;
            Task <MovieDomainModel> responseTask     = Task.FromResult(movieDomainModel);

            _movieService  = new Mock <IMovieService>();
            _loggerService = new Mock <ILogger <MoviesController> >();
            _movieService.Setup(x => x.GetMovieByIdAsync(It.IsAny <Guid>())).Returns(responseTask);

            MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object);

            //Act
            var result        = moviesController.ChangeCurrent(Guid.NewGuid()).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult  = ((BadRequestObjectResult)result).Value;
            var errorResponse = (ErrorResponseModel)objectResult;

            //Assert
            Assert.IsNotNull(errorResponse);
            Assert.AreEqual(expectedMessage, errorResponse.ErrorMessage);
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }
Пример #2
0
        public void PatchAsync_IsNot_Successful_Movie_Cannot_Be_Patched_Return_BadRequest()
        {
            //Arrange
            MovieDomainModel movieDomainModel = new MovieDomainModel
            {
                Id       = Guid.NewGuid(),
                Current  = true,
                HasOscar = true,
                Rating   = 2,
                Title    = "Film1",
                Year     = 2015
            };

            MovieResultModel movieResultModel = new MovieResultModel
            {
                Movie        = movieDomainModel,
                IsSuccessful = false,
                ErrorMessage = Messages.MOVIE_DEACTIVATION_ERROR
            };

            string expectedMessage    = "Cannot deactivate movie which has future projections";
            int    expectedStatusCode = 400;

            Task <MovieDomainModel> responseTask1 = Task.FromResult(movieDomainModel);
            Task <MovieResultModel> responseTask2 = Task.FromResult(movieResultModel);

            _movieService  = new Mock <IMovieService>();
            _loggerService = new Mock <ILogger <MoviesController> >();
            _movieService.Setup(x => x.GetMovieByIdAsync(It.IsAny <Guid>())).Returns(responseTask1);
            _movieService.Setup(x => x.Activate_DeactivateMovie(It.IsAny <Guid>())).Returns(responseTask2);

            MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object);

            //Act
            var result        = moviesController.ChangeCurrent(Guid.NewGuid()).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult  = ((BadRequestObjectResult)result).Value;
            var errorResponse = (ErrorResponseModel)objectResult;

            //Assert
            Assert.IsNotNull(errorResponse);
            Assert.AreEqual(expectedMessage, errorResponse.ErrorMessage);
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }
Пример #3
0
        public void PatchAsync_ChangeCurrent_IsSuccessful_Current_Field_Changed()
        {
            //Arrange
            MovieDomainModel movieDomainModel = new MovieDomainModel
            {
                Id       = Guid.NewGuid(),
                Current  = true,
                HasOscar = true,
                Rating   = 2,
                Title    = "Film1",
                Year     = 2015
            };

            MovieResultModel movieResultModel = new MovieResultModel
            {
                Movie        = movieDomainModel,
                IsSuccessful = true,
                ErrorMessage = null
            };
            int expectedStatusCode = 202;
            Task <MovieResultModel> responseTask  = Task.FromResult(movieResultModel);
            Task <MovieDomainModel> responseTask2 = Task.FromResult(movieDomainModel);

            _movieService  = new Mock <IMovieService>();
            _loggerService = new Mock <ILogger <MoviesController> >();
            _movieService.Setup(x => x.GetMovieByIdAsync(It.IsAny <Guid>())).Returns(responseTask2);
            _movieService.Setup(x => x.Activate_DeactivateMovie(It.IsAny <Guid>())).Returns(responseTask);
            MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object);

            //Act
            var result                 = moviesController.ChangeCurrent(movieDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult           = ((AcceptedResult)result).Value;
            var movieDomainModelResult = (MovieDomainModel)objectResult;

            //Assert
            Assert.IsNotNull(movieDomainModelResult);
            Assert.IsInstanceOfType(result, typeof(AcceptedResult));
            Assert.AreEqual(expectedStatusCode, ((AcceptedResult)result).StatusCode);
        }
Пример #4
0
        public void PatchAsync_DbUpdateException_Throw()
        {
            //Arrange
            MovieDomainModel movieDomainModel = new MovieDomainModel
            {
                Id       = Guid.NewGuid(),
                Current  = true,
                HasOscar = true,
                Rating   = 2,
                Title    = "Film1",
                Year     = 2015
            };
            string                  expectedMessage    = "Inner exception error message.";
            int                     expectedStatusCode = 400;
            Exception               exception          = new Exception("Inner exception error message.");
            DbUpdateException       dbUpdateException  = new DbUpdateException("Error.", exception);
            Task <MovieDomainModel> responseTask       = Task.FromResult(movieDomainModel);

            _movieService  = new Mock <IMovieService>();
            _loggerService = new Mock <ILogger <MoviesController> >();
            _movieService.Setup(x => x.GetMovieByIdAsync(It.IsAny <Guid>())).Returns(responseTask);
            _movieService.Setup(x => x.Activate_DeactivateMovie(It.IsAny <Guid>())).Throws(dbUpdateException);

            MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object);

            //Act
            var result        = moviesController.ChangeCurrent(Guid.NewGuid()).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var objectResult  = ((BadRequestObjectResult)result).Value;
            var errorResponse = (ErrorResponseModel)objectResult;

            //Assert
            Assert.IsNotNull(errorResponse);
            Assert.AreEqual(expectedMessage, errorResponse.ErrorMessage);
            Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }