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

            var cocktail = new Cocktail  {
                Id = Guid.NewGuid(), Name = "Manhattan"
            };
            var userId             = Guid.NewGuid();
            var cocktailCommentDTO = new CocktailCommentsDTO {
                CocktailId = cocktail.Id, UserId = userId
            };


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

                await arrangeContext.SaveChangesAsync();
            }

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

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

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

            var cocktailCommentDTO = new CocktailCommentsDTO {
                CocktailId = cocktail.Id, UserId = user.Id, Comments = "Great"
            };


            using (var arrangeContext = new CMContext(options))
            {
                await arrangeContext.Users.AddRangeAsync(user);

                await arrangeContext.Cocktails.AddRangeAsync(cocktail);

                await arrangeContext.SaveChangesAsync();
            }

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

                Assert.AreEqual(cocktail.Id, result.CocktailId);
                Assert.AreEqual(user.Id, result.UserId);
                Assert.AreEqual(1, assertContext.CocktailComments.Count());
                Assert.IsInstanceOfType(result, typeof(CocktailCommentsDTO));
            }
        }