private async Task SeedBlogsAsync()
        {
            var blog = await _blogRepository.InsertAsync(
                await _blogManager.CreateAsync(_cmsKitTestData.BlogName, _cmsKitTestData.BlogSlug), autoSave : true);

            _cmsKitTestData.Blog_Id = blog.Id;

            var author = await _cmsUserRepository.GetAsync(_cmsKitTestData.User1Id);

            _cmsKitTestData.BlogPost_1_Id =
                (await _blogPostRepository.InsertAsync(
                     await _blogPostManager.CreateAsync(
                         author,
                         blog,
                         _cmsKitTestData.BlogPost_1_Title,
                         _cmsKitTestData.BlogPost_1_Slug,
                         "Short desc 1",
                         "Blog Post 1 Content"))).Id;

            _cmsKitTestData.BlogPost_2_Id =
                (await _blogPostRepository.InsertAsync(
                     await _blogPostManager.CreateAsync(
                         author,
                         blog,
                         _cmsKitTestData.BlogPost_2_Title,
                         _cmsKitTestData.BlogPost_2_Slug,
                         "Short desc 2",
                         "Blog Post 2 Content"))).Id;
        }
    public async Task ShouldCreateItem_WithDraftStatus()
    {
        var user2 = await userRepository.GetAsync(testData.User2Id);

        var blog = await blogRepository.GetAsync(testData.Blog_Id);

        var draftPost = await blogPostManager.CreateAsync(
            user2,
            blog,
            testData.BlogPost_1_Title + "draft",
            testData.BlogPost_1_Slug + "draft",
            BlogPostStatus.Draft,
            "Short desc 1",
            "Blog Post 1 Content"
            );


        await blogPostRepository.InsertAsync(draftPost);

        var draftPostFromDb = await blogPostRepository.GetAsync(draftPost.Id);

        draftPostFromDb.Title.ShouldBe(draftPost.Title);
        draftPostFromDb.Slug.ShouldBe(draftPost.Slug);
        draftPostFromDb.ShortDescription.ShouldBe(draftPost.ShortDescription);
        draftPostFromDb.Content.ShouldBe(draftPost.Content);
        draftPostFromDb.Status.ShouldBe(BlogPostStatus.Draft);
    }
Beispiel #3
0
    public async Task CreateAsync_ShouldWorkProperly_WithExistingUserAndBlog()
    {
        var title = "New blog post";
        var slug  = "new-blog-post";

        var author = await userRepository.GetAsync(cmsKitTestData.User1Id);

        var blog = await blogRepository.GetAsync(cmsKitTestData.Blog_Id);

        var blogPost = await blogPostManager.CreateAsync(author, blog, title, slug, BlogPostStatus.Published);

        blogPost.Id.ShouldNotBe(Guid.Empty);
        blogPost.Title.ShouldBe(title);
        blogPost.Slug.ShouldBe(slug);
    }
    public async Task GetListAsync_ShouldFilterByUser()
    {
        var user2 = await userRepository.GetAsync(cmsKitTestData.User2Id);

        var blog = await blogRepository.GetAsync(cmsKitTestData.Blog_Id);

        var blogPost = await blogPostManager.CreateAsync(
            user2,
            blog,
            cmsKitTestData.BlogPost_1_Title + "by user2",
            cmsKitTestData.BlogPost_1_Slug + "by user2",
            BlogPostStatus.Published,
            "Short desc 1",
            "Blog Post 1 Content"
            );

        await blogPostRepository.InsertAsync(blogPost);

        //should get all not filtered by user
        var blogPosts = await blogPostAppService.GetListAsync(cmsKitTestData.BlogSlug,
                                                              new BlogPostGetListInput {});

        blogPosts.ShouldNotBeNull();
        blogPosts.TotalCount.ShouldBe(3);
        blogPosts.Items.ShouldNotBeEmpty();
        blogPosts.Items.Count.ShouldBe(3);

        //should get only one filtered by user
        blogPosts = await blogPostAppService.GetListAsync(cmsKitTestData.BlogSlug,
                                                          new BlogPostGetListInput { AuthorId = user2.Id });

        blogPosts.ShouldNotBeNull();
        blogPosts.TotalCount.ShouldBe(1);
        blogPosts.Items.ShouldNotBeEmpty();
        blogPosts.Items.Count.ShouldBe(1);

        //should get filtered by user1
        blogPosts = await blogPostAppService.GetListAsync(cmsKitTestData.BlogSlug,
                                                          new BlogPostGetListInput { AuthorId = cmsKitTestData.User1Id });

        blogPosts.ShouldNotBeNull();
        blogPosts.TotalCount.ShouldBe(2);
        blogPosts.Items.ShouldNotBeEmpty();
        blogPosts.Items.Count.ShouldBe(2);
    }
        public override async Task <BlogPostDto> CreateAsync(CreateBlogPostDto input)
        {
            _ = await UserLookupService.GetByIdAsync(CurrentUser.GetId());

            var entity = await BlogPostManager
                         .CreateAsync(
                new BlogPost(
                    GuidGenerator.Create(),
                    input.BlogId,
                    input.Title,
                    input.Slug,
                    input.ShortDescription));

            return(await MapToGetOutputDtoAsync(entity));
        }
Beispiel #6
0
        public virtual async Task <BlogPostDto> CreateAsync(CreateBlogPostDto input)
        {
            var author = await UserLookupService.GetByIdAsync(CurrentUser.GetId());

            var blog = await BlogRepository.GetAsync(input.BlogId);

            var blogPost = await BlogPostManager.CreateAsync(
                author,
                blog,
                input.Title,
                input.Slug,
                input.ShortDescription,
                CurrentTenant.Id);

            await BlogPostRepository.InsertAsync(blogPost);

            return(ObjectMapper.Map <BlogPost, BlogPostDto>(blogPost));
        }