public void TestInitialize() { _movie = new Movie { Id = Guid.NewGuid(), Current = true, Rating = 5, Title = "NazivFilma", Year = 1999 }; _movieDomainModel = new MovieDomainModel { Id = _movie.Id, Current = _movie.Current, Rating = 5, Title = _movie.Title, Year = _movie.Year }; List <Movie> movieList = new List <Movie>(); movieList.Add(_movie); IEnumerable <Movie> movies = movieList; Task <IEnumerable <Movie> > responseTask = Task.FromResult(movies); _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMovieTagService = new Mock <IMovieTagService>(); _mockProjectionService = new Mock <IProjectionService>(); }
public void Delete_Not_Successful_Return_BadRequest() { //Arrange int expectedStatusCode = 400; string expectedMessage = Messages.MOVIE_DOES_NOT_EXIST; Guid g = new Guid(); MovieDomainModel movieDomainModel = null; Task <MovieDomainModel> responseTask = Task.FromResult(movieDomainModel); _movieService = new Mock <IMovieService>(); _loggerService = new Mock <ILogger <MoviesController> >(); _movieService.Setup(x => x.DeleteMovie(It.IsAny <Guid>())).Returns(responseTask); MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object); //Act var result = moviesController.Delete(g).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((BadRequestObjectResult)result).Value; var errorResponse = (ErrorResponseModel)resultList; Assert.IsNotNull(errorResponse); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); Assert.AreEqual(expectedStatusCode, ((BadRequestObjectResult)result).StatusCode); Assert.AreEqual(expectedMessage, errorResponse.ErrorMessage); }
public void Get_Movie_By_Id_Successful() { //Arrange int expectedStatusCode = 200; MovieDomainModel movieDomainModel = new MovieDomainModel { Id = Guid.NewGuid(), Current = true, HasOscar = true, Rating = 2, Title = "Film1", Year = 2015 }; 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.GetAsync(new Guid()).ConfigureAwait(false).GetAwaiter().GetResult().Result; var objectResult = ((OkObjectResult)result).Value; MovieDomainModel movieModelResult = (MovieDomainModel)objectResult; //Assert Assert.IsNotNull(objectResult); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); }
public async Task <IEnumerable <MovieDomainModel> > GetCurrentAndNotCurrentMovies() { var data = await _moviesRepository.GetCurrentAndNotCurrentMovies(); if (data == null) { return(null); } List <MovieDomainModel> result = new List <MovieDomainModel>(); MovieDomainModel model; foreach (var item in data) { model = new MovieDomainModel { Current = item.Current, Id = item.Id, Rating = item.Rating ?? 0, Title = item.Title, Year = item.Year }; result.Add(model); } return(result); }
public async Task <MovieDomainModel> AddMovie(MovieDomainModel newMovie) { Movie movieToCreate = new Movie() { Id = Guid.NewGuid(), Title = newMovie.Title, Current = newMovie.Current, Year = newMovie.Year, Rating = newMovie.Rating, HasOscar = newMovie.HasOscar }; var data = _moviesRepository.Insert(movieToCreate); if (data == null) { return(null); } _moviesRepository.Save(); MovieDomainModel domainModel = new MovieDomainModel() { Id = data.Id, Title = data.Title, Current = data.Current, Year = data.Year, Rating = data.Rating ?? 0, HasOscar = data.HasOscar }; return(domainModel); }
public void Get_Movie_By_Id_Return_Not_Found() { //Arrange int expectedStatusCode = 404; string expectedMessage = Messages.MOVIE_DOES_NOT_EXIST; 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.GetAsync(new Guid()).ConfigureAwait(false).GetAwaiter().GetResult().Result; var objectResult = ((NotFoundObjectResult)result).Value; string errorMessage = (string)objectResult; //Assert Assert.IsNotNull(objectResult); Assert.AreEqual(expectedMessage, errorMessage); Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode); Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult)); }
public async Task <MovieResultModel> ActivateMovie(Guid id) { var movie = await _moviesRepository.GetByIdAsync(id); if (movie == null) { return(new MovieResultModel { IsSuccessful = false, ErrorMessage = Messages.MOVIE_DOES_NOT_EXIST }); } var activatedMovie = await _moviesRepository.ActivateCurrentMovie(movie.Id); _moviesRepository.Save(); MovieDomainModel activatedModel = new MovieDomainModel { Id = movie.Id, Current = activatedMovie.Current, Rating = movie.Rating ?? 0, Title = movie.Title, Year = movie.Year, HasOscar = movie.HasOscar }; return(new MovieResultModel { IsSuccessful = true, Movie = activatedModel }); }
public async Task <MovieDomainModel> UpdateMovie(MovieDomainModel updateMovie) { Movie movie = new Movie() { Id = updateMovie.Id, Title = updateMovie.Title, Current = updateMovie.Current, Year = updateMovie.Year, Rating = updateMovie.Rating, HasOscar = updateMovie.HasOscar }; var data = _moviesRepository.Update(movie); if (data == null) { return(null); } _moviesRepository.Save(); MovieDomainModel domainModel = new MovieDomainModel() { Id = data.Id, Title = data.Title, Current = data.Current, Year = data.Year, Rating = data.Rating ?? 0, HasOscar = data.HasOscar }; return(domainModel); }
public void MovieService_GetAllMoviesWithThisTag_CreateMovieResultModel_ReturnListWithMovieDomainModels() { //Arrange MovieDomainModel movieDomainModel = _movieDomainModel; string stringToSearch = "Type NameTag"; int expectedResultCount = 1; IEnumerable <MovieDomainModel> expectedResult; expectedResult = _movieDomainModels; IEnumerable <MovieTag> movieTags = _movieTagsList; Task <IEnumerable <MovieTag> > responseTaskMovieTagRepository = Task.FromResult(movieTags); IEnumerable <Movie> movies = moviesModelsList; Task <IEnumerable <Movie> > responseTaskMovieRepository = Task.FromResult(movies); _mockMovieTagsRepository = new Mock <IMovieTagsRepository>(); _mockMovieTagsRepository.Setup(x => x.GetAll()).Returns(responseTaskMovieTagRepository); _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMoviesRepository.Setup(x => x.GetAllWithMovieTags()).Returns(responseTaskMovieRepository); MovieService movieController = new MovieService(_mockMoviesRepository.Object, _mockProjectionsRepository.Object, _mockMovieTagsRepository.Object, _mockTicketRepository.Object, _mockTagRepository.Object); //Act var resultAction = movieController.GetAllMoviesWithThisTag(stringToSearch).ConfigureAwait(false).GetAwaiter().GetResult(); var result = (List <MovieDomainModel>)resultAction; //Assert Assert.IsNotNull(result); Assert.AreEqual(expectedResultCount, result.Count); Assert.IsInstanceOfType(result[0], typeof(MovieDomainModel)); }
public void MovieService_GetAllMoviesWithThisTag_CreateMovieResultModel_ReturnNull_NotFilmsWithAllTagsRequired() { //Arrange MovieDomainModel movieDomainModel = _movieDomainModel; string stringToSearch = "string NameTag"; IEnumerable <MovieTag> movieTags = _movieTagsList; Task <IEnumerable <MovieTag> > responseTaskMovieTagRepository = Task.FromResult(movieTags); IEnumerable <Movie> movies = moviesModelsList; Task <IEnumerable <Movie> > responseTaskMovieRepository = Task.FromResult(movies); _mockMovieTagsRepository = new Mock <IMovieTagsRepository>(); _mockMovieTagsRepository.Setup(x => x.GetAll()).Returns(responseTaskMovieTagRepository); _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMoviesRepository.Setup(x => x.GetAllWithMovieTags()).Returns(responseTaskMovieRepository); MovieService movieController = new MovieService(_mockMoviesRepository.Object, _mockProjectionsRepository.Object, _mockMovieTagsRepository.Object, _mockTicketRepository.Object, _mockTagRepository.Object); //Act var resultAction = movieController.GetAllMoviesWithThisTag(stringToSearch).ConfigureAwait(false).GetAwaiter().GetResult(); var result = (List <MovieDomainModel>)resultAction; //Assert Assert.IsNull(resultAction); }
public async Task <IEnumerable <MovieDomainModel> > GetTopMovies() { var movies = await _moviesRepository.GetAll(); if (movies == null) { return(null); } movies = movies.Where(movie => movie.Current == true); movies = movies.OrderByDescending(movie => movie.Rating).ThenByDescending(movie => movie.HasOscar).Take(10); List <MovieDomainModel> result = new List <MovieDomainModel>(); MovieDomainModel model; foreach (var item in movies) { model = new MovieDomainModel { Current = item.Current, Id = item.Id, Rating = item.Rating ?? 0, Title = item.Title, Year = item.Year, HasOscar = item.HasOscar }; result.Add(model); } return(result); }
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)); }
public void MovieService_UpdateMovie_ReturnCreateMovieResultModel_NotSuccessful_Update() { Movie movie = _movie; MovieDomainModel movieDomainModel = _movieDomainModel; Movie movieNull = null; var expectedResult = new CreateMovieResultModel() { ErrorMessage = "Error occured while updating current movie status, please try again.", IsSuccessful = false }; IEnumerable <Projection> listaProjekcija = new List <Projection>(); var id = Guid.NewGuid(); Task <Movie> responseTask = Task.FromResult(movie); _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMoviesRepository.Setup(x => x.GetByIdAsync(_movieDomainModel.Id)).Returns(responseTask); Task <IEnumerable <Projection> > responseTaskProjection = Task.FromResult(listaProjekcija); _mockProjectionsRepository = new Mock <IProjectionsRepository>(); _mockProjectionsRepository.Setup(y => y.GetAllFromOneMovie(_movieDomainModel.Id)).Returns(responseTaskProjection); _mockMoviesRepository.Setup(x => x.Update(movie)).Returns(movieNull); MovieService movieController = new MovieService(_mockMoviesRepository.Object, _mockProjectionsRepository.Object, _mockMovieTagsRepository.Object, _mockTicketRepository.Object, _mockTagRepository.Object); //Act var resultAction = movieController.UpdateMovie(movieDomainModel).ConfigureAwait(false).GetAwaiter().GetResult(); var result = resultAction; //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(CreateMovieResultModel)); Assert.AreEqual(expectedResult.ErrorMessage, result.ErrorMessage); Assert.AreEqual(expectedResult.IsSuccessful, result.IsSuccessful); }
public async Task <IEnumerable <MovieDomainModel> > GetAllMoviesFilterWithNonCurrent(bool?isCurrent, MovieQuery query) { var data = await _moviesRepository.GetAll(); if (query.ActorName != null) { data = data.Where(x => x.MovieActors.Any(a => a.Actor.FirstName.ToLower().Contains(query.ActorName.ToLower()))); } if (query.Title != null) { data = data.Where(x => x.Title.ToLower().Contains(query.Title.ToLower())); } if (query.RatingLowerThan > 0) { data = data.Where(x => x.Rating < query.RatingLowerThan); } if (query.RatingBiggerThan > 0) { data = data.Where(x => x.Rating > query.RatingBiggerThan); } if (query.YearLowerThan > 0) { data = data.Where(x => x.Year < query.YearLowerThan); } if (query.YearBiggerThan > 0) { data = data.Where(x => x.Year > query.YearBiggerThan); } if (query.HasOscar != null) { data = data.Where(x => x.HasOscar == query.HasOscar); } List <MovieDomainModel> result = new List <MovieDomainModel>(); MovieDomainModel model; foreach (var item in data) { model = new MovieDomainModel { Current = item.Current, Id = item.Id, Rating = item.Rating ?? 0, Title = item.Title, Year = item.Year, HasOscar = item.HasOscar }; result.Add(model); } return(result); }
public MovieService_UpdateMovieShould() { _newMovieDto = _fixture.Create <MovieDtoModel>(); _newMovieDomainModel = _fixture.Create <MovieDomainModel>(); _mapper.Setup(_ => _.Map <MovieDtoModel>(It.IsAny <MovieDomainModel>())).Returns(_newMovieDto); _mapper.Setup(_ => _.Map <MovieDomainModel>(_newMovieDto)).Returns(_newMovieDomainModel); }
public async Task <ActionResult> CreateNewMovieWithHisTags([FromBody] CreateMovieModel movieModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MovieDomainModel domainModel = new MovieDomainModel { Current = movieModel.Current, Rating = movieModel.Rating, Title = movieModel.Title, Year = movieModel.Year }; MovieCreateTagDomainModel movieCreateTagDomainModel = new MovieCreateTagDomainModel { Duration = movieModel.Duration, tagsForMovieToAdd = movieModel.listOfTags }; MovieDomainModel createMovie; try { createMovie = await _movieService.AddMovie(domainModel, movieCreateTagDomainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createMovie == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.MOVIE_CREATION_ERROR, StatusCode = System.Net.HttpStatusCode.InternalServerError }; return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, errorResponse)); } return(Created("movies//" + createMovie.Id, createMovie)); }
public IEnumerable <MovieDomainModel> GetAllCurrentMovies() { var data = _moviesRepository.GetCurrentMovies(); if (data == null) { return(null); } List <MovieDomainModel> result = new List <MovieDomainModel>(); MovieDomainModel model; foreach (Movie movie in data) { List <ProjectionDomainModel> listOfProjs = new List <ProjectionDomainModel>(); if (movie.Projections != null) { foreach (Projection projection in movie.Projections) { ProjectionDomainModel projModel = new ProjectionDomainModel { Id = projection.Id, MovieId = projection.MovieId, MovieTitle = projection.Movie.Title, AuditoriumId = projection.AuditoriumId, ProjectionTime = projection.DateTime, }; listOfProjs.Add(projModel); } } model = new MovieDomainModel { Current = movie.Current, Id = movie.Id, Rating = movie.Rating ?? 0, Title = movie.Title, Year = movie.Year, Projections = listOfProjs, BannerUrl = movie.BannerUrl }; result.Add(model); } return(result); }
public void Get_Current_Movies_Return_All() { //Arrange int expectedCount = 1; int expectedStatusCode = 200; MovieDomainModel movieDomainModel = new MovieDomainModel { Id = Guid.NewGuid(), Current = true, HasOscar = false, Rating = 2, Title = "Film1", Year = 2015 }; MovieQuery movieQuery = new MovieQuery { HasOscar = true }; List <MovieDomainModel> movieDomainModels = new List <MovieDomainModel>(); movieDomainModels.Add(movieDomainModel); IEnumerable <MovieDomainModel> movieDomainModelsIEn = movieDomainModels; IEnumerable <MovieDomainModel> response = movieDomainModelsIEn; _movieService = new Mock <IMovieService>(); _loggerService = new Mock <ILogger <MoviesController> >(); _movieService.Setup(x => x.GetAllMovies(It.IsAny <bool>(), It.IsAny <MovieQuery>())).Returns(response); MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object); //Act var result = moviesController.GetAsync(movieQuery).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var movieDomainModelResultList = (List <MovieDomainModel>)resultList; //Assert Assert.IsNotNull(resultList); Assert.AreEqual(expectedCount, movieDomainModelResultList.Count); Assert.AreEqual(movieDomainModel.Id, movieDomainModelResultList[0].Id); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void MovieService_AddMovie_ReturnNull() { //Arrange MovieDomainModel movieDomainModel = _movieDomainModel; MovieCreateTagDomainModel movieCreate = new MovieCreateTagDomainModel(); Movie movie = null; _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMoviesRepository.Setup(x => x.Insert(It.IsAny <Movie>())).Returns(movie); MovieService movieController = new MovieService(_mockMoviesRepository.Object, _mockProjectionsRepository.Object, _mockMovieTagsRepository.Object, _mockTicketRepository.Object, _mockTagRepository.Object); //Act var resultAction = movieController.AddMovie(movieDomainModel, movieCreate).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNull(resultAction); }
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)); }
public void GetAllMovies_Async_Return_All_Movies_Non_Current_Included() { //Arrange List <MovieDomainModel> moviesDomainModelsList = new List <MovieDomainModel>(); MovieDomainModel movieDomainModel = new MovieDomainModel { Id = Guid.NewGuid(), Current = true, HasOscar = true, Rating = 2, Title = "Film1", Year = 2015 }; moviesDomainModelsList.Add(movieDomainModel); IEnumerable <MovieDomainModel> movieDomainModels = moviesDomainModelsList; Task <IEnumerable <MovieDomainModel> > responseTask = Task .FromResult(movieDomainModels); int expectedResultCount = 1; int expectedStatusCode = 200; _movieService = new Mock <IMovieService>(); _loggerService = new Mock <ILogger <MoviesController> >(); _movieService.Setup(x => x.GetAllMoviesNonCurrentIncluded()).Returns(responseTask); MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object); //Act var result = moviesController.GetAllMovies().ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var movieDomainModelResultList = (List <MovieDomainModel>)resultList; //Assert Assert.IsNotNull(movieDomainModelResultList); Assert.AreEqual(expectedResultCount, movieDomainModelResultList.Count); Assert.AreEqual(movieDomainModel.Id, movieDomainModelResultList[0].Id); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public async Task <MovieDomainModel> GetMovieByIdAsync(Guid id) { var data = await _moviesRepository.GetByIdAsync(id); if (data == null) { return(null); } MovieDomainModel domainModel = new MovieDomainModel { Id = data.Id, Current = data.Current, Rating = data.Rating ?? 0, Title = data.Title, Year = data.Year }; return(domainModel); }
public void TestInitialize() { List <Projection> projections = new List <Projection>(); _movie = new Movie { Id = Guid.NewGuid(), Current = true, HasOscar = true, Rating = 7, Title = "Smekerski film", Year = 2021, Projections = projections }; _movieDomainModel = new MovieDomainModel { Id = _movie.Id, Current = _movie.Current, HasOscar = _movie.HasOscar, Rating = _movie.Rating ?? 0, Title = _movie.Title, Year = _movie.Year }; List <Movie> movieModelsList = new List <Movie>(); movieModelsList.Add(_movie); IEnumerable <Movie> movies = movieModelsList; Task <IEnumerable <Movie> > responseTask = Task.FromResult(movies); query = new MovieQuery { HasOscar = null }; _mockMovieRepository = new Mock <IMoviesRepository>(); _mockProjectionRepository = new Mock <IProjectionsRepository>(); _mockMovieRepository.Setup(x => x.GetCurrentMovies()).Returns(movieModelsList); _mockMovieRepository.Setup(x => x.Insert(It.IsAny <Movie>())).Returns(_movie); _mockMovieRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(_movie); }
public void GetMoviesByAuditoriumId_ReturnAll() { //Arrange int expectedCount = 1; int expectedStatusCode = 200; int auditoriumId = 25; MovieDomainModel movieDomainModel = new MovieDomainModel { Id = Guid.NewGuid(), Current = true, HasOscar = true, Rating = 2, Title = "Film1", Year = 2015 }; List <MovieDomainModel> movieDomainModels = new List <MovieDomainModel>(); movieDomainModels.Add(movieDomainModel); IEnumerable <MovieDomainModel> movieDomainModelsIEn = movieDomainModels; Task <IEnumerable <MovieDomainModel> > responseTask = Task.FromResult(movieDomainModelsIEn); _movieService = new Mock <IMovieService>(); _loggerService = new Mock <ILogger <MoviesController> >(); _movieService.Setup(x => x.GetMoviesByAuditoriumId(It.IsAny <int>())).Returns(responseTask); MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object); //Act var result = moviesController.GetMoviesByAuditoriumId(auditoriumId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var movieDomainModelResultList = (List <MovieDomainModel>)resultList; //Assert Assert.IsNotNull(resultList); Assert.AreEqual(expectedCount, movieDomainModelResultList.Count); Assert.AreEqual(movieDomainModel.Id, movieDomainModelResultList[0].Id); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void MovieService_AddMovie_ReturnMovieDomainModel() { //Arrange MovieDomainModel movieDomainModel = _movieDomainModel; MovieCreateTagDomainModel movieCreate = new MovieCreateTagDomainModel(); Movie movie = _movie; //MovieDomainModel repositoryResponse = _mov; _mockMoviesRepository = new Mock <IMoviesRepository>(); _mockMoviesRepository.Setup(x => x.Insert(It.IsAny <Movie>())).Returns(movie); MovieService movieController = new MovieService(_mockMoviesRepository.Object, _mockProjectionsRepository.Object, _mockMovieTagsRepository.Object, _mockTicketRepository.Object, _mockTagRepository.Object); //Act var resultAction = movieController.AddMovie(movieDomainModel, movieCreate).ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.IsInstanceOfType(resultAction, typeof(MovieDomainModel)); Assert.AreEqual(resultAction.Rating, movieDomainModel.Rating); Assert.AreEqual(resultAction.Id, movieDomainModel.Id); }
public async Task <MovieDomainModel> DeleteMovie(Guid id) { var data = _moviesRepository.Delete(id); if (data == null) { return(null); } _moviesRepository.Save(); MovieDomainModel domainModel = new MovieDomainModel { Id = data.Id, Title = data.Title, Current = data.Current, Year = data.Year, Rating = data.Rating ?? 0 }; return(domainModel); }
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); }
public void Delete_Not_Successful_Throw_DbUpdate_Exception() { //Arrange Guid g = new Guid(); 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.DeleteMovie(It.IsAny <Guid>())).Throws(dbUpdateException); MoviesController moviesController = new MoviesController(_loggerService.Object, _movieService.Object); //Act var result = moviesController.Delete(g).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)); }
public async Task <MovieDomainModel> DeleteMovie(Guid movieId) { var deletedMovieTags = await _movieTagService.DeleteByMovieId(movieId); if (deletedMovieTags == null) { return(null); } var deletedProjectionsData = await _projectionService.DeleteByMovieId(movieId); if (deletedProjectionsData == null) { return(null); } var deletedMovieData = _moviesRepository.Delete(movieId); if (deletedMovieData == null) { return(null); } _moviesRepository.Save(); MovieDomainModel domainModel = new MovieDomainModel { Id = deletedMovieData.Id, Title = deletedMovieData.Title, Current = deletedMovieData.Current, Year = deletedMovieData.Year, Rating = deletedMovieData.Rating ?? 0 }; return(domainModel); }
public async Task <IEnumerable <MovieDomainModel> > GetTopTenMovies() { var data = await _moviesRepository.GetTopTenMovies(); if (data == null) { return(null); } var oskarId = _movieTagsRepository.GetOskarId().Id; double rating = 0; List <Movie> listaMovie = new List <Movie>(); foreach (var item in data) { listaMovie.Add(item); } List <MovieDomainModel> result = new List <MovieDomainModel>(); List <Movie> resultOrder = new List <Movie>(); MovieDomainModel model; for (int i = 0; i < listaMovie.Count(); i++) { if (listaMovie[i].Rating == rating) { var hasOskarListAnswer = listaMovie[i].MovieTags.Select(x => x.TagId.Equals(oskarId)); if (hasOskarListAnswer.Contains(true)) { var firstElement = listaMovie[i]; var secondElement = listaMovie[i - 1]; resultOrder.Remove(secondElement); resultOrder.Add(firstElement); resultOrder.Add(secondElement); } resultOrder.Add(listaMovie[i]); } else { resultOrder.Add(listaMovie[i]); rating = listaMovie[i].Rating ?? 0; } } var finalOrder = resultOrder.Take(10); foreach (var item in finalOrder) { model = new MovieDomainModel { Current = item.Current, Id = item.Id, Rating = item.Rating ?? 0, Title = item.Title, Year = item.Year }; result.Add(model); } return(result); }