예제 #1
0
        public void CreateCurrectReview_When_ParamsValid()
        {
            var options    = Utils.GetOptions(nameof(CreateCurrectReview_When_ParamsValid));
            var reviewDTO  = TestsModelsSeeder.SeedReviewDTO();
            var user       = TestsModelsSeeder.SeedUser();
            var targetbeer = TestsModelsSeeder.SeedBeer();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(targetbeer);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new ReviewServices(assertContext);
                var act = sut.CreateReview(reviewDTO);
                assertContext.SaveChanges();
                var result = assertContext.Reviews.ToList()[0];
                Assert.AreEqual(reviewDTO.Name, result.Name);
                Assert.AreEqual(reviewDTO.Rating, result.Rating);
                Assert.AreEqual(reviewDTO.Text, result.Text);
                Assert.AreEqual(reviewDTO.Author, reviewDTO.Author);
            }
        }
예제 #2
0
        public void ThrowArgumentException_When_TargetBeerNotValid()
        {
            var options   = Utils.GetOptions(nameof(ThrowArgumentException_When_TargetBeerNotValid));
            var user      = TestsModelsSeeder.SeedUser();
            var reviewDTO = TestsModelsSeeder.SeedReviewDTO();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new ReviewServices(assertContext);
                Assert.ThrowsException <ArgumentNullException>(() => sut.CreateReview(reviewDTO));
            }
        }