public CacheLifecycle(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.cache = new LeasedObjectCache(lease);
        }
Example #2
0
        public CacheLifecycle(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.cache = new LeasedObjectCache(lease);
        }
 public void SutIsObjectCache()
 {
     // Fixture setup
     var dummyLease = new Mock<ILease>().Object;
     // Exercise system
     var sut = new LeasedObjectCache(dummyLease);
     // Verify outcome
     Assert.IsAssignableFrom<IObjectCache>(sut);
     // Teardown
 }
 public void LeaseIsCorrectWhenInitializedWithMinimalConstructor()
 {
     // Fixture setup
     var expectedLease = new Mock<ILease>().Object;
     var sut = new LeasedObjectCache(expectedLease);
     // Exercise system
     ILease result = sut.Lease;
     // Verify outcome
     Assert.Equal(expectedLease, result);
     // Teardown
 }
Example #5
0
        public void SutIsObjectCache()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;
            // Exercise system
            var sut = new LeasedObjectCache(dummyLease);

            // Verify outcome
            Assert.IsAssignableFrom <IObjectCache>(sut);
            // Teardown
        }
Example #6
0
        public void ObjectCacheIsCorrectWhenInitializedWithMinimalConstructor()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;
            var sut        = new LeasedObjectCache(dummyLease);
            // Exercise system
            IObjectCache result = sut.ObjectCache;

            // Verify outcome
            Assert.IsAssignableFrom <MainObjectCache>(result);
            // Teardown
        }
Example #7
0
        public void LeaseIsCorrectWhenInitializedWithMinimalConstructor()
        {
            // Fixture setup
            var expectedLease = new Mock <ILease>().Object;
            var sut           = new LeasedObjectCache(expectedLease);
            // Exercise system
            ILease result = sut.Lease;

            // Verify outcome
            Assert.Equal(expectedLease, result);
            // Teardown
        }
Example #8
0
        public void ObjectCacheIsCorrectWhenInitializedWithGreedyConstructor()
        {
            // Fixture setup
            var dummyLease    = new Mock <ILease>().Object;
            var expectedCache = new Mock <IObjectCache>().Object;
            var sut           = new LeasedObjectCache(dummyLease, expectedCache);
            // Exercise system
            var result = sut.ObjectCache;

            // Verify outcome
            Assert.Equal(expectedCache, result);
            // Teardown
        }
Example #9
0
        public void LockerIsStable()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;
            var dummyCache = new Mock <IObjectCache>().Object;
            var sut        = new LeasedObjectCache(dummyLease, dummyCache);
            var expected   = sut.Locker;
            // Exercise system
            var result = sut.Locker;

            // Verify outcome
            Assert.Same(expected, result);
            // Teardown
        }
Example #10
0
        public void LockerIsInstance()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;
            var dummyCache = new Mock <IObjectCache> {
                DefaultValue = DefaultValue.Mock
            }.Object;
            var sut = new LeasedObjectCache(dummyLease, dummyCache);
            // Exercise system
            var result = sut.Locker;

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
Example #11
0
        public void DisposeAndClearsDisposesAndClearsDecoratedCache()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;

            var cacheMock = new Mock <IObjectCache>();

            var sut = new LeasedObjectCache(dummyLease, cacheMock.Object);

            // Exercise system
            sut.DisposeAndClear();
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear());
            // Teardown
        }
Example #12
0
        public void CountClearsCacheAppropriately(bool isExpired, int clearCount)
        {
            // Fixture setup
            var leaseStub = new Mock <ILease>();

            leaseStub.SetupGet(l => l.IsExpired).Returns(isExpired);

            var cacheMock = new Mock <IObjectCache>();

            var sut = new LeasedObjectCache(leaseStub.Object, cacheMock.Object);
            // Exercise system
            var ignored = sut.Count;

            // Verify outcome
            cacheMock.Verify(l => l.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }
Example #13
0
        public void SetRenewsLease()
        {
            // Fixture setup
            var leaseMock  = new Mock <ILease>();
            var dummyCache = new Mock <IObjectCache>().Object;

            var sut = new LeasedObjectCache(leaseMock.Object, dummyCache);
            // Exercise system
            var anonymousType     = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var anonymousValue    = new object();

            sut.Set(anonymousType, anonymousInstance, anonymousValue);
            // Verify outcome
            leaseMock.Verify(l => l.Renew());
            // Teardown
        }
Example #14
0
        public void SetSetsOnDecoratedCache()
        {
            // Fixture setup
            var anonymousType     = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var anonymousValue    = new object();

            var dummyLease = new Mock <ILease>().Object;
            var cacheMock  = new Mock <IObjectCache>();

            var sut = new LeasedObjectCache(dummyLease, cacheMock.Object);

            // Exercise system
            sut.Set(anonymousType, anonymousInstance, anonymousValue);
            // Verify outcome
            cacheMock.Verify(c => c.Set(anonymousType, anonymousInstance, anonymousValue));
            // Teardown
        }
Example #15
0
        public void HasClearsCacheAppropriately(bool isExpired, int clearCount)
        {
            // Fixture setup
            var leaseStub = new Mock <ILease>();

            leaseStub.SetupGet(l => l.IsExpired).Returns(isExpired);

            var cacheMock = new Mock <IObjectCache>();

            var sut = new LeasedObjectCache(leaseStub.Object, cacheMock.Object);
            // Exercise system
            var dummyType     = typeof(object);
            var dummyInstance = new ConstructorInstance(dummyType);

            sut.Has(dummyType, dummyInstance);
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }
Example #16
0
        public void HasReturnsCorrectResult(bool expected)
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;

            var anonymousType     = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var cacheStub         = new Mock <IObjectCache>();

            cacheStub.Setup(c => c.Has(anonymousType, anonymousInstance)).Returns(expected);

            var sut = new LeasedObjectCache(dummyLease, cacheStub.Object);
            // Exercise system
            var result = sut.Has(anonymousType, anonymousInstance);

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
Example #17
0
        public void CountReturnsCorrectResult()
        {
            // Fixture setup
            var expectedCount = 9;

            var dummyLease = new Mock <ILease>().Object;

            var cacheStub = new Mock <IObjectCache>();

            cacheStub.SetupGet(c => c.Count).Returns(expectedCount);

            var sut = new LeasedObjectCache(dummyLease, cacheStub.Object);
            // Exercise system
            var result = sut.Count;

            // Verify outcome
            Assert.Equal(expectedCount, result);
            // Teardown
        }
 public void ObjectCacheIsCorrectWhenInitializedWithGreedyConstructor()
 {
     // Fixture setup
     var dummyLease = new Mock<ILease>().Object;
     var expectedCache = new Mock<IObjectCache>().Object;
     var sut = new LeasedObjectCache(dummyLease, expectedCache);
     // Exercise system
     var result = sut.ObjectCache;
     // Verify outcome
     Assert.Equal(expectedCache, result);
     // Teardown
 }
 public void ObjectCacheIsCorrectWhenInitializedWithMinimalConstructor()
 {
     // Fixture setup
     var dummyLease = new Mock<ILease>().Object;
     var sut = new LeasedObjectCache(dummyLease);
     // Exercise system
     IObjectCache result = sut.ObjectCache;
     // Verify outcome
     Assert.IsAssignableFrom<MainObjectCache>(result);
     // Teardown
 }
        public void SetSetsOnDecoratedCache()
        {
            // Fixture setup
            var anonymousType = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var anonymousValue = new object();

            var dummyLease = new Mock<ILease>().Object;
            var cacheMock = new Mock<IObjectCache>();

            var sut = new LeasedObjectCache(dummyLease, cacheMock.Object);
            // Exercise system
            sut.Set(anonymousType, anonymousInstance, anonymousValue);
            // Verify outcome
            cacheMock.Verify(c => c.Set(anonymousType, anonymousInstance, anonymousValue));
            // Teardown
        }
        public void SetRenewsLease()
        {
            // Fixture setup
            var leaseMock = new Mock<ILease>();
            var dummyCache = new Mock<IObjectCache>().Object;

            var sut = new LeasedObjectCache(leaseMock.Object, dummyCache);
            // Exercise system
            var anonymousType = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var anonymousValue = new object();
            sut.Set(anonymousType, anonymousInstance, anonymousValue);
            // Verify outcome
            leaseMock.Verify(l => l.Renew());
            // Teardown
        }
 public void LockerIsStable()
 {
     // Fixture setup
     var dummyLease = new Mock<ILease>().Object;
     var dummyCache = new Mock<IObjectCache>().Object;
     var sut = new LeasedObjectCache(dummyLease, dummyCache);
     var expected = sut.Locker;
     // Exercise system
     var result = sut.Locker;
     // Verify outcome
     Assert.Same(expected, result);
     // Teardown
 }
 public void LockerIsInstance()
 {
     // Fixture setup
     var dummyLease = new Mock<ILease>().Object;
     var dummyCache = new Mock<IObjectCache> { DefaultValue = DefaultValue.Mock }.Object;
     var sut = new LeasedObjectCache(dummyLease, dummyCache);
     // Exercise system
     var result = sut.Locker;
     // Verify outcome
     Assert.NotNull(result);
     // Teardown
 }
        public void HasClearsCacheAppropriately(bool isExpired, int clearCount)
        {
            // Fixture setup
            var leaseStub = new Mock<ILease>();
            leaseStub.SetupGet(l => l.IsExpired).Returns(isExpired);

            var cacheMock = new Mock<IObjectCache>();

            var sut = new LeasedObjectCache(leaseStub.Object, cacheMock.Object);
            // Exercise system
            var dummyType = typeof(object);
            var dummyInstance = new ConstructorInstance(dummyType);
            sut.Has(dummyType, dummyInstance);
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }
        public void HasReturnsCorrectResult(bool expected)
        {
            // Fixture setup
            var dummyLease = new Mock<ILease>().Object;

            var anonymousType = typeof(object);
            var anonymousInstance = new ConstructorInstance(anonymousType);
            var cacheStub = new Mock<IObjectCache>();
            cacheStub.Setup(c => c.Has(anonymousType, anonymousInstance)).Returns(expected);

            var sut = new LeasedObjectCache(dummyLease, cacheStub.Object);
            // Exercise system
            var result = sut.Has(anonymousType, anonymousInstance);
            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
        public void DisposeAndClearsDisposesAndClearsDecoratedCache()
        {
            // Fixture setup
            var dummyLease = new Mock<ILease>().Object;

            var cacheMock = new Mock<IObjectCache>();

            var sut = new LeasedObjectCache(dummyLease, cacheMock.Object);
            // Exercise system
            sut.DisposeAndClear();
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear());
            // Teardown
        }
        public void CountReturnsCorrectResult()
        {
            // Fixture setup
            var expectedCount = 9;

            var dummyLease = new Mock<ILease>().Object;

            var cacheStub = new Mock<IObjectCache>();
            cacheStub.SetupGet(c => c.Count).Returns(expectedCount);

            var sut = new LeasedObjectCache(dummyLease, cacheStub.Object);
            // Exercise system
            var result = sut.Count;
            // Verify outcome
            Assert.Equal(expectedCount, result);
            // Teardown
        }
        public void CountClearsCacheAppropriately(bool isExpired, int clearCount)
        {
            // Fixture setup
            var leaseStub = new Mock<ILease>();
            leaseStub.SetupGet(l => l.IsExpired).Returns(isExpired);

            var cacheMock = new Mock<IObjectCache>();

            var sut = new LeasedObjectCache(leaseStub.Object, cacheMock.Object);
            // Exercise system
            var ignored = sut.Count;
            // Verify outcome
            cacheMock.Verify(l => l.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }