Ejemplo n.º 1
0
        public async Task Throw_If_CR_IsNull()
        {
            var options = Utils.GetOptions(nameof(Throw_If_CR_IsNull));
            var cRId    = Guid.Parse("d7047a3a-7b5e-4eb5-8ed2-c846b7a4d5ce");

            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailReviewLikeService(assertContext);
                await Assert.ThrowsExceptionAsync <ArgumentNullException>
                    (async() => await sut.GetCocktailReviewNumberOfLikes(cRId));
            }
        }
Ejemplo n.º 2
0
        public async Task Get_Correct_Number_Of_Likes()
        {
            var options = Utils.GetOptions(nameof(Get_Correct_Number_Of_Likes));

            var cocktail = new Cocktail()
            {
                Id          = Guid.Parse("8a15e590-0b66-4fae-abfa-d75812b76da6"),
                Name        = "White Russian",
                Description = "The White Russian is decadent and sophisticated."
            };

            var  hasher = new PasswordHasher <User>();
            User user1  = new User
            {
                Id                 = Guid.Parse("a137730d-bb81-4611-8fb8-bb777aae86ac"),
                UserName           = "******",
                NormalizedUserName = "******",
                FirstName          = "Boyan",
                LastName           = "Vuchev",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                LockoutEnabled     = true,
                SecurityStamp      = "DC6E275DD1E24957A7781D42BB68293B",
            };

            user1.PasswordHash = hasher.HashPassword(user1, "123456");

            User user2 = new User
            {
                Id                 = Guid.Parse("ad513447-0536-432b-a848-ea96ade0040d"),
                UserName           = "******",
                NormalizedUserName = "******",
                FirstName          = "Radoslav",
                LastName           = "Simeonov",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                LockoutEnabled     = true,
                SecurityStamp      = "HNWQ7GQFUMWKGOAWSJNC5XV2VFYQRWHC",
            };

            user2.PasswordHash = hasher.HashPassword(user2, "123456");

            var cReview = new CocktailReview()
            {
                Id         = Guid.Parse("d7047a3a-7b5e-4eb5-8ed2-c846b7a4d5ce"),
                CocktailId = cocktail.Id,
                UserId     = user1.Id,
                Rating     = 1,
                Comment    = "Too sour",
                ReviewedOn = DateTime.UtcNow
            };

            var cReview2 = new CocktailReview()
            {
                Id         = Guid.Parse("11c58b41-f0db-480d-bbe5-115bc027f868"),
                CocktailId = cocktail.Id,
                UserId     = user2.Id,
                Rating     = 5,
                Comment    = "Great",
                ReviewedOn = DateTime.UtcNow
            };

            var cReviewLike2 = new CocktailReviewLike()
            {
                CocktailReviewId = cReview2.Id,
                UserId           = user2.Id,
                IsLiked          = true
            };

            var cReviewLike3 = new CocktailReviewLike()
            {
                CocktailReviewId = cReview2.Id,
                UserId           = user1.Id,
                IsLiked          = true
            };

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Cocktails.Add(cocktail);
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.CocktailReviews.Add(cReview);
                arrangeContext.CocktailReviews.Add(cReview2);
                arrangeContext.CocktailReviewLikes.Add(cReviewLike2);
                arrangeContext.CocktailReviewLikes.Add(cReviewLike3);
                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new CMContext(options))
            {
                var sut    = new CocktailReviewLikeService(assertContext);
                var result = await sut.GetCocktailReviewNumberOfLikes(cReview2.Id);

                Assert.AreEqual(2, result);
            }
        }