Exemple #1
0
        public void ConstructorInjectionTest()
        {
            var container  = new GeckoContainer();
            var injection0 = new Test1();
            var injection1 = new Test1();

            container.RegisterInstance(injection0).WithName("Test0");
            container.RegisterInstance(injection1).WithName("Test1");

            var actual = container.BuildUpType <Test2>();

            Assert.IsNotNull(actual);
            Assert.AreEqual(injection0, actual.Test0);
            Assert.AreEqual(injection1, actual.Test1);
        }
Exemple #2
0
        public void TestResolveNamedDependency()
        {
            var container = new GeckoContainer();
            var test1     = new Test1();
            var test2     = new Test1();

            container.RegisterInstance(test1).WithName("Test1");
            container.RegisterInstance(test2).WithName("test1");

            var testNamedDep = new TestNamedDep();

            container.BuildUp(testNamedDep);

            Assert.AreEqual(test1, testNamedDep.Test1);
            Assert.AreEqual(test2, testNamedDep.Test2);
        }
Exemple #3
0
        public void SetContextOnRegistryTest()
        {
            var container = new GeckoContainer();
            var context   = new ShandyGecko.ShandyGeckoDI.Context();

            container.RegisterInstance(new TestClass(), context);
            Assert.AreEqual(1, context.ContainerRegistries.Count);
        }
Exemple #4
0
        public void ContainerRegisterInstanceAsWrongInterfaceTest()
        {
            var container = new GeckoContainer();
            var testClass = new TestClass();

            Assert.Throws <ContainerException>(() =>
            {
                container.RegisterInstance(testClass).As <ITest3>();
            });
        }
Exemple #5
0
        public void MethodInjectionTest()
        {
            var container  = new GeckoContainer();
            var injection1 = new Test1();

            container.RegisterInstance(injection1);

            var actual = container.BuildUpType <Test2>();

            Assert.IsNotNull(actual);
            Assert.AreEqual(injection1, actual.Test1);
        }
Exemple #6
0
        public void TestInjectInInheritedConstructor()
        {
            var container = new GeckoContainer();
            var test1     = new Test1();

            container.RegisterInstance(test1);

            var child = container.BuildUpType <ChildTest>();

            Assert.IsNotNull(child);
            Assert.AreEqual(test1, child.Test1);
        }
Exemple #7
0
        public void TestResolveProtectedDependency()
        {
            var container = new GeckoContainer();
            var test1     = new Test1();

            container.RegisterInstance(test1);

            var test2 = new TestProtectedDep();

            container.BuildUp(test2);

            Assert.AreEqual(test1, test2.GetTestDep());
        }
Exemple #8
0
        public void TestResolveInheritedDependency()
        {
            var container = new GeckoContainer();
            var test      = new Test();

            container.RegisterInstance(test);

            var testChild = new TestChild();

            container.BuildUp(testChild);

            Assert.AreEqual(test, testChild.TestDep);
        }
Exemple #9
0
        public void TestResolveInternalDependency()
        {
            var container = new GeckoContainer();
            var test1     = new Test1();

            container.RegisterInstance(test1);

            var test2 = new TestInternalDep();

            container.BuildUp(test2);

            Assert.AreEqual(test1, test2.Test1);
        }
Exemple #10
0
        public void ContainerRegisterInstanceTest()
        {
            var container = new GeckoContainer();
            var testClass = new TestClass();

            container.RegisterInstance(testClass);

            Assert.IsTrue(container.IsKeyRegistered <TestClass>());

            var actual = container.Resolve <TestClass>();

            Assert.AreEqual(testClass, actual);
        }
Exemple #11
0
        public void ConstructorWithDependencyAttributeInjectionTest()
        {
            var container = new GeckoContainer();
            var injection = new Test1();

            container.RegisterInstance(injection);
            container.RegisterSingletone <Test2>();

            var actual = container.BuildUpType <Test3>();

            Assert.IsNotNull(actual);
            Assert.AreEqual(injection, actual.Test1);
            Assert.IsNotNull(actual.Test2);
        }
Exemple #12
0
        public void ConstructorParameterOverProviderInjection()
        {
            var container = new GeckoContainer();

            var test1Param    = new Test1();
            var test1Provider = new Test1();

            container.RegisterInstance(test1Provider);

            var test2 = container.BuildUpType <Test2>(new Parameter(test1Param));

            Assert.NotNull(test2);
            Assert.AreEqual(test1Param, test2.Test1);
            Assert.AreNotEqual(test1Provider, test2.Test1);
        }
Exemple #13
0
        public void ContainerRegisterInstanceAsMultipleInterfacesTest()
        {
            var container = new GeckoContainer();
            var testClass = new TestClass();

            container.RegisterInstance(testClass).As <ITest>().As <ITest2>();

            Assert.IsTrue(container.IsKeyRegistered <TestClass>());
            Assert.IsTrue(container.IsKeyRegistered <ITest>());
            Assert.IsTrue(container.IsKeyRegistered <ITest2>());

            var actual = container.Resolve <ITest2>();

            Assert.AreEqual(testClass, actual);
        }
Exemple #14
0
        public void ContainerRegisterInstanceWithNameAsInterfaceTest()
        {
            var container = new GeckoContainer();
            var testClass = new TestClass();

            container.RegisterInstance(testClass).WithName(TestName).As <ITest>();

            Assert.IsFalse(container.IsKeyRegistered <TestClass>());
            Assert.IsTrue(container.IsKeyRegistered <TestClass>(TestName));

            Assert.IsFalse(container.IsKeyRegistered <ITest>());
            Assert.IsTrue(container.IsKeyRegistered <ITest>(TestName));

            var actual = container.Resolve <ITest>(TestName);

            Assert.AreEqual(testClass, actual);
        }
Exemple #15
0
        public void ObjectsResolveTest()
        {
            var dummy = new Dummy();

            var container = new GeckoContainer();

            container.RegisterInstance(dummy);

            container.RegisterSingletone <Test1>();
            container.RegisterSingletone <Test2>();

            var test2Instance = container.Resolve <Test2>();

            Assert.NotNull(test2Instance);
            Assert.NotNull(test2Instance.Test1);
            Assert.NotNull(test2Instance.Test1.Dummy);
            Assert.AreEqual(dummy, test2Instance.Test1.Dummy);
        }