public async Task AddGenreAsyncWithCorrectDataShouldReturnCorrectResult() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var genresService = new GenresService(groupGenresRepository, genresRepository); var actual = await genresService.AddGenreAsync(5, 1); var expected = 5; Assert.Equal(expected, actual); }
public async Task AddGenreAsyncWithDublicateNameShouldThrowArgumentException() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var genresService = new GenresService(groupGenresRepository, genresRepository); await groupGenresRepository.AddAsync(new GroupGenre { GroupId = 2, GenreId = 1 }); await groupGenresRepository.SaveChangesAsync(); await Assert.ThrowsAsync <ArgumentException>(async() => { await genresService.AddGenreAsync(2, 1); }); }