Example #1
0
        public async Task Expect_Delete_Article_With_Comments()
        {
            var createArticleCommand = new Create.Command
            {
                Article = new Create.ArticleData
                {
                    Title       = "Test article 666",
                    Description = "Description of the test article",
                    Body        = "Body of the test article"
                }
            };

            var createdArticle = await ArticleHelpers.CreateArticle(this, createArticleCommand);

            var article = await ExecuteDbContextAsync(context => context.Articles
                                                      .Include(a => a.ArticleTags)
                                                      .Where(d => d.Slug == createdArticle.Slug)
                                                      .SingleOrDefaultAsync());

            var articleId = article.ArticleId;
            var slug      = article.Slug;

            var createCommentCommand = new beeforum.Features.Comments.Create.Command
            {
                Comment = new beeforum.Features.Comments.Create.CommentData
                {
                    Body = "article comment"
                },
                Slug = slug
            };

            var comment = await CommentHelpers.CreateComment(this, createCommentCommand, UserHelpers.DefaultUserName);

            // delete article with comment
            var deleteCommand = new Delete.Command(slug);

            var dbContext = GetDbContext();

            var handler = new Delete.Handler(dbContext);
            await handler.Handle(deleteCommand, new CancellationToken());

            var deleted = await ExecuteDbContextAsync(context =>
                                                      context.Articles.Where(d => d.Slug == deleteCommand.Slug).SingleOrDefaultAsync());

            Assert.Null(deleted);
        }
Example #2
0
        public async Task Expect_Delete_Article_With_Comments()
        {
            var createArticleCmd = new Create.Command()
            {
                Article = new Create.ArticleData()
                {
                    Title       = "Test article dsergiu77",
                    Description = "Description of the test article",
                    Body        = "Body of the test article",
                }
            };

            var article = await ArticleHelpers.CreateArticle(this, createArticleCmd);

            var dbArticle = await ExecuteDbContextAsync(
                db => db.Articles.Include(a => a.ArticleTags)
                .Where(d => d.Slug == article.Slug).SingleOrDefaultAsync()
                );

            var articleId = dbArticle.ArticleId;
            var slug      = dbArticle.Slug;

            // create article comment
            var createCommentCmd = new Codebase.Features.Comments.Create.Command()
            {
                Comment = new Codebase.Features.Comments.Create.CommentData()
                {
                    Body = "article comment"
                },
                Slug = slug
            };

            var comment = await CommentHelpers.CreateComment(this, createCommentCmd, UserHelpers.DefaultUserName);

            // delete article with comment
            var deleteCmd = new Delete.Command(slug);

            var dbContext = GetDbContext();

            var articleDeleteHandler = new Delete.QueryHandler(dbContext);
            await articleDeleteHandler.Handle(deleteCmd, new System.Threading.CancellationToken());

            var deleted = await ExecuteDbContextAsync(db => db.Articles.Where(d => d.Slug == deleteCmd.Slug).SingleOrDefaultAsync());

            Assert.Null(deleted);
        }