public void Throw_WhenIdIsInvalid()
        {
            var options = Utils.GetOptions(nameof(Throw_WhenIdIsInvalid));

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new BreweryServices(assertContext);
                Assert.ThrowsException <ArgumentNullException>(() => sut.GetBrewery(1));
            }
        }
        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);
            }
        }
Пример #3
0
        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);
            }
        }