public async Task RemoveVenueFromDb() { var options = new DbContextOptionsBuilder <BoboTuDbContext>() .UseInMemoryDatabase($"BoboTuDatabaseForTesting{Guid.NewGuid()}") .Options; var venueData = System.IO.File.ReadAllText(@"VenueDataSeed/venueDataSeed.json"); var venues = JsonConvert.DeserializeObject <List <Venue> >(venueData); int venueCount = 0; using (var context = new BoboTuDbContext(options)) { context.Venues.AddRange(venues); context.SaveChanges(); venueCount = context.Venues.Count(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); var venue = (await venueRepo.GetAllVenuesAsync(new List <int>().ToArray(), new List <int>().ToArray())).First(); venueRepo.DeleteVenue(venue); await venueRepo.SaveChanges(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); Assert.Equal(venueCount - 1, context.Venues.Count()); } }
public async Task RemoveVenue_Null_ThrowsArgumentException() { var options = new DbContextOptionsBuilder <BoboTuDbContext>() .UseInMemoryDatabase($"BoboTuDatabaseForTesting{Guid.NewGuid()}") .Options; var venueData = System.IO.File.ReadAllText(@"VenueDataSeed/venueDataSeed.json"); var venues = JsonConvert.DeserializeObject <List <Venue> >(venueData); int venueCount = 0; using (var context = new BoboTuDbContext(options)) { context.Venues.AddRange(venues); context.SaveChanges(); venueCount = context.Venues.Count(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); await Assert.ThrowsAsync <ArgumentException>( // Act async() => { venueRepo.DeleteVenue(null); await venueRepo.SaveChanges(); } ); } }
public async Task AddNewVenueToDb() { var options = new DbContextOptionsBuilder <BoboTuDbContext>() .UseInMemoryDatabase($"BoboTuDatabaseForTesting{Guid.NewGuid()}") .Options; var venueData = System.IO.File.ReadAllText(@"VenueDataSeed/venueDataSeed.json"); var venues = JsonConvert.DeserializeObject <List <Venue> >(venueData); int venueCount = 0; using (var context = new BoboTuDbContext(options)) { context.Venues.AddRange(venues); context.SaveChanges(); venueCount = context.Venues.Count(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); var venue = new Venue() { AverageRating = 7.4, City = "Wrocław", Description = "Ładna restauracja" }; venueRepo.AddVenue(venue); await venueRepo.SaveChanges(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); Assert.Equal(venueCount + 1, context.Venues.Count()); } }