public void Single_generic_SerializingCacheProvider_should_not_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(object); string key = "some key"; SerializingCacheProvider <StubSerialized> serializingCacheProvider = new SerializingCacheProvider <StubSerialized>(stubCacheProvider.For <StubSerialized>(), stubSerializer); serializingCacheProvider.Put(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1))); serializeInvoked.Should().Be(false); stubCacheProvider.Get(key).Should().BeNull(); }
public void Single_generic_SerializingCacheProvider_from_extension_syntax_should_not_deserialize_on_get_when_item_not_in_cache() { bool deserializeInvoked = false; StubSerializer <object, StubSerialized> stubSerializer = new StubSerializer <object, StubSerialized>( serialize: o => new StubSerialized(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; stubCacheProvider.Get(key).Should().BeNull(); SerializingCacheProvider <StubSerialized> serializingCacheProvider = stubCacheProvider.For <StubSerialized>().WithSerializer(stubSerializer); object fromCache = serializingCacheProvider.Get(key); deserializeInvoked.Should().Be(false); fromCache.Should().Be(default(object)); }
public void Single_generic_SerializingCacheProvider_should_not_deserialize_on_get_when_item_not_in_cache() { bool deserializeInvoked = false; StubSerializer <object, StubSerialized> stubSerializer = new StubSerializer <object, StubSerialized>( serialize: o => new StubSerialized(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; stubCacheProvider.TryGet(key).Item1.Should().BeFalse(); SerializingCacheProvider <StubSerialized> serializingCacheProvider = new SerializingCacheProvider <StubSerialized>(stubCacheProvider.For <StubSerialized>(), stubSerializer); (bool cacheHit, object fromCache) = serializingCacheProvider.TryGet(key); cacheHit.Should().BeFalse(); deserializeInvoked.Should().BeFalse(); fromCache.Should().Be(default);
public void Single_generic_SerializingCacheProvider_from_extension_syntax_should_serialize_on_put() { 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 = new object(); string key = "some key"; SerializingCacheProvider <StubSerialized> serializingCacheProvider = stubCacheProvider.For <StubSerialized>().WithSerializer(stubSerializer); serializingCacheProvider.Put(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1))); serializeInvoked.Should().Be(true); stubCacheProvider.Get(key).Should().BeOfType <StubSerialized>() .Which.Original.Should().Be(objectToCache); }
public void Single_generic_SerializingCacheProvider_from_extension_syntax_should_deserialize_on_get() { bool deserializeInvoked = false; StubSerializer <object, StubSerialized> stubSerializer = new StubSerializer <object, StubSerialized>( serialize: o => new StubSerialized(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); string key = "some key"; stubCacheProvider.Put(key, new StubSerialized(objectToCache), new Ttl(TimeSpan.FromMinutes(1))); SerializingCacheProvider <StubSerialized> serializingCacheProvider = stubCacheProvider.For <StubSerialized>().WithSerializer(stubSerializer); object fromCache = serializingCacheProvider.Get(key); deserializeInvoked.Should().Be(true); fromCache.Should().Be(objectToCache); }
public void 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"; SerializingCacheProvider <StubSerialized> serializingCacheProvider = new SerializingCacheProvider <StubSerialized>(stubCacheProvider.For <StubSerialized>(), stubSerializer); serializingCacheProvider.Put(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1))); serializeInvoked.Should().BeTrue(); (bool cacheHit, object fromCache) = stubCacheProvider.TryGet(key); cacheHit.Should().BeTrue(); fromCache.Should().BeOfType <StubSerialized>() .Which.Original.Should().Be(objectToCache); }
public void Double_generic_SerializingCacheProvider_from_extension_syntax_should_deserialize_on_get() { bool deserializeInvoked = false; StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> > stubTResultSerializer = new StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> >( serialize: o => new StubSerialized <ResultPrimitive>(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; string key = "some key"; SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = stubCacheProvider.For <StubSerialized <ResultPrimitive> >().WithSerializer(stubTResultSerializer); stubCacheProvider.Put(key, new StubSerialized <ResultPrimitive>(objectToCache), new Ttl(TimeSpan.FromMinutes(1))); ResultPrimitive fromCache = serializingCacheProvider.Get(key); deserializeInvoked.Should().Be(true); fromCache.Should().Be(objectToCache); }
public void 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"; SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = new SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> >(stubCacheProvider.For <StubSerialized <ResultPrimitive> >(), stubTResultSerializer); serializingCacheProvider.Put(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1))); serializeInvoked.Should().Be(true); stubCacheProvider.Get(key).Should().BeOfType <StubSerialized <ResultPrimitive> >() .Which.Original.Should().Be(objectToCache); }
public void Double_generic_SerializingCacheProvider_from_extension_syntax_should_not_deserialize_on_get_when_item_not_in_cache() { bool deserializeInvoked = false; StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> > stubTResultSerializer = new StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> >( serialize: o => new StubSerialized <ResultPrimitive>(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; stubCacheProvider.TryGet(key).Item2.Should().BeNull(); SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = stubCacheProvider.For <StubSerialized <ResultPrimitive> >().WithSerializer(stubTResultSerializer); (bool cacheHit, ResultPrimitive fromCache) = serializingCacheProvider.TryGet(key); cacheHit.Should().BeFalse(); deserializeInvoked.Should().BeFalse(); fromCache.Should().Be(default(ResultPrimitive)); }
public void Double_generic_SerializingCacheProvider_from_extension_syntax_should_serialize_on_put_for_defaultTResult() { 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 ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = default(ResultPrimitive); string key = "some key"; SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = stubCacheProvider.For <StubSerialized <ResultPrimitive> >().WithSerializer(stubTResultSerializer); serializingCacheProvider.Put(key, objectToCache, new Ttl(TimeSpan.FromMinutes(1))); serializeInvoked.Should().BeTrue(); (bool cacheHit, object fromCache) = stubCacheProvider.TryGet(key); cacheHit.Should().BeTrue(); fromCache.Should().BeOfType <StubSerialized <ResultPrimitive> >() .Which.Original.Should().Be(objectToCache); }
public void Double_generic_SerializingCacheProvider_should_not_deserialize_on_get_when_item_not_in_cache() { bool deserializeInvoked = false; StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> > stubTResultSerializer = new StubSerializer <ResultPrimitive, StubSerialized <ResultPrimitive> >( serialize: o => new StubSerialized <ResultPrimitive>(o), deserialize: s => { deserializeInvoked = true; return(s.Original); } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; stubCacheProvider.Get(key).Should().BeNull(); SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> > serializingCacheProvider = new SerializingCacheProvider <ResultPrimitive, StubSerialized <ResultPrimitive> >(stubCacheProvider.For <StubSerialized <ResultPrimitive> >(), stubTResultSerializer); ResultPrimitive fromCache = serializingCacheProvider.Get(key); deserializeInvoked.Should().Be(false); fromCache.Should().Be(default(ResultPrimitive)); }