public void ParseAcceptHeader_GracefullyRecoversFromInvalidMediaTypeValues_AndReturnsValidMediaTypes(
            string[] acceptHeader,
            string[] expected)
        {
            // Arrange
            var expectedMediaTypes = expected.Select(e => new MediaTypeSegmentWithQuality(new StringSegment(e), 1.0)).ToList();

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(acceptHeader);

            // Assert
            Assert.Equal(expectedMediaTypes, parsed);
        }
        public void ParseAcceptHeader_InvalidTokenAtEnd()
        {
            // Arrange
            var expected = new MediaTypeSegmentWithQuality[0];

            var input = "*/*:";

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string>()
            {
                input
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
        public void ParseAcceptHeader_DelimiterAtStart()
        {
            // Arrange
            var expected = new MediaTypeSegmentWithQuality[0];

            var input = ",;:";

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string>()
            {
                input
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
        public void ParseAcceptHeader_ValidMediaType_FollowedBySemicolon()
        {
            // Arrange
            var expected = new MediaTypeSegmentWithQuality[0];

            var input = "*/*Content-Type;application/json";

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string>()
            {
                input
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
Exemple #5
0
        public void ParseAcceptHeader_ParsesSimpleHeader()
        {
            // Arrange
            var header   = "application/json";
            var expected = new List <MediaTypeSegmentWithQuality>
            {
                new MediaTypeSegmentWithQuality(new StringSegment("application/json"), 1.0)
            };

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string> {
                header
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
Exemple #6
0
        public void ParseAcceptHeader_ParsesMultipleHeaderValues()
        {
            // Arrange
            var expected = new List <MediaTypeSegmentWithQuality>
            {
                new MediaTypeSegmentWithQuality(new StringSegment("application/json"), 1.0),
                new MediaTypeSegmentWithQuality(new StringSegment("application/xml;q=0.8"), 0.8)
            };

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(
                new List <string> {
                "application/json", "", "application/xml;q=0.8"
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
        public void ParseAcceptHeader_ParsesSimpleHeaderWithMultipleValues_InvalidFormat()
        {
            // Arrange
            var header             = "application/json, application/xml,;q=0.8";
            var expectedMediaTypes = new List <MediaTypeSegmentWithQuality>
            {
                new MediaTypeSegmentWithQuality(new StringSegment("application/json"), 1.0),
                new MediaTypeSegmentWithQuality(new StringSegment("application/xml"), 1.0),
            };

            // Act
            var mediaTypes = AcceptHeaderParser.ParseAcceptHeader(new List <string> {
                header
            });

            // Assert
            Assert.Equal(expectedMediaTypes, mediaTypes);
        }
        public void ParseAcceptHeader_ValidMediaType_FollowedByWhitespace()
        {
            // Arrange
            var expected = new MediaTypeSegmentWithQuality[]
            {
                new MediaTypeSegmentWithQuality(new StringSegment("application/json"), 1.0),
            };

            var input = "*/*Content-Type application/json";

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string>()
            {
                input
            });

            // Assert
            Assert.Equal(expected, parsed);
        }
Exemple #9
0
        public void ParseAcceptHeader_ParsesSimpleHeaderWithMultipleValues()
        {
            // Arrange
            var header   = "application/json, application/xml;q=0.8";
            var expected = new List <MediaTypeSegmentWithQuality>
            {
                new MediaTypeSegmentWithQuality(new StringSegment("application/json"), 1.0),
                new MediaTypeSegmentWithQuality(new StringSegment("application/xml;q=0.8"), 0.8)
            };

            // Act
            var parsed = AcceptHeaderParser.ParseAcceptHeader(new List <string> {
                header
            });

            // Assert
            Assert.Equal(expected, parsed);
            foreach (var mediaType in parsed)
            {
                Assert.Same(header, mediaType.MediaType.Buffer);
            }
        }