Ejemplo n.º 1
0
        public void CanAddBinding()
        {
            // Act
            Container.AddConfig(new Config <ITest1, Test1>());
            Container.AddConfig(new Config <ITest2>(new Test2()));

            // Assert
            var test1 = Container.GetBinding <ITest1>();

            Assert.IsNotNull(test1);
            Assert.IsFalse(string.IsNullOrWhiteSpace(test1.TestString));
            Assert.IsNotNull(Container.GetBinding <ITest2>());
        }
Ejemplo n.º 2
0
        public void CanOverwriteConfig()
        {
            // Arrange
            Container.AddConfig(new Config <ITest1, Test1>());

            // Act
            Container.OverwriteConfig(new Config <ITest1, Test1A>());

            // Assert
            var test1 = Container.GetBinding <ITest1>();
            var expectedTestString = new Test1A().TestString;

            Assert.AreEqual(expectedTestString, test1.TestString);
        }
Ejemplo n.º 3
0
        public void CanChainAddBindings()
        {
            Container.AddConfig(new Config <ITest1, Test1>());
            Container.AddConfig(new Config <ITest2>(new Test2()));
            Container.AddConfig(new Config <ITest3, Test3>().AsSingleton());
            Container.AddConfig(new Config <ITest4>(new Test4()).AsSingleton());

            var test1 = Container.GetBinding <ITest1>();

            Assert.IsNotNull(test1);
            Assert.IsFalse(string.IsNullOrWhiteSpace(test1.TestString));
            Assert.IsNotNull(Container.GetBinding <ITest2>());
            Assert.IsNotNull(Container.GetBinding <ITest3>());
            Assert.IsNotNull(Container.GetBinding <ITest4>());
        }
Ejemplo n.º 4
0
        public void CanDetermineBetweenTwoImplementations()
        {
            // Arrange
            var configs = new List <IConfig>
            {
                new Config <ITest1, Test1>().WithName("Test1"),
                new Config <ITest1, Test1A>().WithName("asdf")
            };

            // Act
            Container.Initialize(configs);

            // Assert
            var test1  = Container.GetBinding <ITest1>("Test1");
            var test1A = Container.GetBinding <ITest1>("asdf");

            Assert.AreEqual("Hello World", test1.TestString);
            Assert.AreEqual("Hello World From Test1 A", test1A.TestString);
        }
Ejemplo n.º 5
0
        public void BindingDictionaryReturnsImplementationOfPassedInConfig()
        {
            // Arrange
            var configs = new List <IConfig>
            {
                new Config <ITest1, Test1>(),
                new Config <ITest2>(new Test2()),
                new Config <ITest3, Test3>().AsSingleton(),
                new Config <ITest4>(new Test4()).AsSingleton()
            };

            // Act
            Container.Initialize(configs);

            // Assert
            var test1 = Container.GetBinding <ITest1>();

            Assert.IsNotNull(test1);
            Assert.IsFalse(string.IsNullOrWhiteSpace(test1.TestString));
            Assert.IsNotNull(Container.GetBinding <ITest2>());
            Assert.IsNotNull(Container.GetBinding <ITest3>());
            Assert.IsNotNull(Container.GetBinding <ITest4>());
        }
Ejemplo n.º 6
0
        public void CanChangeInstanceOfInterfaceUsedDependingOnConfig()
        {
            // Arrange
            var configs = new List <IConfig>
            {
                new Config <ITest1, Test1>().WithName("Test1"),
                new Config <ITest1, Test1A>().WithName("asdf"),
                new SelfConfig(typeof(Test5))
                .ResolveConstructorArgumentUsing <Test1>("test1")
                .ResolveConstructorArgumentUsing <Test1A>("test1A"),
                new Config <ITest2, Test2>()
            };

            // Act
            Container.Initialize(configs);

            var test5 = Container.GetBinding <Test5>();

            // Assert
            Assert.IsInstanceOfType(test5.Test1, typeof(Test1));
            Assert.IsInstanceOfType(test5.Test1A, typeof(Test1A));
            Assert.IsNotNull(test5.Test2);
        }