예제 #1
0
        public void ThrowWhenIdIsNotFound()
        {
            var options  = TestUtilities.GetOptions(nameof(ThrowWhenIdIsNotFound));
            int resultId = -1;
            var review1  = new CocktailReview
            {
                Id         = resultId,
                CocktailId = 1,
            };
            var review2 = new CocktailReview
            {
                Id         = -2,
                CocktailId = 1,
            };
            var review3 = new CocktailReview
            {
                Id         = -3,
                CocktailId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new CocktailReviewServices(assertContext);
                Assert.ThrowsExceptionAsync <ArgumentNullException>(
                    () => sut.DeleteAsync(int.MaxValue));
            }
        }
예제 #2
0
        public void CorrectlyDeleteReview()
        {
            var options  = TestUtilities.GetOptions(nameof(CorrectlyDeleteReview));
            int resultId = -1;
            var review1  = new CocktailReview
            {
                Id         = resultId,
                CocktailId = 1,
            };
            var review2 = new CocktailReview
            {
                Id         = -2,
                CocktailId = 1,
            };
            var review3 = new CocktailReview
            {
                Id         = -3,
                CocktailId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new CocktailReviewServices(assertContext);
                sut.DeleteAsync(resultId).GetAwaiter();
                Assert.IsFalse(assertContext.CocktailReviews.Contains(review1));
            }
        }
        public void ReturnNullWhenCocktailIdIsNotFound()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnNullWhenCocktailIdIsNotFound));
            var review1 = new CocktailReview
            {
                Id         = -1,
                CocktailId = 1,
            };
            var review2 = new CocktailReview
            {
                Id         = -2,
                CocktailId = 1,
            };
            var review3 = new CocktailReview
            {
                Id         = -3,
                CocktailId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailReviewServices(assertContext);
                var result = sut.GetCocktailReviewsCollectionAsync(int.MaxValue).GetAwaiter().GetResult();
                Assert.AreEqual(0, result.Count);
            }
        }
        public void ReturnCorrectReviews()
        {
            var options  = TestUtilities.GetOptions(nameof(ReturnCorrectReviews));
            int resultId = 1;
            var review1  = new CocktailReview
            {
                Id         = -1,
                CocktailId = 1,
            };
            var review2 = new CocktailReview
            {
                Id         = -2,
                CocktailId = 1,
            };
            var review3 = new CocktailReview
            {
                Id         = -3,
                CocktailId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailReviewServices(assertContext);
                var result = sut.GetCocktailReviewsCollectionAsync(resultId).GetAwaiter().GetResult();
                Assert.IsNotNull(result);
                Assert.AreEqual(2, result.Count);
                Assert.IsTrue(result.Select(br => br.CocktailId).Contains(1));
            }
        }
        public void ReturnNullWhenIdNotFound()
        {
            var options  = TestUtilities.GetOptions(nameof(ReturnNullWhenIdNotFound));
            int resultId = -1;
            var review   = new CocktailReview
            {
                Id = resultId,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailReviewServices(assertContext);
                var result = sut.GetCocktailReviewAsync(int.MaxValue).GetAwaiter().GetResult();
                Assert.IsNull(result);
            }
        }
        public void ReturnCorrectReview()
        {
            var options  = TestUtilities.GetOptions(nameof(ReturnCorrectReview));
            int resultId = -1;
            var review   = new CocktailReview
            {
                Id = resultId,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailReviewServices(assertContext);
                var result = sut.GetCocktailReviewAsync(resultId).GetAwaiter().GetResult();
                Assert.IsNotNull(result);
                Assert.AreEqual(resultId, result.Id);
            }
        }