public void GetOrCreateCityShouldCreateCity() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "Address_CreateCity_Database") .Options; var dbContext = new XeonDbContext(options); var addressService = new AddressesService(null, dbContext); var cityName = "Burgas"; var cityPostcode = "8000"; addressService.GetOrCreateCity(cityName, cityPostcode); var city = dbContext.Cities .FirstOrDefault(x => x.Name == cityName && x.Postcode == cityPostcode); Assert.Equal(cityName, city.Name); Assert.Equal(cityPostcode, city.Postcode); }
public void GetOrCreateCityShouldReturnExistingCity() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "Address_GetCity_Database") .Options; var dbContext = new XeonDbContext(options); var addressService = new AddressesService(null, dbContext); var cityName = "Burgas"; var cityPostcode = "8000"; dbContext.Cities.Add(new City { Name = cityName, Postcode = cityPostcode }); dbContext.SaveChanges(); var city = addressService.GetOrCreateCity(cityName, cityPostcode); Assert.Equal(1, dbContext.Cities.Count()); Assert.Equal(cityName, city.Name); Assert.Equal(cityPostcode, city.Postcode); }