Beispiel #1
0
        public async Task Given_null_content_when_cloning_should_return_null_content()
        {
            HttpContent content = null;

            // Act
            // ReSharper disable once ExpressionIsAlwaysNull
            ByteArrayContent clone = await content.CloneAsByteArrayContentAsync();

            // Assert
            clone.Should().BeNull();
        }
Beispiel #2
0
        public async Task Given_content_when_cloning_should_return_byte_array_content_with_same_data_and_headers(HttpContent content, string expectedData)
        {
            // Act
            ByteArrayContent clone = await content.CloneAsByteArrayContentAsync();

            // Assert
            clone.Should().NotBeNull();
            clone.Headers.Should().BeEquivalentTo(content.Headers);

            string actual = await clone.ReadAsStringAsync();

            actual.Should().Be(expectedData);
        }
Beispiel #3
0
        /// <summary>
        /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request.
        /// </summary>
        /// <param name="responds"></param>
        /// <param name="statusCode">The status code response for given request.</param>
        /// <param name="content">The response content.</param>
        public static TResult Respond <TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, HttpContent content)
            where TResult : IResponseResult
        {
            if (responds is null)
            {
                throw new ArgumentNullException(nameof(responds));
            }

            if (content is null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            return(responds.Respond(async() => new HttpResponseMessage(statusCode)
            {
                Content = await content.CloneAsByteArrayContentAsync().ConfigureAwait(false)
            }));
        }
Beispiel #4
0
        public async Task Given_content_when_cloning_multiple_times_should_not_throw(HttpContent content, string expectedData)
        {
            // Act
            for (int i = 0; i < 3; i++)
            {
                ByteArrayContent clone = null;
                Func <Task>      act   = async() => clone = await content.CloneAsByteArrayContentAsync();

                // Assert
                await act.Should().NotThrowAsync();

                clone.Should().NotBeNull();
                clone.Headers.Should().BeEquivalentTo(content.Headers, "iteration {0} should have same headers", i);

                string actual = await clone.ReadAsStringAsync();

                actual.Should().Be(expectedData, "iteration {0} should have same data", i);
            }
        }