mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:10:50 +08:00 
			
		
		
		
	#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:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user