public void ThrowArgumentException_When_UpdatedBeerExists() { var options = Utils.GetOptions(nameof(ThrowArgumentException_When_UpdatedBeerExists)); var beerType = TestsModelsSeeder.SeedBeerType(); var brewery = TestsModelsSeeder.SeedBrewery(); var country = TestsModelsSeeder.SeedCountry(); var beer = TestsModelsSeeder.SeedBeer(); var beer2 = TestsModelsSeeder.SeedBeer2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery); arrangeContext.BeerTypes.Add(beerType); arrangeContext.Beers.Add(beer); arrangeContext.Beers.Add(beer2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerServices(assertContext); Assert.ThrowsException <ArgumentException>(() => sut.UpdateBeer(1, beer2.Name, beer2.Type.Name, beer2.Brewery.Name, 6)); } }
public void ReturnCorrectBeers_When_ParamsValid() { var options = Utils.GetOptions(nameof(ReturnCorrectBeers_When_ParamsValid)); var country = TestsModelsSeeder.SeedCountry(); var beerType = TestsModelsSeeder.SeedBeerType(); var brewery = TestsModelsSeeder.SeedBrewery(); var beer = TestsModelsSeeder.SeedBeer(); var beer2 = TestsModelsSeeder.SeedBeer2(); var beer3 = TestsModelsSeeder.SeedBeer3(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.BeerTypes.Add(beerType); arrangeContext.Breweries.Add(brewery); arrangeContext.Add(beer); arrangeContext.Add(beer2); arrangeContext.Add(beer3); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerServices(assertContext); var result = sut.GetAllBeers().ToList(); Assert.AreEqual(3, result.Count); Assert.AreEqual(beer.Name, result[0].Name); Assert.AreEqual(beer2.Name, result[1].Name); Assert.AreEqual(beer3.Name, result[2].Name); } }
public void UpdateCorrectBeer_When_ParamsAreValid() { var options = Utils.GetOptions(nameof(UpdateCorrectBeer_When_ParamsAreValid)); var beer = TestsModelsSeeder.SeedBeer(); var beerType = TestsModelsSeeder.SeedBeerType(); var brewery = TestsModelsSeeder.SeedBrewery(); var country = TestsModelsSeeder.SeedCountry(); var beer2 = TestsModelsSeeder.SeedBeer2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery); arrangeContext.BeerTypes.Add(beerType); arrangeContext.Beers.Add(beer); arrangeContext.Beers.Add(beer2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerServices(assertContext); var act = sut.UpdateBeer(1, "NewBeerName", beer2.Type.Name, brewery.Name, 6); var result = sut.GetBeer(1); Assert.AreEqual("NewBeerName", result.Name); Assert.AreEqual(beer2.Type.Name, result.BeerType); Assert.AreEqual(brewery.Name, result.Brewery); Assert.AreEqual(6, result.AlcoholByVolume); } }
public void ReturnCorrectList_WhenDataIsPresent() { var options = Utils.GetOptions(nameof(ReturnCorrectList_WhenDataIsPresent)); var country = TestsModelsSeeder.SeedCountry(); var brewery1 = TestsModelsSeeder.SeedBrewery(); var brewery2 = TestsModelsSeeder.SeedBrewery2(); var brewery3 = TestsModelsSeeder.SeedBrewery3(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery1); arrangeContext.Breweries.Add(brewery2); arrangeContext.Breweries.Add(brewery3); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); var result = sut.GetAllBreweries().ToList(); Assert.AreEqual(3, result.Count); Assert.AreEqual(brewery1.Name, result[0].Name); Assert.AreEqual(brewery2.Name, result[1].Name); Assert.AreEqual(brewery3.Name, result[2].Name); } }
public void ReturnCurrectCountries_When_ParamsValid() { var options = Utils.GetOptions(nameof(ReturnCurrectCountries_When_ParamsValid)); var country = TestsModelsSeeder.SeedCountry(); var country2 = TestsModelsSeeder.SeedCountry2(); var country3 = TestsModelsSeeder.SeedCountry3(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Countries.Add(country2); arrangeContext.Countries.Add(country3); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new CountryServices(assertContext); var result = sut.GetAllCountries().ToList(); Assert.AreEqual(3, result.Count()); Assert.AreEqual(country.Name, result[0].Name); Assert.AreEqual(country2.Name, result[1].Name); Assert.AreEqual(country3.Name, result[2].Name); } }
public void ReturnCurrectCountry_When_ParamsValid() { var options = Utils.GetOptions(nameof(ReturnCurrectCountry_When_ParamsValid)); var country = TestsModelsSeeder.SeedCountry(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new CountryServices(assertContext); var result = sut.GetCountry(1); Assert.AreEqual(country.Name, result.Name); Assert.AreEqual(country.Code, result.CountryCode); } }
public void Throw_WhenBreweryAlreadyExists() { var options = Utils.GetOptions(nameof(Throw_WhenBreweryAlreadyExists)); var breweryDTO = TestsModelsSeeder.SeedBreweryDTO(); var brewery = TestsModelsSeeder.SeedBrewery(); var country = TestsModelsSeeder.SeedCountry(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); Assert.ThrowsException <ArgumentException>(() => sut.CreateBrewery(breweryDTO)); } }
public void ReturnCorrectBrewery_WhenParamsAreValid() { var options = Utils.GetOptions(nameof(ReturnCorrectBrewery_WhenParamsAreValid)); var breweryDTO = TestsModelsSeeder.SeedBreweryDTO(); var country = TestsModelsSeeder.SeedCountry(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); var act = sut.CreateBrewery(breweryDTO); var result = assertContext.Breweries.FirstOrDefault(brewery => brewery.Name == breweryDTO.Name); Assert.AreEqual(breweryDTO.Id, result.Id); Assert.AreEqual(breweryDTO.Name, result.Name); Assert.AreEqual(breweryDTO.Country, result.Country.Name); } }
public void ReturnCorrectBrewery_WhenIdIsValid() { var options = Utils.GetOptions(nameof(ReturnCorrectBrewery_WhenIdIsValid)); var country = TestsModelsSeeder.SeedCountry(); var brewery1 = TestsModelsSeeder.SeedBrewery(); var brewery2 = TestsModelsSeeder.SeedBrewery2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery1); arrangeContext.Breweries.Add(brewery2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); var result = sut.GetBrewery(2); Assert.AreEqual(brewery2.Id, result.Id); Assert.AreEqual(brewery2.Name, result.Name); Assert.AreEqual(brewery2.Country.Name, result.Country); } }
public void CorrectlyUpdate_WhenDataIsValid() { var options = Utils.GetOptions(nameof(CorrectlyUpdate_WhenDataIsValid)); var country = TestsModelsSeeder.SeedCountry(); var brewery1 = TestsModelsSeeder.SeedBrewery(); var brewery2 = TestsModelsSeeder.SeedBrewery2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Countries.Add(country); arrangeContext.Breweries.Add(brewery1); arrangeContext.Breweries.Add(brewery2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); var act = sut.UpdateBrewery(2, "NewBrewery", "Bulgaria"); var result = sut.GetBrewery(2); Assert.AreEqual("NewBrewery", result.Name); Assert.AreEqual("Bulgaria", result.Country); } }