Ejemplo n.º 1
0
        public async Task DeleteComment_Throws_When_NoCommentFound()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(DeleteComment_Throws_When_NoCommentFound));

            var user = new User {
                Id = Guid.NewGuid(), UserName = "******"
            };
            var cocktail = new Cocktail {
                Id = Guid.NewGuid(), Name = "Manhattan"
            };
            var cocktailComment = new CocktailComment {
                CocktailId = cocktail.Id, UserId = user.Id
            };
            var commentId = Guid.NewGuid();

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Cocktails.AddAsync(cocktail);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.CocktailComments.AddAsync(cocktailComment);

                await arrangeContext.SaveChangesAsync();
            }

            //Act, Assert
            using (var assertContext = new CMContext(options))
            {
                var sut = new CocktailCommentServices(assertContext);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.DeleteComment(commentId));
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteComment_ShouldDelete_Correct()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(DeleteComment_ShouldDelete_Correct));

            var user = new User {
                Id = Guid.NewGuid(), UserName = "******"
            };
            var cocktail = new Cocktail {
                Id = Guid.NewGuid(), Name = "Manhattan"
            };
            var cocktailComment = new CocktailComment {
                CocktailId = cocktail.Id, UserId = user.Id
            };

            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Cocktails.AddAsync(cocktail);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.CocktailComments.AddAsync(cocktailComment);

                await arrangeContext.SaveChangesAsync();
            }

            //Act, Assert
            using (var assertContext = new CMContext(options))
            {
                var sut    = new CocktailCommentServices(assertContext);
                var result = await sut.DeleteComment(cocktailComment.Id);

                Assert.AreEqual(true, result.IsDeleted);
                Assert.IsInstanceOfType(result, typeof(CocktailCommentsDTO));
            }
        }