Пример #1
0
        public void ReplaceBaseUrlWithUrlFormat_Content()
        {
            var result = _postUrlHelper.ReplaceBaseUrlWithUrlFormat(_postWithBaseUrls);

            result.Should().NotBeNull();
            result.Content.Should().Be("content with an url: %URL%/pineblog-tests/content-url-1. nice isn't it?");
        }
Пример #2
0
            /// <summary>
            /// Handle the AddPostCommand request.
            /// </summary>
            /// <param name="request">The AddPostCommand request.</param>
            /// <param name="cancellationToken">A cancellation token.</param>
            public async Task <Result <Post> > Handle(AddPostCommand request, CancellationToken cancellationToken)
            {
                var author = await _uow.Authors.SingleOrDefaultAsync(a => a.UserName.Equals(request.UserName), cancellationToken);

                if (author == null)
                {
                    return(Result <Post> .Fail(new NotFoundException($"Could not find author for \"{request.UserName}\".")));
                }

                var entity = new Post
                {
                    AuthorId     = author.Id,
                    Title        = request.Title,
                    Slug         = request.Title.ToPostSlug(),
                    Description  = request.Description,
                    Content      = request.Content,
                    Categories   = request.Categories,
                    Published    = request.Published,
                    CoverUrl     = request.CoverUrl,
                    CoverCaption = request.CoverCaption,
                    CoverLink    = request.CoverLink
                };

                entity = _postUrlHelper.ReplaceBaseUrlWithUrlFormat(entity);

                _uow.Posts.Add(entity);
                var result = await _uow.SaveChangesAsync(cancellationToken);

                if (!result.IsSuccess)
                {
                    return(Result <Post> .Fail(result.Exception));
                }

                return(Result <Post> .Success(entity));
            }
Пример #3
0
            /// <summary>
            /// Handle the UpdatePostCommand request.
            /// </summary>
            /// <param name="request">The UpdatePostCommand request.</param>
            /// <param name="cancellationToken">A cancellation token.</param>
            public async Task <Result <Post> > Handle(UpdatePostCommand request, CancellationToken cancellationToken)
            {
                var entity = await _uow.Posts.SingleOrDefaultAsync(e => e.Id.Equals(request.Id), cancellationToken);

                if (entity == null)
                {
                    return(Result <Post> .Fail(new NotFoundException <Post>($"Could not find post, id: \"{request.Id}\"")));
                }

                entity.Title        = request.Title;
                entity.Slug         = request.Title.ToPostSlug();
                entity.Description  = request.Description;
                entity.Content      = request.Content;
                entity.Categories   = request.Categories;
                entity.Published    = request.Published;
                entity.CoverUrl     = request.CoverUrl;
                entity.CoverCaption = request.CoverCaption;
                entity.CoverLink    = request.CoverLink;

                entity = _postUrlHelper.ReplaceBaseUrlWithUrlFormat(entity);

                _uow.Posts.Update(entity);
                var result = await _uow.SaveChangesAsync(cancellationToken);

                if (!result.IsSuccess)
                {
                    return(Result <Post> .Fail(result.Exception));
                }

                return(Result <Post> .Success(entity));
            }