public void UseBufferedOutputStream_CausesContentLengthHeaderToBeSet(HttpContent content, bool expectedResult)
        {
            // Arrange & Act
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
            HttpResponseMessage         response = new HttpResponseMessage();

            response.Content = content;

            selector.UseBufferedOutputStream(response);

            IEnumerable <string> contentLengthEnumerable;
            bool isContentLengthInHeaders = content.Headers.TryGetValues("Content-Length", out contentLengthEnumerable);

            string[] contentLengthStrings = isContentLengthInHeaders ? contentLengthEnumerable.ToArray() : new string[0];
            long?    contentLength        = content.Headers.ContentLength;

            // Assert
            if (contentLength.HasValue && contentLength.Value >= 0)
            {
                // Setting the header is HttpContentHeader's responsibility, but we assert
                // it has happened here because it is UseBufferedOutputStream's responsibility
                // to cause that to happen. HttpControllerHandler relies on this.
                Assert.True(isContentLengthInHeaders);
                Assert.Equal(contentLength.Value, long.Parse(contentLengthStrings[0]));
            }
        }
        public void UseBufferedOutputStream_ReturnsCorrectValue(HttpContent content, bool expectedResult)
        {
            // Arrange
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
            HttpResponseMessage response = new HttpResponseMessage();
            response.Content = content;

            // Act
            bool actualResult = selector.UseBufferedOutputStream(response);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
        public void UseBufferedOutputStream_ReturnsCorrectValue(HttpContent content, bool expectedResult)
        {
            // Arrange
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
            HttpResponseMessage         response = new HttpResponseMessage();

            response.Content = content;

            // Act
            bool actualResult = selector.UseBufferedOutputStream(response);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
        public void UseBufferedOutputStream_ThrowsOnNull()
        {
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();

            Assert.ThrowsArgumentNull(() => selector.UseBufferedOutputStream(null), "response");
        }
        void UseBufferedInputStream_ThrowsOnNull()
        {
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();

            Assert.ThrowsArgumentNull(() => selector.UseBufferedInputStream(null), "hostContext");
        }
        public void UseBufferedOutputStream_CausesContentLengthHeaderToBeSet(HttpContent content, bool expectedResult)
        {
            // Arrange & Act
            WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
            HttpResponseMessage response = new HttpResponseMessage();
            response.Content = content;

            selector.UseBufferedOutputStream(response);

            IEnumerable<string> contentLengthEnumerable;
            bool isContentLengthInHeaders = content.Headers.TryGetValues("Content-Length", out contentLengthEnumerable);
            string[] contentLengthStrings = isContentLengthInHeaders ? contentLengthEnumerable.ToArray() : new string[0];
            long? contentLength = content.Headers.ContentLength;

            // Assert
            if (contentLength.HasValue && contentLength.Value >= 0)
            {
                // Setting the header is HttpContentHeader's responsibility, but we assert
                // it has happened here because it is UseBufferedOutputStream's responsibility
                // to cause that to happen. HttpControllerHandler relies on this.
                Assert.True(isContentLengthInHeaders);
                Assert.Equal(contentLength.Value, long.Parse(contentLengthStrings[0]));
            }
        }
 public void UseBufferedOutputStream_ThrowsOnNull()
 {
     WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
     Assert.ThrowsArgumentNull(() => selector.UseBufferedOutputStream(null), "response");
 }
 void UseBufferedInputStream_ThrowsOnNull()
 {
     WebHostBufferPolicySelector selector = new WebHostBufferPolicySelector();
     Assert.ThrowsArgumentNull(() => selector.UseBufferedInputStream(null), "hostContext");
 }