Ejemplo n.º 1
0
        public void GetClearsCacheAppropriately(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.Get(dummyType, dummyInstance);
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }
Ejemplo n.º 2
0
        public void GetReturnsCorrectResult()
        {
            // Fixture setup
            var dummyLease = new Mock <ILease>().Object;

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

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

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

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
        public void GetClearsCacheAppropriately(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.Get(dummyType, dummyInstance);
            // Verify outcome
            cacheMock.Verify(c => c.DisposeAndClear(), Times.Exactly(clearCount));
            // Teardown
        }
        public void GetReturnsCorrectResult()
        {
            // Fixture setup
            var dummyLease = new Mock<ILease>().Object;

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

            var sut = new LeasedObjectCache(dummyLease, cacheStub.Object);
            // Exercise system
            var result = sut.Get(anonymousType, anonymousInstance);
            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }