Beispiel #1
0
        public void SetObjectParameterWithType()
        {
            var container = new GeckoContainer();
            var dummy     = new Dummy();

            container.RegisterSingletone <Test>().SetParameter(new Parameter(dummy, typeof(IDummy)));
            var instance = container.Resolve <Test>();

            Assert.AreEqual(dummy, instance.Dummy);
        }
Beispiel #2
0
        public void SetObjectParameterWithoutType()
        {
            var container = new GeckoContainer();
            var dummy     = new Dummy();

            container.RegisterSingletone <Test>().SetParameter(new Parameter(dummy));
            Assert.Throws <ContainerException>(() =>
            {
                container.Resolve <Test>();
            });
        }
Beispiel #3
0
        public void SetParameterWithoutNameTest()
        {
            var container = new GeckoContainer();

            container.RegisterSingletone <Test>().SetParameter(new Parameter(Parameter1));

            var instance = container.Resolve <Test>("", new Parameter(Parameter2));

            Assert.AreEqual(Parameter1, instance.Parameter1);
            Assert.AreEqual(Parameter2, instance.Parameter2);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }