public void CorrectMapping_ToCocktailReviewDTO()
        {
            //Arrange
            var sut = new CocktailReviewMapper();

            var options  = Utils.GetOptions(nameof(CorrectMapping_ToCocktailReviewDTO));
            var cocktail = new Cocktail {
                Id = 1, Name = "Mojito"
            };
            var user = new User {
                Id = 2, UserName = "******"
            };
            var review = new CocktailsUsersReviews
            {
                CocktailId = 1,
                Cocktail   = cocktail,
                UserId     = 2,
                User       = user,
                Comment    = "Top!",
                Rating     = 4
            };

            //Act
            var result = sut.MapToCocktailReviewDTO(review);

            //Assert
            Assert.AreEqual(review.CocktailId, result.CocktailId);
            Assert.AreEqual(review.UserId, result.AuthorId);
            Assert.AreEqual(review.Cocktail.Name, result.CocktailName);
            Assert.AreEqual(review.User.UserName, result.Author);
            Assert.AreEqual(review.Comment, result.Comment);
            Assert.AreEqual(review.Rating, result.Rating);
        }
        public void CorrectReturnInstanceType_ToCocktailReviewDTO()
        {
            //Arrange
            var sut = new CocktailReviewMapper();

            var options  = Utils.GetOptions(nameof(CorrectReturnInstanceType_ToCocktailReviewDTO));
            var cocktail = new Cocktail {
                Id = 1, Name = "Mojito"
            };
            var user = new User {
                Id = 2, UserName = "******"
            };
            var review = new CocktailsUsersReviews
            {
                CocktailId = 1,
                Cocktail   = cocktail,
                UserId     = 2,
                User       = user,
                Comment    = "Top!",
                Rating     = 4
            };

            //Act
            var result = sut.MapToCocktailReviewDTO(review);

            //Assert
            Assert.IsInstanceOfType(result, typeof(CocktailReviewDTO));
        }
        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);
            }
        }
Example #4
0
        public CocktailsUsersReviews MapToCocktailReview(CocktailReviewDTO reviewDTO)
        {
            CocktailsUsersReviews review = new CocktailsUsersReviews
            {
                Rating     = reviewDTO.Rating,
                Comment    = reviewDTO.Comment,
                CocktailId = reviewDTO.CocktailId,
                UserId     = reviewDTO.AuthorId
            };

            return(review);
        }
Example #5
0
        public CocktailReviewDTO MapToCocktailReviewDTO(CocktailsUsersReviews review)
        {
            CocktailReviewDTO reviewDTO = new CocktailReviewDTO
            {
                Rating       = review.Rating,
                Comment      = review.Comment,
                CocktailId   = review.CocktailId,
                CocktailName = review.Cocktail.Name,
                AuthorId     = review.UserId,
                Author       = review.User.UserName
            };

            return(reviewDTO);
        }
Example #6
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);
            }
        }