public async Task ReturnNullWhenUserIsNotFound() { // Arrange contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "ReturnNullWhenUserIsNotFound") .Options; var userId = "userId"; var projectionId = 5; // Assert && Act watchedMovie = new WatchedMovie() { UserId = userId, ProjectionId = projectionId }; using (var actContext = new AlphaCinemaContext(contextOptions)) { await actContext.WatchedMovies.AddAsync(watchedMovie); await actContext.SaveChangesAsync(); } var serviceProviderMock = new Mock <IServiceProvider>(); // Act && Assert using (var assertContext = new AlphaCinemaContext(contextOptions)) { var watchedMoviesService = new WatchedMoviesService(assertContext); var result = await watchedMoviesService.GetWatchedMovie("no user id", projectionId); Assert.IsNull(result); } }
public async Task ReturnWatchedMovieWhenParamsAreInDatabase() { // Arrange contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "ReturnWatchedMovieWhenParamsAreInDatabase") .Options; var userId = "userId"; var projectionId = 5; watchedMovie = new WatchedMovie() { UserId = userId, ProjectionId = projectionId }; using (var actContext = new AlphaCinemaContext(contextOptions)) { await actContext.WatchedMovies.AddAsync(watchedMovie); await actContext.SaveChangesAsync(); } // Act && Assert using (var assertContext = new AlphaCinemaContext(contextOptions)) { var watchedMoviesService = new WatchedMoviesService(assertContext); var result = await watchedMoviesService.GetWatchedMovie(userId, projectionId); Assert.IsNotNull(result); Assert.AreEqual(result.ProjectionId, projectionId); Assert.AreEqual(result.UserId, userId); } }
public async Task ThrowEntityAlreadyExistsExceptionWhenParamsAreValid() { // Arrange contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "ThrowEntityAlreadyExistsExceptionWhenParamsAreValid") .Options; var userId = "userId"; var projectionId = 5; watchedMovie = new WatchedMovie() { UserId = userId, ProjectionId = projectionId }; using (var actContext = new AlphaCinemaContext(contextOptions)) { await actContext.WatchedMovies.AddAsync(watchedMovie); await actContext.SaveChangesAsync(); } // Act && Assert using (var assertContext = new AlphaCinemaContext(contextOptions)) { var watchedMoviesService = new WatchedMoviesService(assertContext); await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(() => watchedMoviesService.AddNewWatchedMovie(userId, projectionId)); } }
public async Task SuccessfullyCreateNewWatchedMovieWhenParamsAreValid() { // Arrange contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "SuccessfullyCreateNewWatchedMovieWhenParamsAreValid") .Options; var userId = "djoni"; var projectionId = 6; // Act && Assert using (var assertContext = new AlphaCinemaContext(contextOptions)) { var watchedMoviesService = new WatchedMoviesService(assertContext); await watchedMoviesService.AddNewWatchedMovie(userId, projectionId); var watchedMovie = await watchedMoviesService.GetWatchedMovie(userId, projectionId); Assert.AreEqual(userId, watchedMovie.UserId); Assert.AreEqual(projectionId, watchedMovie.ProjectionId); } }
public async Task ReturnWatchedMoviesWhenUserIsValid() { // Arrange contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>() .UseInMemoryDatabase(databaseName: "ReturnWatchedMoviesWhenUserIsValid") .Options; var userId = "Mitio"; var watchedMovies = new List <WatchedMovie>() { new WatchedMovie() { UserId = userId, Projection = new Projection() { Movie = new Movie() { Name = "movie Name" }, City = new City() { Name = "city name" }, OpenHour = new OpenHour { Hours = 12 } } }, new WatchedMovie() { UserId = userId, Projection = new Projection() { Movie = new Movie() { Name = "movie Name" }, City = new City() { Name = "city name" }, OpenHour = new OpenHour { Hours = 12 } } }, new WatchedMovie() { UserId = userId, Projection = new Projection() { Movie = new Movie() { Name = "movie Name" }, City = new City() { Name = "city name" }, OpenHour = new OpenHour { Hours = 12 } } }, }; using (var actContext = new AlphaCinemaContext(contextOptions)) { foreach (var watchedMovie in watchedMovies) { await actContext.WatchedMovies.AddAsync(watchedMovie); } await actContext.SaveChangesAsync(); } using (var assertContext = new AlphaCinemaContext(contextOptions)) { var watchedMoviesService = new WatchedMoviesService(assertContext); var result = await watchedMoviesService.GetWatchedMoviesByUserId(userId); Assert.AreEqual(watchedMovies.Count, result.Count); } }