public async Task SupportsNullArgsDictionary() { var hookableHandler = new HookableHandler(); var configuration = SteamConfiguration.Create(c => c.WithHttpClientFactory(() => new HttpClient(hookableHandler))); dynamic iface = configuration.GetAsyncWebAPIInterface("IFooService"); var handlerCalled = false; hookableHandler.OnRequest = request => { Assert.NotNull(request); Assert.Equal(HttpMethod.Get, request.Method); Assert.Equal("/IFooService/PerformFooOperation/v2/", request.RequestUri.AbsolutePath); var values = request.RequestUri.ParseQueryString(); Assert.Single(values); Assert.Equal("vdf", values["format"]); handlerCalled = true; return(Task.CompletedTask); }; var args = default(Dictionary <string, object>); var response = await iface.CallAsync(HttpMethod.Get, "PerformFooOperation", 2, args); Assert.True(handlerCalled); }
public async Task UsesArgsAsQueryStringParams() { var hookableHandler = new HookableHandler(); var configuration = SteamConfiguration.Create(c => c.WithHttpClientFactory(() => new HttpClient(hookableHandler))); dynamic iface = configuration.GetAsyncWebAPIInterface("IFooService"); var handlerCalled = false; hookableHandler.OnRequest = request => { Assert.NotNull(request); Assert.Equal(HttpMethod.Get, request.Method); Assert.Equal("/IFooService/PerformFooOperation/v2/", request.RequestUri.AbsolutePath); var values = request.RequestUri.ParseQueryString(); Assert.Equal(3, values.Count); Assert.Equal("foo", values["f"]); Assert.Equal("bar", values["b"]); Assert.Equal("vdf", values["format"]); handlerCalled = true; return(Task.CompletedTask); }; var args = new Dictionary <string, object> { ["f"] = "foo", ["b"] = "bar", }; var response = await iface.PerformFooOperation2(args); Assert.True(handlerCalled); }
public async Task DoesntThrowWhenCorrectFormatInArgsProvided() { var hookableHandler = new HookableHandler(); var configuration = SteamConfiguration.Create(c => c.WithHttpClientFactory(() => new HttpClient(hookableHandler))); WebAPI.AsyncInterface iface = configuration.GetAsyncWebAPIInterface("IFooService"); var args = new Dictionary <string, object> { ["f"] = "foo", ["b"] = "bar", ["format"] = "vdf" }; await iface.CallAsync(HttpMethod.Get, "GetFoo", args : args); }
public async Task UsesSingleParameterArgumentsDictionary() { var hookableHandler = new HookableHandler(); var configuration = SteamConfiguration.Create(c => c.WithHttpClientFactory(() => new HttpClient(hookableHandler))); dynamic iface = configuration.GetAsyncWebAPIInterface("IFooService"); var args = new Dictionary <string, object> { ["f"] = "foo", ["b"] = "bar", ["method"] = "PUT" }; var handlerCalled = false; hookableHandler.OnRequest = async request => { Assert.NotNull(request); Assert.Equal("/IFooService/PerformFooOperation/v2", request.RequestUri.AbsolutePath); Assert.Equal(HttpMethod.Put, request.Method); var formData = await request.Content.ReadAsFormDataAsync(); Assert.Equal(3, formData.Count); Assert.Equal("foo", formData["f"]); Assert.Equal("bar", formData["b"]); Assert.Equal("vdf", formData["format"]); handlerCalled = true; }; var response = await iface.PerformFooOperation2(args); Assert.True(handlerCalled); }