public async Task AddVenue_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.AddVenue(null); await venueRepo.SaveChanges(); } ); } }
public virtual IActionResult AddVenue([FromBody] Venue venue) { var result = _venueRepository.AddVenue(venue); if (result == null) { return(BadRequest()); } return(new ObjectResult(result)); }
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()); } }