예제 #1
0
        public void DeleteCommentAndItsRepliesShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteCommentAndItsReplies_Comments_Roads_Database")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var roadsService = new RoadsService(dbContext, null, null, null, null, null);

            var commentsService = new CommentsService(roadsService, dbContext);

            var user = new User
            {
                UserName = "******"
            };
            var comment = new Comment
            {
                Content = "comment1",
                Id      = "commentId1",
                Replies = new List <Reply>
                {
                    new Reply
                    {
                        Id = "replyId1",
                    }
                },
                User = user
            };

            dbContext.Users.Add(user);
            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();

            var result = commentsService.DeleteCommentAndItsReplies(comment.Id);

            Assert.True(result);
            Assert.True(comment.IsDeleted);
        }