public async Task LoadAsync_When_Cache_ThrowsException_BackingStore_Session_IsAvailable_False() { var bucket = new Mock <IBucket>(); bucket.Setup(x => x.GetAsync <Dictionary <string, object> >(It.IsAny <string>())) .Throws(new BucketNotFoundException()); var provider = new Mock <ICouchbaseCacheBucketProvider>(); provider.Setup(x => x.GetBucket()).Returns(bucket.Object); var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions()); var session = new CouchbaseSession(cache, "thekey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true); await session.LoadAsync(); Assert.False(session.IsAvailable); }
public async Task LoadAsync_When_Cache_DoesNotHave_BackingStore_Session_IsAvailable_True() { var op = new Mock <IOperationResult <Dictionary <string, object> > >(); //value is null var bucket = new Mock <IBucket>(); bucket.Setup(x => x.GetAsync <Dictionary <string, object> >(It.IsAny <string>())) .Returns(Task.FromResult(op.Object)); var provider = new Mock <ICouchbaseCacheBucketProvider>(); provider.Setup(x => x.GetBucket()).Returns(bucket.Object); var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions()); var session = new CouchbaseSession(cache, "thekey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true); await session.LoadAsync(); Assert.True(session.IsAvailable); }
public async Task LoadAsync_When_Cache_Has_BackingStore_Session_IsAvailable_True() { var op = new Mock <IOperationResult <Dictionary <string, byte[]> > >(); op.Setup(x => x.Value).Returns(new Dictionary <string, byte[]>()); var bucket = new Mock <IBucket>(); bucket.Setup(x => x.GetAndTouchAsync <Dictionary <string, byte[]> >(It.IsAny <string>(), It.IsAny <TimeSpan>())) .Returns(Task.FromResult(op.Object)); var provider = new Mock <ICouchbaseCacheBucketProvider>(); provider.Setup(x => x.GetBucket()).Returns(bucket.Object); var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions()); var session = new CouchbaseSession(cache, "thekey", new TimeSpan(0, 0, 10, 0), TimeSpan.Zero, () => true, new LoggerFactory(), true); await session.LoadAsync(CancellationToken.None); Assert.True(session.IsAvailable); }