Esempio n. 1
0
        public void Cas_Should_Be_Called()
        {
            var validFor  = new TimeSpan(0, 0, 1);
            var expiresAt = new DateTime(3000, 1, 1);
            var cas       = new CasResult <object> {
                Cas = 1
            };

            // Test : CasResult<bool> Cas(StoreMode mode, string key, object value);
            // covered by 0L for cas

            // Test : CasResult<bool> Cas(StoreMode mode, string key, object value, ulong cas);
            var clientMock2 = new Mock <IMemcachedClient>();
            var service2    = new MemcachedServiceCache(clientMock2.Object);

            service2.Add(cas, "name", CacheItemPolicy.Infinite, "value");
            clientMock2.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", cas.Cas));
            //
            var clientMock2A = new Mock <IMemcachedClient>();
            var service2A    = new MemcachedServiceCache(clientMock2A.Object);

            service2A.Set(cas, "name", CacheItemPolicy.Infinite, "value");
            clientMock2A.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", cas.Cas));

            // Test : CasResult<bool> Cas(StoreMode mode, string key, object value, DateTime expiresAt, ulong cas);
            var clientMock3 = new Mock <IMemcachedClient>();
            var service3    = new MemcachedServiceCache(clientMock3.Object);

            service3.Add(cas, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock3.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", expiresAt, cas.Cas));
            //
            var clientMock3A = new Mock <IMemcachedClient>();
            var service3A    = new MemcachedServiceCache(clientMock3A.Object);

            service3A.Set(cas, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock3A.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", expiresAt, cas.Cas));

            // Test : CasResult<bool> Cas(StoreMode mode, string key, object value, TimeSpan validFor, ulong cas);
            var clientMock4 = new Mock <IMemcachedClient>();
            var service4    = new MemcachedServiceCache(clientMock4.Object);

            service4.Add(cas, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock4.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", validFor, cas.Cas));
            //
            var clientMock4A = new Mock <IMemcachedClient>();
            var service4A    = new MemcachedServiceCache(clientMock4A.Object);

            service4A.Set(cas, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock4A.Verify(x => x.Cas(It.IsAny <StoreMode>(), "name", "value", validFor, cas.Cas));
        }
Esempio n. 2
0
        public void Store_Should_Be_Called()
        {
            var validFor  = new TimeSpan(0, 0, 1);
            var expiresAt = new DateTime(3000, 1, 1);

            // Test : bool Store(StoreMode mode, string key, object value);
            var clientMock = new Mock <IMemcachedClient>();
            var service    = new MemcachedServiceCache(clientMock.Object);

            service.Add(null, "name", CacheItemPolicy.Infinite, "value");
            clientMock.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value"));
            //
            var clientMockA = new Mock <IMemcachedClient>();
            var serviceA    = new MemcachedServiceCache(clientMockA.Object);

            serviceA.Set(null, "name", CacheItemPolicy.Infinite, "value");
            clientMockA.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value"));

            // Test : bool Store(StoreMode mode, string key, object value, DateTime expiresAt);
            var clientMock2 = new Mock <IMemcachedClient>();
            var service2    = new MemcachedServiceCache(clientMock2.Object);

            service2.Add(null, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock2.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value", expiresAt));
            //
            var clientMock2A = new Mock <IMemcachedClient>();
            var service2A    = new MemcachedServiceCache(clientMock2A.Object);

            service2A.Set(null, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock2A.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value", expiresAt));

            // Test : bool Store(StoreMode mode, string key, object value, TimeSpan validFor);
            var clientMock3 = new Mock <IMemcachedClient>();
            var service3    = new MemcachedServiceCache(clientMock3.Object);

            service3.Add(null, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock3.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value", validFor));
            //
            var clientMock3A = new Mock <IMemcachedClient>();
            var service3A    = new MemcachedServiceCache(clientMock3A.Object);

            service3A.Set(null, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock3A.Verify(x => x.Store(It.IsAny <StoreMode>(), "name", "value", validFor));
        }
Esempio n. 3
0
        public void Prepend_Should_Be_Called()
        {
            var prepend    = new ArraySegment <byte>();
            var prependCas = new CasResult <ArraySegment <byte> > {
                Cas = 1, Result = prepend
            };

            // Test : bool Prepend(string key, ArraySegment<byte> data);
            var clientMock = new Mock <IMemcachedClient>();
            var service    = new MemcachedServiceCache(clientMock.Object); //, setTagMapperMock.Object);

            service.Set(prepend, "name", CacheItemPolicy.Infinite, "value");
            clientMock.Verify(x => x.Prepend("name", It.IsAny <ArraySegment <byte> >()));

            // Test : CasResult<bool> Prepend(string key, ulong cas, ArraySegment<byte> data);
            var clientMock2 = new Mock <IMemcachedClient>();
            var service2    = new MemcachedServiceCache(clientMock2.Object); //, setTagMapperMock.Object);

            service2.Set(prependCas, "name", CacheItemPolicy.Infinite, "value");
            clientMock2.Verify(x => x.Prepend("name", prependCas.Cas, It.IsAny <ArraySegment <byte> >()));
        }
Esempio n. 4
0
        public void Increment_Should_Be_Called()
        {
            var validFor  = new TimeSpan(0, 0, 1);
            var expiresAt = new DateTime(3000, 1, 1);
            var increment = new MemcachedServiceCache.IncrementTag {
                DefaultValue = 1, Delta = 2
            };
            var incrementCas = new CasResult <MemcachedServiceCache.IncrementTag> {
                Cas = 1, Result = increment
            };

            // Test : ulong Increment(string key, ulong defaultValue, ulong delta);
            var clientMock = new Mock <IMemcachedClient>();
            var service    = new MemcachedServiceCache(clientMock.Object);

            service.Set(increment, "name", CacheItemPolicy.Infinite, "value");
            clientMock.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta));

            // Test : ulong Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt);
            var clientMock2 = new Mock <IMemcachedClient>();
            var service2    = new MemcachedServiceCache(clientMock2.Object);

            service2.Set(increment, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock2.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta, expiresAt));

            // Test : ulong Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor);
            var clientMock3 = new Mock <IMemcachedClient>();
            var service3    = new MemcachedServiceCache(clientMock3.Object);

            service3.Set(increment, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock3.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta, validFor));

            // Test : CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, ulong cas);
            var clientMock4 = new Mock <IMemcachedClient>();
            var service4    = new MemcachedServiceCache(clientMock4.Object);

            service4.Set(incrementCas, "name", CacheItemPolicy.Infinite, "value");
            clientMock4.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta, incrementCas.Cas));

            // Test : CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas);
            var clientMock5 = new Mock <IMemcachedClient>();
            var service5    = new MemcachedServiceCache(clientMock5.Object);

            service5.Set(incrementCas, "name", new CacheItemPolicy {
                AbsoluteExpiration = expiresAt
            }, "value");
            clientMock5.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta, expiresAt, incrementCas.Cas));

            // Test : CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas);
            var clientMock6 = new Mock <IMemcachedClient>();
            var service6    = new MemcachedServiceCache(clientMock6.Object);

            service6.Set(incrementCas, "name", new CacheItemPolicy {
                SlidingExpiration = validFor
            }, "value");
            clientMock6.Verify(x => x.Increment("name", increment.DefaultValue, increment.Delta, validFor, incrementCas.Cas));
        }