Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void DefaultConstructorTest()
        {
            var container = new GeckoContainer();

            container.RegisterSingletone <Test1>();

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

            Assert.IsNotNull(actual);
        }
Exemplo n.º 4
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>();
            });
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }