コード例 #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));
        }
コード例 #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));
        }
コード例 #3
0
        public void Append_Should_Be_Called()
        {
            var append    = new ArraySegment <byte>();
            var appendCas = new CasResult <ArraySegment <byte> > {
                Cas = 1, Result = append
            };

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

            service.Add(append, "name", CacheItemPolicy.Infinite, "value");
            clientMock.Verify(x => x.Append("name", It.IsAny <ArraySegment <byte> >()));

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

            service2.Add(appendCas, "name", CacheItemPolicy.Infinite, "value");
            clientMock2.Verify(x => x.Append("name", appendCas.Cas, It.IsAny <ArraySegment <byte> >()));
        }