PageRenderTime 66ms CodeModel.GetById 61ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/src/UnitTests/Proxy/LazyObjectTests.cs

http://github.com/philiplaureano/LinFu
C# | 38 lines | 31 code | 5 blank | 2 comment | 0 complexity | 8014e5c894b7fa601a1f8b9b218a838d MD5 | raw file
 1using System.Reflection;
 2using LinFu.IoC;
 3using LinFu.IoC.Configuration;
 4using LinFu.IoC.Configuration.Interfaces;
 5using LinFu.IoC.Interceptors;
 6using LinFu.Proxy;
 7using LinFu.Proxy.Interfaces;
 8using Xunit;
 9using SampleLibrary;
10using SampleLibrary.IOC;
11
12namespace LinFu.UnitTests.Proxy
13{
14    public class LazyObjectTests : BaseTestFixture
15    {
16        [Fact]
17        public void LazyObjectShouldNeverBeInitialized()
18        {
19            var container = new ServiceContainer();
20            container.AddService<IProxyFactory>(new ProxyFactory());
21            container.AddService<IMethodBuilder<MethodInfo>>(new MethodBuilder());
22
23            Assert.True(container.Contains(typeof(IProxyFactory)));
24
25            var proxyFactory = container.GetService<IProxyFactory>();
26            var interceptor = new LazyInterceptor<ISampleService>(() => new SampleLazyService());
27
28            SampleLazyService.Reset();
29            // The instance should be uninitialized at this point
30            var proxy = proxyFactory.CreateProxy<ISampleService>(interceptor);
31            Assert.False(SampleLazyService.IsInitialized);
32
33            // The instance should be initialized once the method is called
34            proxy.DoSomething();
35            Assert.True(SampleLazyService.IsInitialized);
36        }
37    }
38}