Example #1
0
        public async Task Expect_Delete_Article_With_Tags()
        {
            var createCmd = new Create.Command(new Create.ArticleData()
            {
                Title       = "Test article dsergiu77",
                Description = "Description of the test article",
                Body        = "Body of the test article",
                TagList     = new string[] { "tag1", "tag2" }
            });

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

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

            var deleteCmd = new Delete.Command(article.Slug);

            var dbContext = GetDbContext();

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

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

            Assert.Null(dbArticle);
        }
Example #2
0
        public async Task Expect_Delete_Article()
        {
            var createCmd = 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, createCmd);

            var slug = article.Slug;

            var deleteCmd = new Delete.Command(slug);

            var dbContext = GetDbContext();

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

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

            Assert.Null(dbArticle);
        }
Example #3
0
        public async Task Expect_Edit_Article()
        {
            var createCommand = new Create.Command(new Create.ArticleData()
            {
                Title       = "Test article dsergiu77",
                Description = "Description of the test article",
                Body        = "Body of the test article",
                TagList     = new string[] { "tag1", "tag2" }
            });

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

            var command = new Edit.Command(new(new Edit.ArticleData()
            {
                Title = "Updated " + createdArticle.Title,
                Description = "Updated" + createdArticle.Description,
                Body = "Updated" + createdArticle.Body,
            }), createdArticle.Slug);

            // remove the first tag and add a new tag
            command.Model.Article.TagList = new string[] { createdArticle.TagList[1], "tag3" };

            var dbContext = GetDbContext();

            var articleEditHandler = new Edit.Handler(dbContext);
            var edited             = await articleEditHandler.Handle(command, new System.Threading.CancellationToken());

            Assert.NotNull(edited);
            Assert.Equal(edited.Article.Title, command.Model.Article.Title);
            Assert.Equal(edited.Article.TagList.Count(), command.Model.Article.TagList.Count());
            // use assert Contains because we do not know the order in which the tags are saved/retrieved
            Assert.Contains(edited.Article.TagList[0], command.Model.Article.TagList);
            Assert.Contains(edited.Article.TagList[1], command.Model.Article.TagList);
        }
        public async Task Expect_Create_Article()
        {
            var command = new Create.Command(new Create.ArticleData()
            {
                Title       = "Test article dsergiu77",
                Description = "Description of the test article",
                Body        = "Body of the test article",
                TagList     = new string[] { "tag1", "tag2" }
            });

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

            Assert.NotNull(article);
            Assert.Equal(article.Title, command.Article.Title);
            Assert.Equal(article.TagList.Count(), command.Article.TagList.Count());
        }
Example #5
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 Conduit.Features.Comments.Create.Command()
            {
                Comment = new Conduit.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);
        }