Пример #1
0
        public async Task SupportPATCHMethod()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PatchSomething");
            var output  = factory(new object[] { "testData" });

            Assert.AreEqual("PATCH", output.Method.Method);
        }
Пример #2
0
        public void NullDynamicHeaderShouldNotBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithDynamicHeader");
            var output  = factory(new object[] { 6, null });

            Assert.Null(output.Headers.Authorization);//, "Headers include Authorization header");
        }
Пример #3
0
        public void DontBlowUpWithDynamicAuthorizationHeaderAndContent()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PutSomeContentWithAuthorization");
            var output  = factory(new object[] { 7, new { Octocat = "Dunetocat" }, "Basic RnVjayB5ZWFoOmhlYWRlcnMh" });

            Assert.NotNull(output.Headers.Authorization);//, "Headers include Authorization header");
            Assert.Equal("RnVjayB5ZWFoOmhlYWRlcnMh", output.Headers.Authorization.Parameter);
        }
Пример #4
0
        public void DynamicHeaderShouldBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithDynamicHeader");
            var output  = factory(new object[] { 6, "Basic RnVjayB5ZWFoOmhlYWRlcnMh" });

            Assert.NotNull(output.Headers.Authorization);//, "Headers include Authorization header");
            Assert.Equal("RnVjayB5ZWFoOmhlYWRlcnMh", output.Headers.Authorization.Parameter);
        }
Пример #5
0
        public void HardcodedQueryParamShouldBeInUrl()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithHardcodedQueryParameter");
            var output = factory(new object[] { 6 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/foo/bar/6?baz=bamf", uri.PathAndQuery);
        }
Пример #6
0
        public void ContentHeadersCanBeHardcoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeStuffWithHardCodedContentTypeHeader");
            var output  = factory(new object[] { 6, "stuff" });

            Assert.True(output.Content.Headers.Contains("Content-Type"), "Content headers include Content-Type header");
            Assert.Equal("literally/anything", output.Content.Headers.ContentType.ToString());
        }
Пример #7
0
        public void EmptyDynamicHeaderShouldBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithCustomHeader");
            var output  = factory(new object[] { 6, "" });

            Assert.True(output.Headers.Contains("X-Emoji"), "Headers include X-Emoji header");
            Assert.Equal("", output.Headers.GetValues("X-Emoji").First());
        }
Пример #8
0
        public void QueryParamWithPathDelimiterShouldBeEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithVoidAndQueryAlias");
            var output  = factory(new object[] { "6/6", "*****@*****.**", "push!=pull" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/void/6%2F6/path?a=test%40example.com&b=push%21%3Dpull", uri.PathAndQuery);
        }
Пример #9
0
        public void QueryParamShouldFormat()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithQueryFormat");
            var output  = factory(new object[] { 6 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo/bar/6.0", uri.PathAndQuery);
        }
Пример #10
0
        public void NonFormattableQueryParamsShouldBeIncluded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithNonFormattableQueryParams");
            var output  = factory(new object[] { true, 'x' });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo?b=True&c=x", uri.PathAndQuery);
        }
Пример #11
0
        public void ParameterizedQueryParamsShouldBeInUrl()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithHardcodedAndOtherQueryParameters");
            var output  = factory(new object[] { 6, "foo" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo/bar/6?baz=bamf&search_for=foo", uri.PathAndQuery);
        }
Пример #12
0
        public void MultipleParametersInTheSameSegmentAreGeneratedProperly()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomethingWithMultipleParametersPerSegment");
            var output  = factory(new object[] { 6, 1024, 768 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/6/1024x768/foo", uri.PathAndQuery);
        }
Пример #13
0
        public void NullHardcodedHeadersShouldNotBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithNullHardcodedHeader");
            var output  = factory(new object[] { 6 });

            Assert.True(output.Headers.Contains("User-Agent"), "Headers include User-Agent header");
            Assert.Equal("RefitTestClient", output.Headers.UserAgent.ToString());
            Assert.False(output.Headers.Contains("Api-Version"), "Headers include Api-Version header");
        }
Пример #14
0
        public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncodedWhenMixedReplacementAndQueryBadId()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithVoidAndQueryAlias");
            var output  = factory(new object[] { "6", "*****@*****.**", "push!=pull" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/void/6/path?a=test%40example.com&b=push%21%3Dpull", uri.PathAndQuery);
        }
Пример #15
0
        public void SuchFlexibleContentTypeWow()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PutSomeStuffWithDynamicContentType");
            var output  = factory(new object[] { 7, "such \"refit\" is \"amaze\" wow", "text/dson" });

            Assert.NotNull(output.Content);                                          //, "Request has content");
            Assert.NotNull(output.Content.Headers.ContentType);                      //, "Headers include Content-Type header");
            Assert.Equal("text/dson", output.Content.Headers.ContentType.MediaType); //, "Content-Type header has the expected value");
        }
Пример #16
0
        public void QueryStringWithArrayFormatted(string apiMethodName, string expectedQuery)
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));

            var factory = fixture.BuildRequestFactoryForMethod(apiMethodName);
            var output  = factory(new object[] { new [] { 1, 2, 3 } });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal(expectedQuery, uri.PathAndQuery);
        }
Пример #17
0
        public void AddCustomHeadersToRequestHeadersOnly()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeStuffWithCustomHeader");
            var output  = factory(new object[] { 6, new { Foo = "bar" }, ":smile_cat:" });

            Assert.True(output.Headers.Contains("Api-Version"), "Headers include Api-Version header");
            Assert.True(output.Headers.Contains("X-Emoji"), "Headers include X-Emoji header");
            Assert.False(output.Content.Headers.Contains("Api-Version"), "Content headers include Api-Version header");
            Assert.False(output.Content.Headers.Contains("X-Emoji"), "Content headers include X-Emoji header");
        }
Пример #18
0
        public async Task ICanPostAValueTypeIfIWantYoureNotTheBossOfMe()
        {
            var fixture  = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory  = fixture.BuildRequestFactoryForMethod("PostAValueType");
            var guid     = Guid.NewGuid();
            var expected = string.Format("\"{0}\"", guid);
            var output   = factory(new object[] { 7, guid });

            var content = await output.Content.ReadAsStringAsync();

            Assert.AreEqual(expected, content);
        }
Пример #19
0
        [UseCulture("es-ES")] // Spain uses a , instead of a .
        public void DefaultParmeterFormatterIsInvariant()
        {
            var settings = new RefitSettings();
            var fixture  = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuff");
            var output  = factory(new object[] { 5.4 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo/bar/5.4", uri.PathAndQuery);
        }
Пример #20
0
        public void QueryStringWithArrayFormattedAsSsvAndItemsFormattedIndividually()
        {
            var settings = new RefitSettings {
                UrlParameterFormatter = new TestUrlParameterFormatter("custom-parameter")
            };
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("QueryWithArrayFormattedAsSsv");
            var output  = factory(new object[] { new int[] { 1, 2, 3 } });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/query?numbers=custom-parameter%20custom-parameter%20custom-parameter", uri.PathAndQuery);
        }
Пример #21
0
        public void QueryStringWithArrayCanBeFormatted()
        {
            var settings = new RefitSettings {
                UrlParameterFormatter = new TestEnumerableUrlParameterFormatter()
            };
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("QueryWithArray");
            var output  = factory(new object[] { new int[] { 1, 2, 3 } });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/query?numbers=1%2C2%2C3", uri.PathAndQuery);
        }
Пример #22
0
        public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithHardcodedAndOtherQueryParameters");
            var output  = factory(new object[] { 6, "push!=pull" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

#if NETCOREAPP2_0
            Assert.Equal("/foo/bar/6?baz=bamf&search_for=push!%3Dpull", uri.PathAndQuery);
#else
            Assert.Equal("/foo/bar/6?baz=bamf&search_for=push!%3dpull", uri.PathAndQuery);
#endif
        }
Пример #23
0
        public async Task CustomParmeterFormatterCommaSeparatedArray()
        {
            var settings = new RefitSettings {
                UrlParameterFormatter = new TestUrlParameterFormatter("?value=1,2,3&bcd=5")
            };
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuff");
            var output  = factory(new object[] { 5 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo/bar/?value=1%2c2%2c3&bcd=5", uri.PathAndQuery);
        }
Пример #24
0
        public void CustomParmeterFormatter()
        {
            var settings = new RefitSettings {
                UrlParameterFormatter = new TestUrlParameterFormatter("custom-parameter")
            };
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuff");
            var output  = factory(new object[] { 5 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);

            Assert.Equal("/foo/bar/custom-parameter", uri.PathAndQuery);
        }
Пример #25
0
        public async Task FormFieldGetsAliased()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeAliasedUrlEncodedStuff");
            var output  = factory(
                new object[] {
                6,
                new SomeRequestData {
                    ReadablePropertyName = 99
                }
            });

            string content = await output.Content.ReadAsStringAsync();

            Assert.AreEqual("rpn=99", content);
        }
Пример #26
0
        public async Task BodyContentGetsUrlEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeUrlEncodedStuff");
            var output  = factory(
                new object[] {
                6,
                new {
                    Foo = "Something",
                    Bar = 100,
                    Baz = default(string)
                }
            });

            string content = await output.Content.ReadAsStringAsync();

            Assert.AreEqual("Foo=Something&Bar=100&Baz=", content);
        }
Пример #27
0
        public void MethodsThatDontHaveAnHttpMethodShouldFail()
        {
            var failureMethods = new[] {
                "SomeOtherMethod",
                "weofjwoeijfwe",
                null,
            };

            var successMethods = new[] {
                "FetchSomeStuff",
            };

            foreach (var v in failureMethods)
            {
                bool shouldDie = true;

                try {
                    var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
                    fixture.BuildRequestFactoryForMethod(v);
                } catch (Exception) {
                    shouldDie = false;
                }
                Assert.False(shouldDie);
            }

            foreach (var v in successMethods)
            {
                bool shouldDie = false;

                try {
                    var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
                    fixture.BuildRequestFactoryForMethod(v);
                } catch (Exception) {
                    shouldDie = true;
                }

                Assert.False(shouldDie);
            }
        }
Пример #28
0
        public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithHardcodedAndOtherQueryParameters");
            var output = factory(new object[] { 6, "*****@*****.**" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/foo/bar/6?baz=bamf&search_for=test%40example.com", uri.PathAndQuery);
        }
Пример #29
0
        public void QueryParamWithPathDelimiterShouldBeEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithVoidAndQueryAlias");
            var output = factory(new object[] { "6/6", "*****@*****.**", "push!=pull" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/void/6%2F6/path?a=test%40example.com&b=push!%3dpull", uri.PathAndQuery);
        }
Пример #30
0
        public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncodedWhenMixedReplacementAndQueryBadId()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithVoidAndQueryAlias");
            var output = factory(new object[] { "6", "*****@*****.**", "push!=pull" });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/void/6/path?a=test%40example.com&b=push!%3dpull", uri.PathAndQuery);
        }
Пример #31
0
        public void DontBlowUpWithDynamicAuthorizationHeaderAndContent() 
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PutSomeContentWithAuthorization");
            var output = factory(new object[] { 7, new { Octocat = "Dunetocat" }, "Basic RnVjayB5ZWFoOmhlYWRlcnMh" });

            Assert.IsNotNull(output.Headers.Authorization, "Headers include Authorization header");
            Assert.AreEqual("RnVjayB5ZWFoOmhlYWRlcnMh", output.Headers.Authorization.Parameter);
        }
Пример #32
0
        public async Task BodyContentGetsUrlEncoded() 
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeUrlEncodedStuff");
            var output = factory(
                new object[] {
                    6, 
                    new {
                        Foo = "Something", 
                        Bar = 100, 
                        Baz = default(string)
                    }
                });

            string content = await output.Content.ReadAsStringAsync();

            Assert.AreEqual("Foo=Something&Bar=100&Baz=", content);
        }
Пример #33
0
        public async Task FormFieldGetsAliased()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeAliasedUrlEncodedStuff");
            var output = factory(
                new object[] {
                    6, 
                    new SomeRequestData {
                        ReadablePropertyName = 99
                    }
                });

            string content = await output.Content.ReadAsStringAsync();

            Assert.AreEqual("rpn=99", content);
        }
Пример #34
0
        public void SuchFlexibleContentTypeWow()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PutSomeStuffWithDynamicContentType");
            var output = factory(new object[] { 7, "such \"refit\" is \"amaze\" wow", "text/dson" });

            Assert.IsNotNull(output.Content, "Request has content");
            Assert.IsNotNull(output.Content.Headers.ContentType, "Headers include Content-Type header");
            Assert.AreEqual("text/dson", output.Content.Headers.ContentType.MediaType, "Content-Type header has the expected value");
        }
Пример #35
0
        public async Task SupportPATCHMethod()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PatchSomething");
            var output = factory(new object[] { "testData" });

            Assert.AreEqual("PATCH", output.Method.Method);
        }
Пример #36
0
        public void NullHardcodedHeadersShouldNotBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithNullHardcodedHeader");
            var output = factory(new object[] { 6 });

            Assert.IsTrue(output.Headers.Contains("User-Agent"), "Headers include User-Agent header");
            Assert.AreEqual("Refit Test Client", output.Headers.UserAgent.ToString());
            Assert.IsFalse(output.Headers.Contains("Api-Version"), "Headers include Api-Version header");
        }
Пример #37
0
        public void NullDynamicHeaderShouldNotBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithDynamicHeader");
            var output = factory(new object[] { 6, null });

            Assert.IsNull(output.Headers.Authorization, "Headers include Authorization header");
        }
Пример #38
0
        public void MethodsThatDontHaveAnHttpMethodShouldFail()
        {
            var failureMethods = new[] {
                "SomeOtherMethod",
                "weofjwoeijfwe",
                null,
            };

            var successMethods = new[] {
                "FetchSomeStuff",
            };

            foreach (var v in failureMethods) {
                bool shouldDie = true;

                try {
                    var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
                    fixture.BuildRequestFactoryForMethod(v);
                } catch (Exception ex) {
                    shouldDie = false;
                }
                Assert.IsFalse(shouldDie);
            }

            foreach (var v in successMethods) {
                bool shouldDie = false;

                try {
                    var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
                    fixture.BuildRequestFactoryForMethod(v);
                } catch (Exception ex) {
                    shouldDie = true;
                }

                Assert.IsFalse(shouldDie);
            }
        }
Пример #39
0
        public void EmptyDynamicHeaderShouldBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithCustomHeader");
            var output = factory(new object[] { 6, "" });

            Assert.IsTrue(output.Headers.Contains("X-Emoji"), "Headers include X-Emoji header");
            Assert.AreEqual("", output.Headers.GetValues("X-Emoji").First());
        }
Пример #40
0
        public void DynamicHeaderShouldBeInHeaders()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuffWithDynamicHeader");
            var output = factory(new object[] { 6, "Basic RnVjayB5ZWFoOmhlYWRlcnMh" });

            Assert.IsNotNull(output.Headers.Authorization, "Headers include Authorization header");
            Assert.AreEqual("RnVjayB5ZWFoOmhlYWRlcnMh", output.Headers.Authorization.Parameter);
        }
Пример #41
0
        public async Task CustomParmeterFormatter()
        {
            var settings = new RefitSettings { UrlParameterFormatter = new TestUrlParameterFormatter("custom-parameter") };
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi), settings);

            var factory = fixture.BuildRequestFactoryForMethod("FetchSomeStuff");
            var output = factory(new object[] { 5 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/foo/bar/custom-parameter", uri.PathAndQuery);
        }
Пример #42
0
        public void MultipleParametersInTheSameSegmentAreGeneratedProperly()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("FetchSomethingWithMultipleParametersPerSegment");
            var output = factory(new object[] { 6, 1024, 768 });

            var uri = new Uri(new Uri("http://api"), output.RequestUri);
            Assert.AreEqual("/6/1024x768/foo", uri.PathAndQuery);
        }
Пример #43
0
        public void ContentHeadersCanBeHardcoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeStuffWithHardCodedContentTypeHeader");
            var output = factory(new object[] { 6, "stuff" });

            Assert.IsTrue(output.Content.Headers.Contains("Content-Type"), "Content headers include Content-Type header");
            Assert.AreEqual("literally/anything", output.Content.Headers.ContentType.ToString());
        }
Пример #44
0
        public void AddCustomHeadersToRequestHeadersOnly()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostSomeStuffWithCustomHeader");
            var output = factory(new object[] { 6, new { Foo = "bar" }, ":smile_cat:" });

            Assert.IsTrue(output.Headers.Contains("Api-Version"), "Headers include Api-Version header");
            Assert.IsTrue(output.Headers.Contains("X-Emoji"), "Headers include X-Emoji header");
            Assert.IsFalse(output.Content.Headers.Contains("Api-Version"), "Content headers include Api-Version header");
            Assert.IsFalse(output.Content.Headers.Contains("X-Emoji"), "Content headers include X-Emoji header");
        }
Пример #45
0
        public async Task ICanPostAValueTypeIfIWantYoureNotTheBossOfMe()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.BuildRequestFactoryForMethod("PostAValueType");
            var guid = Guid.NewGuid();
            var expected = string.Format("\"{0}\"", guid);
            var output = factory(new object[] { 7, guid });

            var content = await output.Content.ReadAsStringAsync();
            
            Assert.AreEqual(expected, content);
        }