예제 #1
0
        public void HoldInstanceWithNull()
        {
            // Setup
            var lifespan = new CacheLifespan();

            // Execute
            lifespan.Hold(a_instance: null);
        }
예제 #2
0
        public void ConstructCacheLifespanWithTimespan()
        {
            // Setup
            var timeout = TimeSpan.FromMinutes(1);

            // Execute
            var lifespan = new CacheLifespan(timeout);

            // Assert
            Assert.AreEqual(timeout, lifespan.Timeout);
        }
예제 #3
0
        public void HoldInstance()
        {
            // Setup
            var lifespan = new CacheLifespan();
            var instance = new object();

            // Execute
            lifespan.Hold(instance);

            // Assert
            Assert.AreSame(instance, lifespan.Instance);
        }
예제 #4
0
        public void KillInstanceWithNoInstanceHeld()
        {
            // Setup
            var lifespan = new CacheLifespan();
            var instance = new object();
            lifespan.Hold(instance);

            // Execute
            lifespan.Kill();

            // Assert
            Assert.IsNull(lifespan.Instance);
        }
예제 #5
0
        public void ResolveServiceTwiceWithCacheLifespan()
        {
            // Setup
            var lifespan = new CacheLifespan(TimeSpan.FromMinutes(5));
            var container = new Container();
            var service = new Service(container, typeof(ServiceWithDefaultConstructor), typeof(ServiceBase), a_lifespan: lifespan);

            // Execute
            var serviceInstance1 = service.Resolve();
            var serviceInstance2 = service.Resolve();

            // Assert
            Assert.AreSame(serviceInstance1, serviceInstance2);
        }
예제 #6
0
        public async Task WaitPastTimeout()
        {
            // Setup
            var lifespan = new CacheLifespan(TimeSpan.FromMilliseconds(500));
            var instance = new object();
            lifespan.Hold(instance);

            // Execute
            await Task.Delay(1000);

            // Assert
            Assert.IsNull(lifespan.Instance);
        }