mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 01:58:15 +08:00
Fix/issue666 (#889)
* cache key now can generate from query string for request with Get Methods and request content for requests with post methods * MD5Helper Added. OutputCacheMiddleware now can generate cache key using method, url and content * unit test created for CacheKeyGenerator * CacheKeyGenerator Registered in OcelotBuilder as singletone
This commit is contained in:
34
test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs
Normal file
34
test/Ocelot.UnitTests/Cache/CacheKeyGeneratorTests.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Cache;
|
||||
using Ocelot.Middleware;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Cache {
|
||||
public class CacheKeyGeneratorTests {
|
||||
private readonly ICacheKeyGenerator _cacheKeyGenerator;
|
||||
private readonly DownstreamContext _downstreamContext;
|
||||
|
||||
public CacheKeyGeneratorTests() {
|
||||
_cacheKeyGenerator = new CacheKeyGenerator();
|
||||
_cacheKeyGenerator = new CacheKeyGenerator();
|
||||
_downstreamContext = new DownstreamContext(new DefaultHttpContext()) {
|
||||
DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123"))
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_generate_cache_key_from_context() {
|
||||
this.Given(x => x.GivenCacheKeyFromContext(_downstreamContext))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenCacheKeyFromContext(DownstreamContext context) {
|
||||
string generatedCacheKey = _cacheKeyGenerator.GenerateRequestCacheKey(context);
|
||||
string cachekey = MD5Helper.GenerateMd5("GET-https://some.url/blah?abcd=123");
|
||||
generatedCacheKey.ShouldBe(cachekey);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user