Example #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();
        }
Example #2
0
        public void add_parameters_should_add_parameter_for_media_type()
        {
            // arrange
            var reader  = new MediaTypeApiVersionReader();
            var context = new Mock <IApiVersionParameterDescriptionContext>();

            context.Setup(c => c.AddParameter(It.IsAny <string>(), It.IsAny <ApiVersionParameterLocation>()));

            // act
            reader.AddParmeters(context.Object);

            // assert
            context.Verify(c => c.AddParameter("v", MediaTypeParameter), Times.Once());
        }
Example #3
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);
        }
Example #4
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");
        }
Example #5
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");
        }
Example #6
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");
        }