PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/UnitTests/IOC/FactoryStorageTests.cs

http://github.com/philiplaureano/LinFu
C# | 50 lines | 38 code | 11 blank | 1 comment | 0 complexity | 17f12367966f2ca7ea0821832ac941cf MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using LinFu.IoC;
 4using LinFu.IoC.Interfaces;
 5using Moq;
 6using Xunit;
 7
 8namespace LinFu.UnitTests.IOC
 9{
10    public class FactoryStorageTests : BaseTestFixture
11    {
12        protected override void Init()
13        {
14            _storage = new FactoryStorage();
15        }
16
17        protected override void Term()
18        {
19            _storage = null;
20        }
21
22
23        private IFactoryStorage _storage;
24
25        [Fact]
26        public void ShouldDistinguishBetweenTwoServicesOfTheSameTypeButDifferentParameters()
27        {
28            var firstFactory = new Mock<IFactory>();
29            var secondFactory = new Mock<IFactory>();
30
31            var serviceType = typeof(int);
32
33            IEnumerable<Type> firstParameters = new[] {typeof(int), typeof(int)};
34            IEnumerable<Type> secondParameters = new[] {typeof(int), typeof(int), typeof(int), typeof(int)};
35
36            _storage.AddFactory("", serviceType, firstParameters, firstFactory.Object);
37            _storage.AddFactory("", serviceType, secondParameters, secondFactory.Object);
38
39            Assert.True(_storage.ContainsFactory("", serviceType, firstParameters));
40            Assert.True(_storage.ContainsFactory("", serviceType, secondParameters));
41
42            // Make sure that the factory returns the correct container
43            var firstResult = _storage.GetFactory("", serviceType, firstParameters);
44            Assert.Same(firstFactory.Object, firstResult);
45
46            var secondResult = _storage.GetFactory("", serviceType, secondParameters);
47            Assert.Same(secondFactory.Object, secondResult);
48        }
49    }
50}