public async Task Single_generic_SerializingCacheProvider_should_serialize_on_put_for_defaultTResult() { bool serializeInvoked = false; StubSerializer <object, StubSerialized> stubSerializer = new StubSerializer <object, StubSerialized>( serialize: o => { serializeInvoked = true; return(new StubSerialized(o)); }, deserialize: s => s.Original ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object objectToCache = default; string key = "some key"; AsyncSerializingCacheProvider <StubSerialized> serializingCacheProvider = new AsyncSerializingCacheProvider <StubSerialized>(stubCacheProvider.AsyncFor <StubSerialized>(), stubSerializer); await serializingCacheProvider.PutAsync(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false); serializeInvoked.Should().BeTrue(); (bool cacheHit, object fromCache) = stubCacheProvider.TryGet(key); cacheHit.Should().BeTrue(); fromCache.Should().BeOfType <StubSerialized>() .Which.Original.Should().Be(objectToCache); }
public async Task Double_generic_SerializingCacheProvider_should_serialize_on_put() { bool serializeInvoked = false; StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> > stubTResultSerializer = new StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> >( serialize: o => { serializeInvoked = true; return(new StubSerialized <ResultPrimitive>(o)); }, deserialize: s => s.Original ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; string key = "some key"; AsyncSerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = new AsyncSerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> >(stubCacheProvider.AsyncFor <StubSerialized <ResultPrimitive> >(), stubTResultSerializer); await serializingCacheProvider.PutAsync(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false); serializeInvoked.Should().BeTrue(); (bool cacheHit, object fromCache) = await stubCacheProvider.TryGetAsync(key, CancellationToken.None, false); cacheHit.Should().BeTrue(); fromCache.Should().BeOfType <StubSerialized <ResultPrimitive> >() .Which.Original.Should().Be(objectToCache); }