#289 fix for issue where I was not preserving original query string when more than one query with same name (#290)

This commit is contained in:
Tom Pallister
2018-03-20 20:48:30 +00:00
committed by GitHub
parent b51df71d7b
commit 7e43af0126
3 changed files with 139 additions and 7 deletions

View File

@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.QueryStrings
public class AddQueriesToRequestTests
{
private readonly AddQueriesToRequest _addQueriesToRequest;
private readonly HttpRequestMessage _downstreamRequest;
private HttpRequestMessage _downstreamRequest;
private readonly Mock<IClaimsParser> _parser;
private List<ClaimToThing> _configuration;
private List<Claim> _claims;
@ -53,6 +53,34 @@ namespace Ocelot.UnitTests.QueryStrings
.BDDfy();
}
[Fact]
public void should_add_new_queries_to_downstream_request_and_preserve_other_queries()
{
var claims = new List<Claim>
{
new Claim("test", "data")
};
this.Given(
x => x.GivenAClaimToThing(new List<ClaimToThing>
{
new ClaimToThing("query-key", "", "", 0)
}))
.Given(x => x.GivenClaims(claims))
.And(x => GivenTheDownstreamRequestHasQueryString("?test=1&test=2"))
.And(x => x.GivenTheClaimParserReturns(new OkResponse<string>("value")))
.When(x => x.WhenIAddQueriesToTheRequest())
.Then(x => x.ThenTheResultIsSuccess())
.And(x => x.ThenTheQueryIsAdded())
.And(x => TheTheQueryStringIs("?test=1&test=2&query-key=value"))
.BDDfy();
}
private void TheTheQueryStringIs(string expected)
{
_downstreamRequest.RequestUri.Query.ShouldBe(expected);
}
[Fact]
public void should_replace_existing_queries_on_downstream_request()
{
@ -110,6 +138,11 @@ namespace Ocelot.UnitTests.QueryStrings
_claims = claims;
}
private void GivenTheDownstreamRequestHasQueryString(string queryString)
{
_downstreamRequest = new HttpRequestMessage(HttpMethod.Post, $"http://my.url/abc{queryString}");
}
private void GivenTheDownstreamRequestHasQueryString(string key, string value)
{
var newUri = Microsoft.AspNetCore.WebUtilities.QueryHelpers