PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 58ms app.codeStats 0ms

/src/UnitTests/IOC/Configuration/InitializerTests.cs

http://github.com/philiplaureano/LinFu
C# | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | bb2675267863fbb6f2b197638fc5d6f6 MD5 | raw file
 1using System;
 2using LinFu.IoC;
 3using LinFu.IoC.Configuration;
 4using LinFu.IoC.Interfaces;
 5using Xunit;
 6
 7namespace LinFu.UnitTests.IOC.Configuration
 8{
 9    public class InitializerTests
10    {
11        public class InitializableObject : IInitialize
12        {
13            public bool InitializeCalled { get; set; }
14
15
16            public void Initialize(IServiceContainer source)
17            {
18                InitializeCalled = true;
19            }
20        }
21
22        public class TestServiceContainer : ServiceContainer
23        {
24            public TestServiceContainer()
25            {
26                this.AddService(typeof(InitializableObject), typeof(InitializableObject));
27            }
28        }
29
30        [Fact]
31        public void InitializerDoesNotHoldRerenceToInitializedObjects()
32        {
33            var container = new TestServiceContainer();
34
35            var initializable = container.GetService<InitializableObject>();
36            Assert.True(initializable.InitializeCalled);
37            var weakRef = new WeakReference(initializable);
38            Assert.True(weakRef.IsAlive);
39
40            initializable = null;
41            GC.Collect(0, GCCollectionMode.Forced);
42            Assert.False(weakRef.IsAlive);
43        }
44    }
45}