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 Throw_WhenBreweryIdIsInvalid() { var options = Utils.GetOptions(nameof(Throw_WhenBreweryIdIsInvalid)); var brewery1 = TestsModelsSeeder.SeedBrewery(); var brewery2 = TestsModelsSeeder.SeedBrewery2(); using (var arrangeContext = new BeerOverflowContext(options)) { arrangeContext.Breweries.Add(brewery1); arrangeContext.Breweries.Add(brewery2); arrangeContext.SaveChanges(); } using (var assertContext = new BeerOverflowContext(options)) { var sut = new BreweryServices(assertContext); Assert.ThrowsException <ArgumentNullException>(() => sut.UpdateBrewery(5, "NewBrewery", "Bulgaria")); } }
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); } }