Beispiel #1
0
        public void read_should_null_when_media_type_is_unspecified()
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var request = new HttpRequestMessage(Get, "http://tempuri.org");

            // act
            var version = reader.Read(request);

            // assert
            version.Should().BeNull();
        }
Beispiel #2
0
        public void read_should_retrieve_version_from_accept_with_quality(string[] mediaTypes, string expected)
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var request = new HttpRequestMessage(Get, "http://tempuri.org");

            foreach (var mediaType in mediaTypes)
            {
                request.Headers.Accept.Add(Parse(mediaType));
            }

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be(expected);
        }
Beispiel #3
0
        public void read_should_retrieve_version_from_accept()
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var request = new HttpRequestMessage(Get, "http://tempuri.org");
            var accept  = new MediaTypeWithQualityHeaderValue("application/json")
            {
                Parameters = { new NameValueHeaderValue("v", "2.0") }
            };

            request.Headers.Accept.Add(accept);

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be("2.0");
        }
Beispiel #4
0
        public void read_should_prefer_version_from_content_type_over_accept()
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var request = new HttpRequestMessage(Post, "http://tempuri.org")
            {
                Content = new StringContent("{\"message\":\"test\"}", UTF8)
            };

            request.Content.Headers.ContentType = Parse("application/json;v=2.0");
            request.Headers.Accept.Add(Parse("application/xml"));
            request.Headers.Accept.Add(Parse("application/xml+atom;q=0.8;v=1.5"));
            request.Headers.Accept.Add(Parse("application/json;q=0.2;v=2.0"));

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be("2.0");
        }
Beispiel #5
0
        public void read_should_retrieve_version_from_content_type()
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var request = new HttpRequestMessage(Post, "http://tempuri.org")
            {
                Content = new StringContent("{\"message\":\"test\"}", UTF8)
            };

            request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json")
            {
                Parameters = { new NameValueHeaderValue("v", "2.0") }
            };

            // act
            var version = reader.Read(request);

            // assert
            version.Should().Be("2.0");
        }