示例#1
0
        public void ResolveWillReturnNewInstanceWhenLeaseExpires()
        {
            // Fixture setup
            var kernel    = new DefaultKernel();
            var model     = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var expired   = false;
            var leaseStub = new Mock <ILease> {
                DefaultValue = DefaultValue.Mock
            };

            leaseStub.Setup(l => l.IsExpired).Returns(() =>
            {
                var b   = expired;
                expired = !expired;
                return(b);
            });
            kernel.Register(Component.For <ILease>().Instance(leaseStub.Object));

            var sut = new CacheLifestyleManager();

            sut.Init(activator, kernel, model);
            // Exercise system
            var first  = sut.Resolve(CreationContext.Empty);
            var second = sut.Resolve(CreationContext.Empty);

            // Verify outcome
            Assert.NotSame(first, second);
            // Teardown
        }
示例#2
0
        public void ReleaseWrongObjectWillNotReleaseInstance()
        {
            // Fixture setup
            var kernel    = new DefaultKernel();
            var model     = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var leaseMock = new Mock <ILease> {
                DefaultValue = DefaultValue.Mock
            };

            kernel.Register(Component.For <ILease>().Instance(leaseMock.Object));

            var sut = new CacheLifestyleManager();

            sut.Init(activator, kernel, model);

            var first = sut.Resolve(CreationContext.Empty);

            // Exercise system
            sut.Release(new object());
            // Verify outcome
            var second = sut.Resolve(CreationContext.Empty);

            Assert.Same(first, second);
            // Teardown
        }
示例#3
0
        public void ResolveTwiceReturnsSame()
        {
            // Fixture setup
            var kernel    = new DefaultKernel();
            var model     = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var sut = new CacheLifestyleManager();

            sut.Init(activator, kernel, model);
            // Exercise system
            var first  = sut.Resolve(CreationContext.Empty);
            var second = sut.Resolve(CreationContext.Empty);

            // Verify outcome
            Assert.Same(first, second);
            // Teardown
        }
示例#4
0
        public void MultipleResolvesWillOnlyRenewOnce()
        {
            // Fixture setup
            var kernel    = new DefaultKernel();
            var model     = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var leaseMock = new Mock <ILease> {
                DefaultValue = DefaultValue.Mock
            };

            kernel.Register(Component.For <ILease>().Instance(leaseMock.Object));

            var sut = new CacheLifestyleManager();

            sut.Init(activator, kernel, model);
            // Exercise system
            sut.Resolve(CreationContext.Empty);
            sut.Resolve(CreationContext.Empty);
            // Verify outcome
            leaseMock.Verify(l => l.Renew(), Times.Once());
            // Teardown
        }
示例#5
0
        public void ResolveOnceReturnsCorrectResult()
        {
            // Fixture setup
            var kernel    = new DefaultKernel();
            var model     = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var sut = new CacheLifestyleManager();

            sut.Init(activator, kernel, model);
            // Exercise system
            var result = sut.Resolve(CreationContext.Empty);

            // Verify outcome
            Assert.IsAssignableFrom <Version>(result);
            // Teardown
        }
        public void ResolveOnceReturnsCorrectResult()
        {
            // Fixture setup
            var kernel = new DefaultKernel();
            var model = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var sut = new CacheLifestyleManager();
            sut.Init(activator, kernel, model);
            // Exercise system
            var result = sut.Resolve(CreationContext.Empty);
            // Verify outcome
            Assert.IsAssignableFrom<Version>(result);
            // Teardown
        }
        public void ReleaseWrongObjectWillNotReleaseInstance()
        {
            // Fixture setup
            var kernel = new DefaultKernel();
            var model = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var leaseMock = new Mock<ILease> { DefaultValue = DefaultValue.Mock };
            kernel.Register(Component.For<ILease>().Instance(leaseMock.Object));

            var sut = new CacheLifestyleManager();
            sut.Init(activator, kernel, model);

            var first = sut.Resolve(CreationContext.Empty);
            // Exercise system
            sut.Release(new object());
            // Verify outcome
            var second = sut.Resolve(CreationContext.Empty);
            Assert.Same(first, second);
            // Teardown
        }
        public void ResolveWillReturnNewInstanceWhenLeaseExpires()
        {
            // Fixture setup
            var kernel = new DefaultKernel();
            var model = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var expired = false;
            var leaseStub = new Mock<ILease> { DefaultValue = DefaultValue.Mock };
            leaseStub.Setup(l => l.IsExpired).Returns(() =>
                {
                    var b = expired;
                    expired = !expired;
                    return b;
                });
            kernel.Register(Component.For<ILease>().Instance(leaseStub.Object));

            var sut = new CacheLifestyleManager();
            sut.Init(activator, kernel, model);
            // Exercise system
            var first = sut.Resolve(CreationContext.Empty);
            var second = sut.Resolve(CreationContext.Empty);
            // Verify outcome
            Assert.NotSame(first, second);
            // Teardown
        }
        public void MultipleResolvesWillOnlyRenewOnce()
        {
            // Fixture setup
            var kernel = new DefaultKernel();
            var model = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var leaseMock = new Mock<ILease> { DefaultValue = DefaultValue.Mock };
            kernel.Register(Component.For<ILease>().Instance(leaseMock.Object));

            var sut = new CacheLifestyleManager();
            sut.Init(activator, kernel, model);
            // Exercise system
            sut.Resolve(CreationContext.Empty);
            sut.Resolve(CreationContext.Empty);
            // Verify outcome
            leaseMock.Verify(l => l.Renew(), Times.Once());
            // Teardown
        }
        public void ResolveTwiceReturnsSame()
        {
            // Fixture setup
            var kernel = new DefaultKernel();
            var model = new ComponentModel("foo", typeof(ICloneable), typeof(Version));
            var activator = kernel.CreateComponentActivator(model);

            var sut = new CacheLifestyleManager();
            sut.Init(activator, kernel, model);
            // Exercise system
            var first = sut.Resolve(CreationContext.Empty);
            var second = sut.Resolve(CreationContext.Empty);
            // Verify outcome
            Assert.Same(first, second);
            // Teardown
        }