Ejemplo n.º 1
0
        public void MyIocContainerShouldNotRegisterTheSameInterfaceTwice()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            Assert.Throws <System.Exception>(() => ioc.Register <ISimpleService, SimpleWorker>());
        }
Ejemplo n.º 2
0
 public void MyIocContainerShouldResolveNestedDependencies()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     ioc.Register<IComplexService, ComplexWorker>();
     var complexWorker = ioc.Resolve(typeof(IComplexService));
     Assert.AreEqual(typeof(ComplexWorker), complexWorker.GetType());
     Assert.AreEqual(typeof(SimpleWorker), (complexWorker as ComplexWorker).NestedSimpleService.GetType());
 }
Ejemplo n.º 3
0
        public void MyIocContainerShouldResolveNestedDependencies()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            ioc.Register <IComplexService, ComplexWorker>();
            var complexWorker = ioc.Resolve(typeof(IComplexService));

            Assert.AreEqual(typeof(ComplexWorker), complexWorker.GetType());
            Assert.AreEqual(typeof(SimpleWorker), (complexWorker as ComplexWorker).NestedSimpleService.GetType());
        }
Ejemplo n.º 4
0
 public void MyIocContainerShouldResolveADependency()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     var worker = ioc.Resolve(typeof(ISimpleService));
     Assert.AreEqual(typeof(SimpleWorker), worker.GetType());
 }
Ejemplo n.º 5
0
 public void MyIocContainerShouldReturnTheSameInstanceOfSingletonTypes()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>(LifeCycleTypes.SINGLETON);
     var worker0 = ioc.Resolve(typeof(ISimpleService));
     var worker1 = ioc.Resolve(typeof(ISimpleService));
     Assert.AreEqual(worker0, worker1);
 }
Ejemplo n.º 6
0
 public void MyIocContainerShouldReturnNewInstancesOfTransientTypes()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     var worker0 = ioc.Resolve(typeof(ISimpleService));
     var worker1 = ioc.Resolve(typeof(ISimpleService));
     Assert.AreNotEqual(worker0, worker1);
 }
Ejemplo n.º 7
0
        public void MyIocContainerShouldResolveADependency()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            var worker = ioc.Resolve(typeof(ISimpleService));

            Assert.AreEqual(typeof(SimpleWorker), worker.GetType());
        }
Ejemplo n.º 8
0
        public void MyIocContainerShouldReturnTheSameInstanceOfSingletonTypes()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>(LifeCycleTypes.SINGLETON);
            var worker0 = ioc.Resolve(typeof(ISimpleService));
            var worker1 = ioc.Resolve(typeof(ISimpleService));

            Assert.AreEqual(worker0, worker1);
        }
Ejemplo n.º 9
0
        public void MyIocContainerShouldReturnNewInstancesOfTransientTypes()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            var worker0 = ioc.Resolve(typeof(ISimpleService));
            var worker1 = ioc.Resolve(typeof(ISimpleService));

            Assert.AreNotEqual(worker0, worker1);
        }
Ejemplo n.º 10
0
        public void MyIocContainerShouldRegisterADependency()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
        }
Ejemplo n.º 11
0
 public void MyIocContainerShouldNotRegisterTheSameInterfaceTwice()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     Assert.Throws<System.Exception>(() => ioc.Register<ISimpleService, SimpleWorker>());
 }
Ejemplo n.º 12
0
 public void MyIocContainerShouldRegisterADependency()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
 }