public async Task ReturnCReviewDTO_IfParamsAreValid()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            mockICocktailReviewMapper
            .Setup(r => r.MapToCocktailReviewDTO(It.IsAny <CocktailsUsersReviews>()))
            .Returns <CocktailsUsersReviews>(r => new CocktailReviewDTO
            {
                CocktailId = r.CocktailId, AuthorId = r.UserId, Comment = r.Comment
            });

            var options = Utils.GetOptions(nameof(ReturnCReviewDTO_IfParamsAreValid));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.GetCocktailReviewAsync(1, 2);

                Assert.AreEqual(1, result.CocktailId);
                Assert.AreEqual(2, result.AuthorId);
            }
        }
        public async Task ReturnTrue_IfCocktailReviewDeletedSuccesfully()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnTrue_IfCocktailReviewDeletedSuccesfully));

            var review = new CocktailsUsersReviews
            {
                CocktailId = 1,
                UserId     = 2,
                Comment    = "Top!",
                Rating     = 5
            };

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.DeleteCocktailReviewAsync(1, 2);

                var deletedReview = assertContext.CocktailsUsersReviews
                                    .FirstOrDefault(r => r.CocktailId == 1 && r.UserId == 2);


                Assert.IsTrue(result);
                Assert.AreEqual(true, deletedReview.IsDeleted);
            }
        }
Beispiel #3
0
        public async Task Throw_Exception_When_CocktailReview_Cocktail_IsNull()
        {
            var options = Utils.GetOptions(nameof(Throw_Exception_When_CocktailReview_Cocktail_IsNull));

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

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

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailReviewService(arrangeContext);

                arrangeContext.Users.Add(user);
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailReviewService(assertContext);
                await Assert.ThrowsExceptionAsync <ArgumentNullException>
                    (async() => await sut.CreateCocktailReview(null, user.UserName, 5, "Very good!"));
            }
        }
Beispiel #4
0
        public async Task Throw_Exception_When_CocktailReview_User_IsNull()
        {
            var options = Utils.GetOptions(nameof(Throw_Exception_When_CocktailReview_User_IsNull));

            var cocktail = new Cocktail()
            {
                Id          = Guid.Parse("74d3f564-5811-4eda-97d6-e39d6bbd35a9"),
                Name        = "Cosmopolitan",
                Description = "The legendary Cosmopolitan is a simple cocktail with a big history."
            };

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailReviewService(arrangeContext);

                arrangeContext.Cocktails.Add(cocktail);
                await arrangeContext.SaveChangesAsync();
            }
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailReviewService(assertContext);
                await Assert.ThrowsExceptionAsync <ArgumentNullException>
                    (async() => await sut.CreateCocktailReview(cocktail.Name, null, 5, "Very good!"));
            }
        }
        public async Task Return_Correct_If_Reviewd()
        {
            var options = Utils.GetOptions(nameof(Return_Correct_If_Reviewd));

            var cocktail = new Cocktail()
            {
                Id          = Guid.Parse("74d3f564-5811-4eda-97d6-e39d6bbd35a9"),
                Name        = "Cosmopolitan",
                Description = "The legendary Cosmopolitan is a simple cocktail with a big history."
            };

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

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


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

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Cocktails.Add(cocktail);
                arrangeContext.Users.Add(user);
                arrangeContext.CocktailReviews.Add(cReview);
                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new CMContext(options))
            {
                var sut    = new CocktailReviewService(assertContext);
                var result = await sut.HasAlreadyReviewedAsync(cocktail.Id, user.Id);

                Assert.AreEqual(true, result);
            }
        }
Beispiel #6
0
        public async Task Create_Cocktail_Review()
        {
            var options = Utils.GetOptions(nameof(Create_Cocktail_Review));

            var cocktail = new Cocktail()
            {
                Id          = Guid.Parse("74d3f564-5811-4eda-97d6-e39d6bbd35a9"),
                Name        = "Cosmopolitan",
                Description = "The legendary Cosmopolitan is a simple cocktail with a big history."
            };

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

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

            using (var arrangeContext = new CMContext(options))
            {
                var sut = new CocktailReviewService(arrangeContext);

                arrangeContext.Cocktails.Add(cocktail);
                arrangeContext.Users.Add(user);
                await arrangeContext.SaveChangesAsync();

                var cocktailReviewDTO = await sut.CreateCocktailReview(cocktail.Name, user.UserName, 5, "Very good!");
            }

            using (var assertContext = new CMContext(options))
            {
                Assert.AreEqual(cocktail.Id, assertContext.CocktailReviews.First().CocktailId);
                Assert.AreEqual(user.Id, assertContext.CocktailReviews.First().UserId);
                Assert.AreEqual("Very good!", assertContext.CocktailReviews.First().Comment);
                Assert.AreEqual(5, assertContext.CocktailReviews.First().Rating);
            }
        }
        public async Task ReturnNull_IfNoCocktailReviewDTO()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnNull_IfNoCocktailReviewDTO));

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.CreateCocktailReviewAsync(null);

                Assert.IsNull(result);
            }
        }
        public async Task ReturnEmpty_IfNoCocktailReviews()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnEmpty_IfNoCocktailReviews));

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.GetAllCocktailReviewsAsync(1);

                Assert.AreEqual(0, result.Count);
            }
        }
Beispiel #9
0
        public async Task ReturnNull_IfNoUpdatedCReviewDTO()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            mockICocktailReviewMapper
            .Setup(r => r.MapToCocktailReview(It.IsAny <CocktailReviewDTO>()))
            .Returns <CocktailReviewDTO>(r => new CocktailsUsersReviews
            {
                CocktailId = r.CocktailId, UserId = r.AuthorId, Comment = r.Comment
            });

            mockICocktailReviewMapper
            .Setup(r => r.MapToCocktailReviewDTO(It.IsAny <CocktailsUsersReviews>()))
            .Returns <CocktailsUsersReviews>(r => new CocktailReviewDTO
            {
                CocktailId = r.CocktailId, AuthorId = r.UserId, Comment = r.Comment
            });

            var options = Utils.GetOptions(nameof(ReturnNull_IfNoUpdatedCReviewDTO));

            var review = new CocktailsUsersReviews
            {
                CocktailId = 1,
                UserId     = 1,
                Comment    = "Top!",
                Rating     = 5
            };

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.UpdateCocktailReviewAsync(1, 1, null);

                Assert.IsNull(result);
            }
        }
        public async Task Return_IfCocktailReviewDTOParamsAreValid()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            var options = Utils.GetOptions(nameof(Return_IfCocktailReviewDTOParamsAreValid));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.GetAllCocktailReviewsAsync(1);

                Assert.AreEqual(2, result.Count);
            }
        }
        public async Task ReturnNull_IfCocktailReviewMissingOrDeleted()
        {
            //Arrange
            var mockIDateTimeProvider     = new Mock <IDateTimeProvider>();
            var mockICocktailReviewMapper = new Mock <ICocktailReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnNull_IfCocktailReviewMissingOrDeleted));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new CocktailReviewService(mockIDateTimeProvider.Object, assertContext, mockICocktailReviewMapper.Object);

                var result = await sut.DeleteCocktailReviewAsync(3, 2);

                Assert.IsFalse(result);
            }
        }
Beispiel #12
0
        public async Task Get_Correct_Number_CR()
        {
            var options = Utils.GetOptions(nameof(Get_Correct_Number_CR));

            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
            };

            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);
                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new CMContext(options))
            {
                var sut    = new CocktailReviewService(assertContext);
                var result = await sut.GetAllSpecificCocktailReviews(cocktail.Id);

                Assert.AreEqual(cReview.Id, result.ElementAt(0).Id);
                Assert.AreEqual(cReview2.Id, result.ElementAt(1).Id);
                Assert.AreEqual(cReview.UserId, result.ElementAt(0).UserId);
                Assert.AreEqual(cReview2.UserId, result.ElementAt(1).UserId);
                Assert.AreEqual(cReview.Comment, result.ElementAt(0).Comment);
                Assert.AreEqual(cReview2.Comment, result.ElementAt(1).Comment);
                Assert.AreEqual(2, result.Count());
            }
        }