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

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

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

            var deleteCommand = new Delete.Command(createdArticle.Slug);

            var dbContext = GetDbContext();

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

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

            Assert.Null(article);
        }
Exemple #2
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);
        }
Exemple #3
0
        public async Task Expect_Create_Article()
        {
            var command = new Create.Command
            {
                Article = new Create.ArticleData
                {
                    Title       = "Test article 666",
                    Description = "Description of the test article",
                    Body        = "Body of the test article",
                    TagList     = new[] { "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.Length);
        }
Exemple #4
0
        public async Task Expect_Edit_Article()
        {
            var createCommand = new Create.Command()
            {
                Article = new Create.ArticleData()
                {
                    Title       = "Test article 666",
                    Description = "Description of the test article",
                    Body        = "Body of the test article",
                    TagList     = new[] { "tag1", "tag2" }
                }
            };

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

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

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

            var dbContext = GetDbContext();

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

            Assert.NotNull(edited);
            Assert.Equal(edited.Article.Title, command.Article.Title);
            Assert.Equal(edited.Article.TagList.Count, command.Article.TagList.Length);
            // use assert Contains because we do not know the order in which the tags are saved/retrieved
            Assert.Contains(edited.Article.TagList[0], command.Article.TagList);
            Assert.Contains(edited.Article.TagList[1], command.Article.TagList);
        }