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 ReturnCorrectList_WhenDataIsPresent() { var options = Utils.GetOptions(nameof(ReturnCorrectList_WhenDataIsPresent)); var beerType1 = TestsModelsSeeder.SeedBeerType(); var beerType2 = TestsModelsSeeder.SeedBeerType2(); var beerType3 = TestsModelsSeeder.SeedBeerType3(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType1); arrangeContext.BeerTypes.Add(beerType2); arrangeContext.BeerTypes.Add(beerType3); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); var result = sut.GetAllBeerTypes().ToList(); Assert.AreEqual(3, result.Count); Assert.AreEqual(beerType1.Name, result[0].Name); Assert.AreEqual(beerType2.Name, result[1].Name); Assert.AreEqual(beerType3.Name, result[2].Name); } }
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 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 ReturnCorrectBeer_When_ParamsValid() { var options = Utils.GetOptions(nameof(ReturnCorrectBeer_When_ParamsValid)); var beertype = TestsModelsSeeder.SeedBeerType(); var brewery = TestsModelsSeeder.SeedBrewery(); var beerDTO = TestsModelsSeeder.SeedBeerDTO(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beertype); arrangeContext.Breweries.Add(brewery); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerServices(assertContext); var act = sut.CreateBeer(beerDTO); var result = assertContext.Beers.FirstOrDefault(beer => beer.Name == beerDTO.Name); Assert.AreEqual(beerDTO.Id, result.Id); Assert.AreEqual(beerDTO.Name, result.Name); Assert.AreEqual(beerDTO.AlcoholByVolume, result.AlcoholByVolume); Assert.AreEqual(beerDTO.Brewery, result.Brewery.Name); } }
public void Throw_When_BeerTypeAlreadyExists() { var options = Utils.GetOptions(nameof(Throw_When_BeerTypeAlreadyExists)); var beerTypeDTO = TestsModelsSeeder.SeedBeerTypeDTO(); var beerType = TestsModelsSeeder.SeedBeerType(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); Assert.ThrowsException <ArgumentException>(() => sut.CreateBeerType(beerTypeDTO)); } }
public void ReturnFalse_WhenIdIsIncorrect() { var options = Utils.GetOptions(nameof(ReturnFalse_WhenIdIsIncorrect)); var beerType = TestsModelsSeeder.SeedBeerType(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); var result = sut.DeleteBeerType(beerType.Id + 1); Assert.IsFalse(result); } }
public void Throw_WhenBeerTypeIdIsInvalid() { var options = Utils.GetOptions(nameof(Throw_WhenBeerTypeIdIsInvalid)); var beerType1 = TestsModelsSeeder.SeedBeerType(); var beerType2 = TestsModelsSeeder.SeedBeerType2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType1); arrangeContext.BeerTypes.Add(beerType2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); Assert.ThrowsException <ArgumentNullException>(() => sut.UpdateBeerType(5, "newBeerType")); } }
public void DeleteBeerType_WhenIdIsCorrect() { var options = Utils.GetOptions(nameof(DeleteBeerType_WhenIdIsCorrect)); var beerType = TestsModelsSeeder.SeedBeerType(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); var act = sut.DeleteBeerType(beerType.Id); var result = assertContext.BeerTypes.FirstOrDefault(bt => bt.Name == beerType.Name).IsDeleted; Assert.IsTrue(result); } }
public void CorrectlyUpdateBeerType_WhenDataIsValid() { var options = Utils.GetOptions(nameof(CorrectlyUpdateBeerType_WhenDataIsValid)); var beerType1 = TestsModelsSeeder.SeedBeerType(); var beerType2 = TestsModelsSeeder.SeedBeerType2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType1); arrangeContext.BeerTypes.Add(beerType2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); var act = sut.UpdateBeerType(2, "newBeerType"); var result = sut.GetBeerType(2); Assert.AreEqual("newBeerType", result.Name); } }
public void ReturnCorrectBeerType_WhenIdIsValid() { var options = Utils.GetOptions(nameof(ReturnCorrectBeerType_WhenIdIsValid)); var beerType1 = TestsModelsSeeder.SeedBeerType(); var beerType2 = TestsModelsSeeder.SeedBeerType2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.BeerTypes.Add(beerType1); arrangeContext.BeerTypes.Add(beerType2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BeerTypeServices(assertContext); var result = sut.GetBeerType(2); Assert.AreEqual(beerType2.Id, result.Id); Assert.AreEqual(beerType2.Name, result.Name); } }