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); }
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"); }
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); }
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); }
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); }
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()); }
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()); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); }
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"); }
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); }
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"); }
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); }
[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); }
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); }
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); }
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 }
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); }
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); }
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); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); }
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"); }
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"); }
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); } }
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()); }
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); }
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); }
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); }
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()); }
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"); }
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); }