/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
- using System.Reflection;
- using LinFu.IoC;
- using LinFu.IoC.Configuration;
- using LinFu.IoC.Configuration.Interfaces;
- using LinFu.IoC.Interceptors;
- using LinFu.Proxy;
- using LinFu.Proxy.Interfaces;
- using Xunit;
- using SampleLibrary;
- using SampleLibrary.IOC;
- namespace LinFu.UnitTests.Proxy
- {
- public class LazyObjectTests : BaseTestFixture
- {
- [Fact]
- public void LazyObjectShouldNeverBeInitialized()
- {
- var container = new ServiceContainer();
- container.AddService<IProxyFactory>(new ProxyFactory());
- container.AddService<IMethodBuilder<MethodInfo>>(new MethodBuilder());
- Assert.True(container.Contains(typeof(IProxyFactory)));
- var proxyFactory = container.GetService<IProxyFactory>();
- var interceptor = new LazyInterceptor<ISampleService>(() => new SampleLazyService());
- SampleLazyService.Reset();
- // The instance should be uninitialized at this point
- var proxy = proxyFactory.CreateProxy<ISampleService>(interceptor);
- Assert.False(SampleLazyService.IsInitialized);
- // The instance should be initialized once the method is called
- proxy.DoSomething();
- Assert.True(SampleLazyService.IsInitialized);
- }
- }
- }