Пример #1
0
        public void ConstructsUriWithPreservedDuplicateGivenParams()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz");
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz2");
            var uri = this.requester.ConstructUri(null, "/foo", requestInfo);

            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=baz&bar=baz2"), uri);
        }
Пример #2
0
        public void EncodesNullQueryKeys()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, null, "&ba r=");
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, null, "?yay?");
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, string.Empty, "?baz");
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal("http://api.example.com/base/foo?%26ba+r%3d&%3fyay%3f&=%3fbaz", uri.ToString(), ignoreCase: true);
        }
Пример #3
0
 public void IgnoresNullQueryParamsWhenUsingToString()
 {
     var requestInfo = new RequestInfo(HttpMethod.Get, null);
     requestInfo.AddQueryParameter<object>(QuerySerializationMethod.ToString, "bar", null);
     var uri = this.requester.ConstructUri("/foo", requestInfo);
     Assert.Equal(new Uri("http://api.example.com/base/foo"), uri);
 }
Пример #4
0
 public void ConstructsUriCombiningExistingAndGivenParams()
 {
     var requestInfo = new RequestInfo(HttpMethod.Get, null);
     requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz");
     var uri = this.requester.ConstructUri("/foo?a=yay", requestInfo);
     Assert.Equal(new Uri("http://api.example.com/base/foo?a=yay&bar=baz"), uri);
 }
Пример #5
0
        public void ThrowsIfSerializedSerializationMethodUsedButNoRequestQueryParamSerializerSet()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "bar", "boom");
            this.requester.RequestQueryParamSerializer = null;
            Assert.Throws <InvalidOperationException>(() => this.requester.ConstructUri(null, "/foo", requestInfo));
        }
Пример #6
0
        public void EncodesUsingQueryEncoding()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "fo o", "a ?b/c");
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal("http://api.example.com/base/foo?fo+o=a+%3fb%2fc", uri.ToString(), ignoreCase: true);
        }
Пример #7
0
        public void IgnoresNullQueryParamsWhenUsingToString()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter <object>(QuerySerializationMethod.ToString, "bar", null);
            var uri = this.requester.ConstructUri(null, "/foo", requestInfo);

            Assert.Equal(new Uri("http://api.example.com/base/foo"), uri);
        }
Пример #8
0
        public void ConstructsUriCombiningExistingAndGivenParams()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz");
            var uri = this.requester.ConstructUri(null, "/foo?a=yay", requestInfo);

            Assert.Equal(new Uri("http://api.example.com/base/foo?a=yay&bar=baz"), uri);
        }
Пример #9
0
        public void DoesNotIncludeQueryPropertyIfNull()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryProperty <string>(QuerySerializationMethod.ToString, "foo", null);
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "foo", "baz");
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal("http://api.example.com/base/foo?foo=baz", uri.ToString(), ignoreCase: true);
        }
Пример #10
0
        public void UsesQueryPropertiesAsWellAsQueryParameters()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryProperty(QuerySerializationMethod.ToString, "foo", "bar");
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "foo", "baz");
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal("http://api.example.com/base/foo?foo=baz&foo=bar", uri.ToString(), ignoreCase: true);
        }
Пример #11
0
        public void HandlesUnicodeCharacters()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "key", "héllo");
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal("http://api.example.com/base/foo?key=héllo", uri.ToString(), ignoreCase: true);
            Assert.Equal("http://api.example.com/base/foo?key=h%C3%A9llo", uri.AbsoluteUri.ToString(), ignoreCase: true);
        }
Пример #12
0
        public void PrependsRawQueryStringWithQueryParams()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddRawQueryParameter("foo=bar&baz=woo");
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "a", "&b");
            var uri = this.requester.ConstructUri(null, "a", requestInfo);

            Assert.Equal("http://api.example.com/base/a?foo=bar&baz=woo&a=%26b", uri.ToString(), ignoreCase: true);
        }
Пример #13
0
        public void CallsToStringWithFormatParameterIfGivenForToStringSerializationMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);
            var objectMock  = new Mock <IFormattable>();

            objectMock.Setup(x => x.ToString("D3", null)).Returns("BOOM").Verifiable();
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", objectMock.Object, "D3");
            var uri = this.requester.ConstructUri(null, "/foo", requestInfo);

            objectMock.VerifyAll();
            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=BOOM"), uri);
        }
Пример #14
0
        public void DoesNotThrowIfRequestQueryParamSerializerReturnsNull()
        {
            var serializer = new Mock <RequestQueryParamSerializer>();

            serializer.Setup(x => x.SerializeQueryParam("name", "value", new RequestQueryParamSerializerInfo())).Returns((IEnumerable <KeyValuePair <string, string> >)null);

            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "name", "value");
            this.requester.RequestQueryParamSerializer = serializer.Object;
            var uri = this.requester.ConstructUri(null, "foo", requestInfo);

            Assert.Equal(new Uri("http://api.example.com/base/foo"), uri);
        }
Пример #15
0
        public void DoesNotIgnoreNullQueryParamsWhenUsingSerializer()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);
            requestInfo.AddQueryParameter<object>(QuerySerializationMethod.Serialized, "bar", null);

            var queryParameterSerializer = new Mock<IRequestQueryParamSerializer>();
            queryParameterSerializer.Setup(x => x.SerializeQueryParam<object>("bar", null))
                .Returns(new[] { new KeyValuePair<string, string>("bar", "foo") })
                .Verifiable();
            this.requester.RequestQueryParamSerializer = queryParameterSerializer.Object;

            var uri = this.requester.ConstructUri("/foo", requestInfo);
            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=foo"), uri);

            queryParameterSerializer.VerifyAll();
        }
Пример #16
0
        public void PassesFormatWhenSerializing()
        {
            var obj         = new HasToString();
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "bar", obj, "D3");

            var serializer = new Mock <RequestQueryParamSerializer>();

            serializer.Setup(x => x.SerializeQueryParam <HasToString>("bar", obj, new RequestQueryParamSerializerInfo(requestInfo, "D3"))).Returns(new[] { new KeyValuePair <string, string>("bar", "BOOMYAY") }).Verifiable();
            this.requester.RequestQueryParamSerializer = serializer.Object;

            var uri = this.requester.ConstructUri("/foo", requestInfo);

            serializer.VerifyAll();
        }
Пример #17
0
        public void SerializesUsingSerializerForSerializedSerializationMethod()
        {
            var obj         = new HasToString();
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "bar", obj);

            var serializer = new Mock <IRequestQueryParamSerializer>();

            serializer.Setup(x => x.SerializeQueryParam <HasToString>("bar", obj)).Returns(new[] { new KeyValuePair <string, string>("bar", "BOOMYAY") }).Verifiable();
            this.requester.RequestQueryParamSerializer = serializer.Object;

            var uri = this.requester.ConstructUri("/foo", requestInfo);

            serializer.VerifyAll();
            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=BOOMYAY"), uri);
        }
Пример #18
0
        public void DoesNotIgnoreNullQueryParamsWhenUsingSerializer()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);

            requestInfo.AddQueryParameter <object>(QuerySerializationMethod.Serialized, "bar", null);

            var queryParameterSerializer = new Mock <RequestQueryParamSerializer>();

            queryParameterSerializer.Setup(x => x.SerializeQueryParam <object>("bar", null, It.IsAny <RequestQueryParamSerializerInfo>()))
            .Returns(new[] { new KeyValuePair <string, string>("bar", "foo") })
            .Verifiable();
            this.requester.RequestQueryParamSerializer = queryParameterSerializer.Object;

            var uri = this.requester.ConstructUri(null, "/foo", requestInfo);

            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=foo"), uri);

            queryParameterSerializer.VerifyAll();
        }
Пример #19
0
        public void CallsToStringForToStringSerializationMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, null);
            var objectMock = new Mock<HasToString>();
            objectMock.Setup(x => x.ToString()).Returns("BOOM").Verifiable();
            requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", objectMock.Object);
            var uri = this.requester.ConstructUri("/foo", requestInfo);

            objectMock.VerifyAll();
            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=BOOM"), uri);
        }
Пример #20
0
        public void SerializesUsingSerializerForSerializedSerializationMethod()
        {
            var obj = new HasToString();
            var requestInfo = new RequestInfo(HttpMethod.Get, null);
            requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "bar", obj);

            var serializer = new Mock<IRequestQueryParamSerializer>();
            serializer.Setup(x => x.SerializeQueryParam<HasToString>("bar", obj)).Returns(new[] { new KeyValuePair<string, string>("bar", "BOOMYAY") }).Verifiable();
            this.requester.RequestQueryParamSerializer = serializer.Object;

            var uri = this.requester.ConstructUri("/foo", requestInfo);

            serializer.VerifyAll();
            Assert.Equal(new Uri("http://api.example.com/base/foo?bar=BOOMYAY"), uri);
        }
Пример #21
0
 public void ConstructsUriWithPreservedDuplicateGivenParams()
 {
     var requestInfo = new RequestInfo(HttpMethod.Get, null);
     requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz");
     requestInfo.AddQueryParameter(QuerySerializationMethod.ToString, "bar", "baz2");
     var uri = this.requester.ConstructUri("/foo", requestInfo);
     Assert.Equal(new Uri("http://api.example.com/base/foo?bar=baz&bar=baz2"), uri);
 }
Пример #22
0
 public void ThrowsIfSerializedSerializationMethodUsedButNoRequestQueryParamSerializerSet()
 {
     var requestInfo = new RequestInfo(HttpMethod.Get, null);
     requestInfo.AddQueryParameter(QuerySerializationMethod.Serialized, "bar", "boom");
     this.requester.RequestQueryParamSerializer = null;
     Assert.Throws<InvalidOperationException>(() => this.requester.ConstructUri("/foo", requestInfo));
 }