コード例 #1
0
        public void HoldInstanceWithNull()
        {
            // Setup
            var lifespan = new CacheLifespan();

            // Execute
            lifespan.Hold(a_instance: null);
        }
コード例 #2
0
        public void HoldInstance()
        {
            // Setup
            var lifespan = new CacheLifespan();
            var instance = new object();

            // Execute
            lifespan.Hold(instance);

            // Assert
            Assert.AreSame(instance, lifespan.Instance);
        }
コード例 #3
0
        public void KillInstanceWithNoInstanceHeld()
        {
            // Setup
            var lifespan = new CacheLifespan();
            var instance = new object();
            lifespan.Hold(instance);

            // Execute
            lifespan.Kill();

            // Assert
            Assert.IsNull(lifespan.Instance);
        }
コード例 #4
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);
        }