Esempio n. 1
0
        public void TestNullInstance()
        {
            var container = new NDOContainer();

            container.RegisterInstance <ICar>(null);
            Assert.IsNull(container.Resolve <ICar>());
        }
Esempio n. 2
0
        public void OverwriteInstanceRegWithTypeReg()
        {
            var container = new NDOContainer();

            container.RegisterInstance <ICar>(new Ford());
            container.RegisterType <ICar, BMW>();
            Assert.IsTrue(container.Resolve <ICar>() is BMW);
        }
Esempio n. 3
0
        public void IsRegisteredWorks()
        {
            var container = new NDOContainer();

            Assert.AreEqual(false, container.IsRegistered <ICar>());
            container.RegisterInstance <ICar>(null);
            Assert.AreEqual(true, container.IsRegistered <ICar>());
        }
Esempio n. 4
0
        public void ResolveTypeWithInstanceDependency()
        {
            var container = new NDOContainer();

            container.RegisterInstance <ICar>(new BMW());
            var drv = container.Resolve <Driver>();

            Assert.NotNull(drv);
        }
Esempio n. 5
0
        public void RegisterInstanceWithName()
        {
            INDOContainer container = new NDOContainer();

            var bmw1 = new BMW();

            container.RegisterInstance <ICar>(bmw1, "bmw");
            var audi1 = new Audi();

            container.RegisterInstance <ICar>(audi1, "audi");

            var bmw2 = container.Resolve <ICar>("bmw");

            Assert.AreSame(bmw1, bmw2);
            var audi2 = container.Resolve <ICar>("audi");

            Assert.AreSame(audi1, audi2);
        }
Esempio n. 6
0
        public void RegisterInstance()
        {
            INDOContainer container = new NDOContainer();

            var car1 = new BMW();

            container.RegisterInstance <ICar>(car1);

            var car2 = container.Resolve <ICar>();

            Assert.AreSame(car1, car2);
        }
Esempio n. 7
0
        public void ResolveWithParameterInParentContainer()
        {
            var container1 = new NDOContainer();

            container1.RegisterType <Driver>();
            var container2 = container1.CreateChildContainer();

            container2.RegisterInstance <ICar>(new BMW());
            var drv = container2.Resolve <Driver>();

            Assert.NotNull(drv);
            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());

            container1 = new NDOContainer();
            container1.RegisterInstance <ICar>(new BMW());
            container2 = container1.CreateChildContainer();
            container2.RegisterType <Driver>();
            drv = container2.Resolve <Driver>();
            Assert.NotNull(drv);
            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());
        }
Esempio n. 8
0
        public void ResolveInstanceWithChildContainer()
        {
            INDOContainer container1 = new NDOContainer();

            container1.RegisterInstance <ICar>(new BMW());

            var car1 = container1.Resolve <ICar>();


            var container2 = container1.CreateChildContainer();
            var car2       = container2.Resolve <ICar>();

            Assert.AreSame(car1, car2);

            container2.RegisterInstance <ICar>(new BMW());
            car2 = container2.Resolve <ICar>();

            Assert.AreNotSame(car1, car2);

            container2.Dispose();

            car2 = container1.Resolve <ICar>();
            Assert.AreSame(car1, car2);
        }