PageRenderTime 151ms CodeModel.GetById 60ms app.highlight 2ms RepoModel.GetById 88ms app.codeStats 0ms

/src/UnitTests/IOC/MethodInjectionTests.cs

http://github.com/philiplaureano/LinFu
C# | 32 lines | 24 code | 5 blank | 3 comment | 0 complexity | 430472b82859cfd8d7e97fbf318c18b6 MD5 | raw file
 1using System;
 2using LinFu.IoC;
 3using Xunit;
 4using SampleLibrary;
 5using SampleLibrary.IOC;
 6
 7namespace LinFu.UnitTests.IOC
 8{
 9    public class MethodInjectionTests : BaseTestFixture
10    {
11        [Fact]
12        public void ShouldAutoInjectMethod()
13        {
14            var container = new ServiceContainer();
15            container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "LinFu*.dll");
16
17            var instance = new SampleClassWithInjectionMethod();
18
19            // Initialize the container
20            container.Inject<ISampleService>().Using<SampleClass>().OncePerRequest();
21            container.Inject<ISampleService>("MyService").Using(c => instance).OncePerRequest();
22
23            var result = container.GetService<ISampleService>("MyService");
24            Assert.Same(result, instance);
25
26            // On initialization, the instance.Property value
27            // should be a SampleClass type
28            Assert.NotNull(instance.Property);
29            Assert.Equal(typeof(SampleClass), instance.Property?.GetType());
30        }
31    }
32}