mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-26 08:12:49 +08:00

* #568 Ocelot wont start if QoSOptions specified and no QoS DelegatingHandler registered e.g. no use of Ocelot.Provider.Polly. Also adds a NoQosDelegatingHandler and logs an error if ive missed something and the user can get to making the request * #568 sadly something wierd with IServiceProvider and FluentValidation so I'm just defaulting to warning and noqosdelegatinghandler if someone doesnt register but provides options, also added basic in memory cache in case people dont use a specific package
70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
namespace Ocelot.UnitTests.Cache
|
|
{
|
|
using System;
|
|
using System.Threading;
|
|
using Ocelot.Cache;
|
|
using Shouldly;
|
|
using Xunit;
|
|
|
|
public class InMemoryCacheTests
|
|
{
|
|
private readonly InMemoryCache<Fake> _cache;
|
|
|
|
public InMemoryCacheTests()
|
|
{
|
|
_cache = new InMemoryCache<Fake>();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_cache()
|
|
{
|
|
var fake = new Fake(1);
|
|
_cache.Add("1", fake, TimeSpan.FromSeconds(100), "region");
|
|
var result = _cache.Get("1", "region");
|
|
result.ShouldBe(fake);
|
|
fake.Value.ShouldBe(1);
|
|
}
|
|
|
|
[Fact]
|
|
public void should_clear_region()
|
|
{
|
|
var fake = new Fake(1);
|
|
_cache.Add("1", fake, TimeSpan.FromSeconds(100), "region");
|
|
_cache.ClearRegion("region");
|
|
var result = _cache.Get("1", "region");
|
|
result.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_clear_key_if_ttl_expired()
|
|
{
|
|
var fake = new Fake(1);
|
|
_cache.Add("1", fake, TimeSpan.FromMilliseconds(50), "region");
|
|
Thread.Sleep(200);
|
|
var result = _cache.Get("1", "region");
|
|
result.ShouldBeNull();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(-1)]
|
|
public void should_not_add_to_cache_if_timespan_empty(int ttl)
|
|
{
|
|
var fake = new Fake(1);
|
|
_cache.Add("1", fake, TimeSpan.FromSeconds(ttl), "region");
|
|
var result = _cache.Get("1", "region");
|
|
result.ShouldBeNull();
|
|
}
|
|
|
|
class Fake
|
|
{
|
|
public Fake(int value)
|
|
{
|
|
Value = value;
|
|
}
|
|
|
|
public int Value { get; }
|
|
}
|
|
}
|
|
}
|