public async Task MovieTest() { string inputMovieId = "ab10101010"; string outputMovieId; // Seed the test database using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RepoLogic repoLogic = new RepoLogic(context); // Test CreateMovie() IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); await movieController.CreateMovie(inputMovieId); } using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { var gmMovie = context.Movies.FirstOrDefault <Repository.Models.Movie>(m => m.MovieId == inputMovieId); outputMovieId = gmMovie.MovieId; } Assert.Equal(inputMovieId, outputMovieId); }
public async Task PostExistingMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); Movie outputMovie; // Seed the test database using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test CreateMovie() await movieController.CreateMovie(inputMovie); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { outputMovie = context.Movies.FirstOrDefault(m => m.ImdbId == inputMovie.ImdbId); } Assert.Equal(inputMovie.Title, outputMovie.Title); }
public async Task CreateMovieTest_ResponseStatus_200(CreateMovieRequest request, CreateMovieResponse expectedResult) { // Arrange var expectedMovieEntity = Mapper.Map <MovieEntity>(expectedResult); var mockMovieService = new Mock <IMovieService>(); mockMovieService.Setup(x => x.CreateAsync(It.IsAny <MovieEntity>())) .Returns(Task.FromResult(expectedMovieEntity)); // Act var movieController = new MovieController(Mapper, mockMovieService.Object); MockModelState(request, movieController); var response = await movieController.CreateMovie(request); // Assert var okObjectResponse = Assert.IsType <OkObjectResult>(response.Result); var movieResponse = Assert.IsType <CreateMovieResponse>(okObjectResponse.Value); Assert.Equal(expectedResult.Id, movieResponse.Id); Assert.Equal(expectedResult.Title, movieResponse.Title); Assert.Equal(expectedResult.PlotSummary, movieResponse.PlotSummary); Assert.Equal(expectedResult.Language, movieResponse.Language); Assert.Equal(expectedResult.ReleaseDate, movieResponse.ReleaseDate); Assert.Equal(expectedResult.Genre, movieResponse.Genre); Assert.Equal(expectedResult.Director, movieResponse.Director); Assert.True(expectedResult.CastAndCrew.SequenceEqual(movieResponse.CastAndCrew)); }
public async Task CreateMovieTest_ResponseStatus_400(CreateMovieRequest request) { // Arrange var mockMovieService = new Mock <IMovieService>(); mockMovieService.Setup(x => x.CreateAsync(It.IsAny <MovieEntity>())).Throws <EntityAlreadyExistException>(); // Act var movieController = new MovieController(Mapper, mockMovieService.Object); MockModelState(request, movieController); var response = await movieController.CreateMovie(request); // Assert var badRequestObject = Assert.IsType <BadRequestObjectResult>(response.Result); Assert.IsType <SerializableError>(badRequestObject.Value); }
public async Task CreateMovieTest_ResponseStatus_409(CreateMovieRequest request) { // Arrange var mockMovieService = new Mock <IMovieService>(); mockMovieService.Setup(x => x.CreateAsync(It.IsAny <MovieEntity>())).Throws <EntityAlreadyExistException>(); // Act var movieController = new MovieController(Mapper, mockMovieService.Object); MockModelState(request, movieController); var response = await movieController.CreateMovie(request); // Assert var conflictObject = Assert.IsType <ConflictObjectResult>(response.Result); Assert.IsType <string>(conflictObject.Value); Assert.Equal("Movie with same meta data already exists", conflictObject.Value); }