public void Clear_Test()
        {
            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, "thesessionkey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true);

            var poco = new Poco {
                Name = "jeff"
            };

            session.Set("Clear_Test", poco);

            Assert.NotEmpty(session.Keys);

            session.Clear();

            Assert.Empty(session.Keys);
        }
        public void Remove_Success()
        {
            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, "thesessionkey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true);

            var poco = new Poco {
                Name = "jeff"
            };

            session.Set("remove_success", poco);
            Assert.Contains("remove_success", session.Keys.Cast <string>());

            session.Remove("remove_success");
            Assert.DoesNotContain("remove_success", session.Keys.Cast <string>());
        }
        public void TryGetValue_When_ByteArray_Return_ByteArray()
        {
            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, "thesessionkey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true);

            var poco = ConvertToBytes(new Poco {
                Name = "jeff"
            });

            session.Set("Set_Tests", poco);

            byte[] actual;
            var    result = session.TryGetValue("Set_Tests", out actual);

            Assert.True(result);
            Assert.Same(poco, actual);
        }
        public void GetValue_WhenPoco_Success()
        {
            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, "thesessionkey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true);

            session.Set("thekeyforpoco", new Poco {
                Name = "jeff"
            });

            var result = session.Get("thekeyforpoco");

            Assert.Equal(ConvertToBytes(new Poco {
                Name = "jeff"
            }), result);
        }
        public void TryGetValueOfT_Poco_Success()
        {
            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, "thesessionkey", new TimeSpan(0, 0, 10, 0), () => true, new LoggerFactory(), true);

            var poco = new Poco {
                Name = "jeff"
            };

            session.Set("thekey", poco);

            Poco value;
            var  result = session.TryGetValue("thekey", out value);

            Assert.True(result);
            Assert.Same(poco, value);
        }
        public void SetOfT_Test()
        {
            var op = new Mock <IOperationResult <Dictionary <string, byte[]> > >(); //value is null

            var bucket = new Mock <IBucket>();

            bucket.Setup(x => x.GetAsync <Dictionary <string, byte[]> >(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, "thesessionkey", new TimeSpan(0, 0, 10, 0), TimeSpan.Zero, () => true, new LoggerFactory(), true);

            var poco = new Poco {
                Name = "jeff"
            };

            session.Set("SetOfT_Tests", poco);

            Poco actual;
            var  result = session.TryGetValue("SetOfT_Tests", out actual);

            Assert.True(result);
            Assert.Equal(poco.Name, actual.Name);
        }
        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 void TryGetValue_When_NotFound_Return_Null()
        {
            var op = new Mock <IOperationResult <Dictionary <string, byte[]> > >(); //value is null

            var bucket = new Mock <IBucket>();

            bucket.Setup(x => x.GetAsync <Dictionary <string, byte[]> >(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, "thesessionkey", new TimeSpan(0, 0, 10, 0), TimeSpan.Zero, () => true, new LoggerFactory(), true);

            byte[] actual;
            var    result = session.TryGetValue("Set_Tests", out actual);

            Assert.False(result);
            Assert.Same(null, actual);
        }
        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);
        }
Пример #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="session">The current user session</param>
 /// <param name="allowBookmark">Whether or not to allow bookmarking</param>
 /// <param name="bookmarkedHotels">A list of already bookmarked hotels</param>
 public HotelListViewModelParameter(CouchbaseSession session, bool allowBookmark, Hotels bookmarkedHotels)
 {
     Session          = session;
     AllowBookmark    = allowBookmark;
     BookmarkedHotels = bookmarkedHotels;
 }