public virtual async Task <BlogPost> CreateAsync( [NotNull] CmsUser author, [NotNull] Blog blog, [NotNull] string title, [NotNull] string slug, [NotNull] BlogPostStatus status, [CanBeNull] string shortDescription = null, [CanBeNull] string content = null, [CanBeNull] Guid?coverImageMediaId = null) { Check.NotNull(author, nameof(author)); Check.NotNull(blog, nameof(blog)); Check.NotNullOrEmpty(title, nameof(title)); Check.NotNullOrEmpty(slug, nameof(slug)); var blogPost = new BlogPost( GuidGenerator.Create(), blog.Id, author.Id, title, slug, shortDescription, content, coverImageMediaId, CurrentTenant.Id, status ); await CheckSlugExistenceAsync(blog.Id, blogPost.Slug); return(blogPost); }
private BlogPostBuilder(Guid id, string content, Instant created, BlogPostStatus status, IImmutableSet <Tag> tags) { this.Id = id; this.Content = content; this.Created = created; this.Status = status; this.Tags = tags; }
/// <summary> /// Sets the <see cref="Status"/> of the builder. /// </summary> /// <param name="status">The <see cref="string"/> to set as the status.</param> /// <returns>A new builder instance with the status set.</returns> public BlogPostBuilder WithStatus(BlogPostStatus status) { if (status is null) { throw new ArgumentNullException(nameof(status)); } return(new BlogPostBuilder(this.Id, this.Content, this.Created, status, this.Tags)); }
private string GetStatusText(BlogPostStatus status) { switch (status) { case BlogPostStatus.WorkingDraft: return("Working Draft"); default: return(status.ToString()); } }
public void Given_status_is_not_null_When_WithStatus_is_called_Then_Status_should_be_set() { // Arrange. IClock clock = ConstantClockStub.Create(0); BlogPostBuilder builder = BlogPostBuilder.Create(clock); BlogPostStatus status = BlogPostStatus.Published; // Act. builder = builder.WithStatus(status); // Assert. builder.Status.Should().Be(status); }
public void Given_stauts_is_null_When_WithStatus_is_called_Then_an_ArgumentNullException_should_be_thrown() { // Arrange. IClock clock = ConstantClockStub.Create(0); BlogPostBuilder builder = BlogPostBuilder.Create(clock); BlogPostStatus status = null; // Act. Action testCode = () => builder.WithStatus(status); // Assert. testCode.Should() .Throw <ArgumentNullException>() .WithMessage("*cannot be null*status*"); }
internal BlogPost( Guid id, Guid blogId, Guid authorId, [NotNull] string title, [NotNull] string slug, [CanBeNull] string shortDescription = null, [CanBeNull] string content = null, [CanBeNull] Guid?coverImageMediaId = null, [CanBeNull] Guid?tenantId = null, [CanBeNull] BlogPostStatus?state = null ) : base(id) { TenantId = tenantId; BlogId = blogId; AuthorId = authorId; SetTitle(title); SetSlug(slug); SetShortDescription(shortDescription); SetContent(content); CoverImageMediaId = coverImageMediaId; Status = state ?? BlogPostStatus.Draft; }
public void Given_a_valid_BlogPostBuilder_When_Build_is_called_Then_a_matching_BlogPost_is_constructed() { // Arrange. IClock clock = ConstantClockStub.Create(0); BlogPostBuilder builder; BlogPost blogPost; Guid id = Guid.NewGuid(); const string content = "Content"; BlogPostStatus draft = BlogPostStatus.Draft; ImmutableHashSet <Tag> tags = ImmutableHashSet.Create(Tag.Create("tag")); builder = BlogPostBuilder.Create(clock) .WithId(id) .WithContent(content) .WithStatus(draft) .WithTags(tags); // Act. blogPost = builder.Build(); // Assert. blogPost.Should().BeEquivalentTo(builder); }
public virtual void SetWaitingForReview() { Status = BlogPostStatus.WaitingForReview; }
public virtual void SetPublished() { Status = BlogPostStatus.Published; }
public virtual void SetDraft() { Status = BlogPostStatus.Draft; }
/// <summary> /// Asynchronously update the <see cref="BlogPostStatus" /> in the system. /// </summary> /// <param name="page">Resource instance.</param> /// <returns>True if <see cref="BlogPostStatus" /> is successfully updated, false otherwise.</returns> public virtual Task <bool> UpdateAsync(BlogPostStatus page) { return(UpdateAsync <BlogPostStatus>(page)); }
/// <summary> /// Asynchronously insert the <see cref="BlogPostStatus" /> into the system. /// </summary> /// <param name="blogPost">Resource instance.</param> /// <returns>Newly created <see cref="BlogPostStatus" /> .</returns> public virtual Task <BlogPostStatus> InsertAsync(BlogPostStatus blogPost) { return(InsertAsync <BlogPostStatus>(blogPost)); }