/// <summary>
        /// Sets the metadata to be used by the builder.
        /// </summary>
        /// <param name="metadata">The <see cref="PagedEnumerableMetadata"/> to use.</param>
        /// <returns>A new <see cref="PagedEnumerableBuilder{T}"/> with the given <paramref name="metadata"/>.</returns>
        public PagedEnumerableBuilder <T> WithMetadata(PagedEnumerableMetadata metadata)
        {
            if (metadata is null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            return(new PagedEnumerableBuilder <T>(metadata, this.Records));
        }
        public void When_Default_is_called_Then_Count_and_Navigation_should_equal_respective_Default()
        {
            // Act.
            var defaultMetadata   = PagedEnumerableMetadata.Default();
            var defaultCount      = PagedEnumerableCount.Default();
            var defaultNavigation = PagedEnumerableNavigation.Default();

            // Assert.
            defaultMetadata.Count.Should().BeEquivalentTo(defaultCount);
            defaultMetadata.Navigation.Should().BeEquivalentTo(defaultNavigation);
        }
Exemple #3
0
        public void Given_no_inputs_When_Create_is_called_Then_Metadata_should_be_same_as_Default_PagedEnumerableMetadata()
        {
            // Arrange.
            PagedEnumerableMetadata         defaultMetadata = PagedEnumerableMetadata.Default();
            PagedEnumerableBuilder <object> builder;

            // Act.
            builder = PagedEnumerableBuilder <object> .Create();

            // Assert.
            builder.Metadata.Should().BeEquivalentTo(defaultMetadata);
        }
        public void Given_a_null_builder_When_Create_is_called_Then_an_AgrumentNullException_should_be_thrown()
        {
            // Arrange.
            PagedEnumerableMetadataBuilder builder = null;

            // Act.
            Action testCode = () => PagedEnumerableMetadata.Create(builder);

            // Assert.
            testCode.Should()
            .Throw <ArgumentNullException>()
            .WithMessage("*cannot be null*builder*");
        }
Exemple #5
0
        public void Given_valid_inputs_When_Build_is_called_Then_a_matching_PagedEnumerable_should_be_created()
        {
            // Arrange.
            IEnumerable <object>    records  = new object[] { "Hello", "World" };
            PagedEnumerableMetadata metadata = PagedEnumerableMetadataFactory.WellFormed();

            var builder = PagedEnumerableBuilder <object> .Create()
                          .WithMetadata(metadata)
                          .WithRecords(records);

            // Act.
            var pagedEnumerable = builder.Build();

            // Assert.
            pagedEnumerable.Records.Should().BeEquivalentTo(records);
            pagedEnumerable.Metadata.Should().BeEquivalentTo(metadata);
        }
Exemple #6
0
        public void Given_valid_input_When_WithMetadata_is_called_Then_Metadata_should_equal_input(PagedEnumerableMetadata metadata)
        {
            // Arrange.
            var builder = PagedEnumerableBuilder <object> .Create();

            // Act.
            builder = builder.WithMetadata(metadata);

            // Assert.
            builder.Metadata.Should().BeEquivalentTo(metadata);
        }
 private PagedEnumerableBuilder(PagedEnumerableMetadata metadata, IEnumerable <T> records)
 {
     this.Records  = ImmutableList.CreateRange(records);
     this.Metadata = metadata;
 }