public SubstituteParamsInRequest ( |
||
requestData | ||
리턴 | SevenDigital.Api.Wrapper.Requests.ApiRequest |
public void Should_return_data() { var requestData = new RequestData { HttpMethod = HttpMethod.Get, Endpoint = "testpath", }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result, Is.Not.Null); Assert.That(result.AbsoluteUrl, Is.Not.Empty); Assert.That(result.Parameters, Is.Not.Null); }
public void Should_substitue_route_parameters() { var requestData = new RequestData { Endpoint = "something/{route}", Parameters = new Dictionary<string, string> { {"route","routevalue"} } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.AbsoluteUrl, Is.StringContaining("something/routevalue")); }
public void Should_substitue_multiple_route_parameters() { var requestData = new RequestData { Endpoint = "something/{firstRoute}/{secondRoute}/thrid/{thirdRoute}", Parameters = new Dictionary<string, string> { {"firstRoute" , "firstValue"}, {"secondRoute","secondValue"}, {"thirdRoute" , "thirdValue"} } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.AbsoluteUrl, Is.StringContaining("something/firstvalue/secondvalue/thrid/thirdvalue")); }
public Request BuildRequest(RequestData requestData) { var apiRequest = _routeParamsSubstitutor.SubstituteParamsInRequest(requestData); var fullUrl = apiRequest.AbsoluteUrl; var headers = new Dictionary <string, string>(requestData.Headers); var oauthHeader = GetAuthorizationHeader(requestData, fullUrl, apiRequest); headers.Add("Authorization", oauthHeader); headers.Add("Accept", requestData.Accept); if (requestData.HttpMethod.HasParamsInQueryString() && (apiRequest.Parameters.Count > 0)) { fullUrl += "?" + apiRequest.Parameters.ToQueryString(); } var requestBody = CheckForRequestPayload(requestData, apiRequest.Parameters); return(new Request(requestData.HttpMethod, fullUrl, headers, requestBody)); }
public void Routes_should_be_case_insensitive() { var requestData = new RequestData { Endpoint = "something/{firstRoUte}/{secOndrouTe}/thrid/{tHirdRoute}", Parameters = new Dictionary<string, string> { {"firstRoute" , "firstValue"}, {"secondRoute","secondValue"}, {"thirdRoute" , "thirdValue"} } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.AbsoluteUrl, Is.StringContaining("something/firstvalue/secondvalue/thrid/thirdvalue")); }
public void Should_remove_multiple_parameters_that_match() { var requestData = new RequestData { Endpoint = "something/{firstRoute}/{secondRoute}/thrid/{thirdRoute}", Parameters = new Dictionary<string, string> { {"firstRoute" , "firstValue"}, {"secondRoute","secondValue"}, {"thirdRoute" , "thirdValue"}, {"foo","bar"}, } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.Parameters.ContainsKey("firstRoute"), Is.False); Assert.That(result.Parameters.ContainsKey("secondRoute"), Is.False); Assert.That(result.Parameters.ContainsKey("thirdRoute"), Is.False); Assert.That(result.Parameters.ContainsKey("foo"), Is.True); }
public void Should_remove_parameters_that_match() { var requestData = new RequestData { Endpoint = "something/{route}", Parameters = new Dictionary<string, string> { {"route","routevalue"}, {"foo","bar"} } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.Parameters.ContainsKey("route"), Is.False); Assert.That(result.Parameters.ContainsKey("foo"), Is.True); }
public void Domain_should_be_case_insensitive_routes_should_be_case_sensitive() { var requestData = new RequestData { Endpoint = "someThing/{firstRoUte}/{secOndrouTe}/third/{tHirdRoute}", Parameters = new Dictionary<string, string> { {"firstRoute" , "firstValue"}, {"secondRoute","secondValue"}, {"thirdRoute" , "thirdValue"} } }; var routeParamsSubstitutor = new RouteParamsSubstitutor(_apiUri); var result = routeParamsSubstitutor.SubstituteParamsInRequest(requestData); Assert.That(result.AbsoluteUrl, Is.EqualTo("http://example.com/someThing/firstValue/secondValue/third/thirdValue")); }