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); }
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); }
public void SetContextOnRegistryTest() { var container = new GeckoContainer(); var context = new ShandyGecko.ShandyGeckoDI.Context(); container.RegisterInstance(new TestClass(), context); Assert.AreEqual(1, context.ContainerRegistries.Count); }
public void ContainerRegisterInstanceAsWrongInterfaceTest() { var container = new GeckoContainer(); var testClass = new TestClass(); Assert.Throws <ContainerException>(() => { container.RegisterInstance(testClass).As <ITest3>(); }); }
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); }
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); }
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()); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }