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 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 ReturnCorrectReviews_When_ParamsValid()
        {
            var options = Utils.GetOptions(nameof(ReturnCorrectReviews_When_ParamsValid));

            var review  = TestsModelsSeeder.SeedReview();
            var review2 = TestsModelsSeeder.SeedReview2();
            var review3 = TestsModelsSeeder.SeedReview3();
            var beer    = TestsModelsSeeder.SeedBeer();
            var beer2   = TestsModelsSeeder.SeedBeer2();
            var beer3   = TestsModelsSeeder.SeedBeer3();
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Reviews.Add(review);
                arrangeContext.Reviews.Add(review2);
                arrangeContext.Reviews.Add(review3);
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.Beers.Add(beer2);
                arrangeContext.Beers.Add(beer3);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new ReviewServices(assertContext);
                var result = sut.GetAllReviews().ToList();
                Assert.AreEqual(3, result.Count());
                Assert.AreEqual(review.Name, result[0].Name);
                Assert.AreEqual(review2.Name, result[1].Name);
                Assert.AreEqual(review3.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);
            }
        }
示例#5
0
        public void ReturnCorrectWishlist_WhenParamsAreValid()
        {
            var options  = Utils.GetOptions(nameof(ReturnCorrectWishlist_WhenParamsAreValid));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var user1    = TestsModelsSeeder.SeedUser();
            var beer1    = TestsModelsSeeder.SeedBeer();
            var beer2    = TestsModelsSeeder.SeedBeer2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user1);
                arrangeContext.Beers.Add(beer1);
                arrangeContext.Beers.Add(beer2);
                arrangeContext.SaveChanges();
                arrangeContext.Users.FirstOrDefault().Wishlist = new HashSet <WishlistBeer>
                {
                    new WishlistBeer
                    {
                        UserId = 1,
                        BeerId = 1,
                    },
                    new WishlistBeer
                    {
                        UserId = 1,
                        BeerId = 2,
                    }
                };
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.GetWishlist(1).ToList();
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(2, result[0].Id);
                Assert.AreEqual(1, result[1].Id);
            }
        }