public void Given_a_valid_Instant_When_WithCreated_is_called_Then_Created_Should_be_set()
        {
            // Arrange.
            IClock          clock   = ConstantClockStub.Create(0);
            BlogPostBuilder builder = BlogPostBuilder.Create(clock);
            Instant         created = Instant.FromUnixTimeMilliseconds(100000);

            // Act.
            builder = builder.WithCreated(created);

            // Assert.
            builder.Created.Should().Be(created);
        }
        public void Given_null_IClock_When_Create_is_called_Then_an_ArgumentNullException_should_be_thrown()
        {
            // Arrange.
            IClock clock = null;

            // Act.
            Action createBuilder = () => BlogPostBuilder.Create(clock);

            // Assert.
            createBuilder.Should()
            .Throw <ArgumentNullException>()
            .WithMessage("*cannot be null*clock*");
        }
        public void Given_a_valid_guid_When_WithId_is_called_Then_Id_should_be_set()
        {
            // Arrange.
            IClock          clock   = ConstantClockStub.Create(0);
            BlogPostBuilder builder = BlogPostBuilder.Create(clock);
            Guid            id      = Guid.NewGuid();

            // Act.
            builder = builder.WithId(id);

            // Assert.
            builder.Id.Should().Be(id);
        }
        public void Given_tags_is_not_null_When_WithTags_is_called_Then_Tags_should_be_set()
        {
            // Arrange.
            IClock              clock   = ConstantClockStub.Create(0);
            BlogPostBuilder     builder = BlogPostBuilder.Create(clock);
            IImmutableSet <Tag> tags    = ImmutableHashSet.Create(Tag.Create("name"));

            // Act.
            builder = builder.WithTags(tags);

            // Assert.
            builder.Tags.Should().BeEquivalentTo(tags);
        }
        public void Given_content_is_not_null_When_WithContent_is_called_Then_Content_should_be_set()
        {
            // Arrange.
            IClock          clock   = ConstantClockStub.Create(0);
            BlogPostBuilder builder = BlogPostBuilder.Create(clock);
            string          content = "Content";

            // Act.
            builder = builder.WithContent(content);

            // Assert.
            builder.Content.Should().Be(content);
        }
        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*");
        }
        public void Given_two_sets_of_tags_When_WithTags_is_called_Then_Tags_should_be_last_set_of_tags()
        {
            // Arrange.
            IClock              clock     = ConstantClockStub.Create(0);
            BlogPostBuilder     builder   = BlogPostBuilder.Create(clock);
            IImmutableSet <Tag> tags      = ImmutableHashSet.Create(Tag.Create("name"), Tag.Create("pizza"));
            IImmutableSet <Tag> otherTags = ImmutableHashSet.Create(Tag.Create("name"), Tag.Create("age"));

            // Act.
            builder = builder.WithTags(tags)
                      .WithTags(otherTags);

            // Assert.
            builder.Tags.Should().BeEquivalentTo(otherTags);
        }
        public void Given_tags_is_null_When_WithTags_is_called_Then_an_ArgumentNullException_should_be_thrown()
        {
            // Arrange.
            IClock              clock   = ConstantClockStub.Create(0);
            BlogPostBuilder     builder = BlogPostBuilder.Create(clock);
            IImmutableSet <Tag> tags    = null;

            // Act.
            Action testCode = () => builder.WithTags(tags);

            // Assert.
            testCode.Should()
            .Throw <ArgumentNullException>()
            .WithMessage("*cannot be null*tags*");
        }
예제 #10
0
        public void Given_a_valid_IClock_When_Create_is_called_Then_builder_should_have_defaults_set()
        {
            // Arrange.
            BlogPostBuilder builder;
            IClock          clock = ConstantClockStub.Create(0);

            // Act.
            builder = BlogPostBuilder.Create(clock);

            // Assert.
            builder.Id.Should().Be(Guid.Empty);
            builder.Content.Should().Be(string.Empty);
            builder.Created.Should().Be(clock.GetCurrentInstant());
            builder.Status.Should().BeEquivalentTo(BlogPostStatus.Draft);
            builder.Tags.Should().BeEmpty();
        }
예제 #11
0
        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);
        }