Exemple #1
0
 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromNinjectContainer()
 {
     var serviceLocator = new ServiceLocator();
     var standardKernel = new StandardKernel();
     serviceLocator.RegisterExternalContainer(standardKernel);
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.AreNotSame(standardKernel.Get<ITestInterface>(), standardKernel.Get<ITestInterface>());
 }
Exemple #2
0
 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToTrueFromWindsorContainer()
 {
     var serviceLocator = new ServiceLocator();
     var windsorContainer = new WindsorContainer();
     serviceLocator.RegisterExternalContainer(windsorContainer);
     serviceLocator.RegisterType<ITestInterface, TestClass1>();
     Assert.AreSame(windsorContainer.Resolve<ITestInterface>(), windsorContainer.Resolve<ITestInterface>());
 }
Exemple #3
0
 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromUnityContainer()
 {
     var serviceLocator = new ServiceLocator();
     var unityContainer = new UnityContainer();
     serviceLocator.RegisterExternalContainer(unityContainer);
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.AreNotSame(unityContainer.Resolve<ITestInterface>(), unityContainer.Resolve<ITestInterface>());
 }
Exemple #4
0
            public void ExportsBothInstancesAndTypes()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;

                var ninjectContainer = new StandardKernel();

                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.RegisterInstance<ITestInterface>(new TestClass1());
                serviceLocator.RegisterType<INotifyPropertyChanged, TestClass1>();

                serviceLocator.RegisterExternalContainer(ninjectContainer);

                Assert.IsFalse(ninjectContainer.GetBindings(typeof(INotifyPropertyChanged)).Any());
                Assert.IsFalse(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());

                serviceLocator.ExportToExternalContainers();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(INotifyPropertyChanged)).Any());
                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());
            }
Exemple #5
0
            public void ExportInstancesToExternalContainers_ExternalContainerHasNoInstanceRegistered()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;

                var ninjectContainer = new StandardKernel();

                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.RegisterInstance<ITestInterface>(new TestClass1());

                serviceLocator.RegisterExternalContainer(ninjectContainer);

                Assert.IsFalse(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());

                serviceLocator.ExportInstancesToExternalContainers();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());
            }
Exemple #6
0
            public void ResolvesSameInstanceFromBothContainers()
            {
                var unityContainer = new UnityContainer();

                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = true;
                serviceLocator.RegisterExternalContainer(unityContainer);

                serviceLocator.RegisterTypeIfNotYetRegistered<IMessageService, MessageService>();

                var ns1 = unityContainer.Resolve<IMessageService>();
                var ns2 = serviceLocator.ResolveType<IMessageService>();

                Assert.AreEqual(ns1, ns2);
            }
Exemple #7
0
            public void AutomaticSynchronization_ResolveType()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;
                serviceLocator.RegisterType<ITestInterface, TestClass1>();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.AutomaticallyKeepContainersSynchronized = true;
                serviceLocator.ResolveType<ITestInterface>();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
            }
Exemple #8
0
            public void AutomaticSynchronization_RegisterIfTypeNotYetRegistered()
            {
                var serviceLocator = new ServiceLocator();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.RegisterTypeIfNotYetRegistered<ITestInterface, TestClass1>();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
            }
Exemple #9
0
            public void AutomaticSynchronization_RegisterInstance()
            {
                var serviceLocator = new ServiceLocator();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.RegisterInstance<ITestInterface>(new TestClass1());

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
            }
Exemple #10
0
            public void RegisterExternalContainer_ValidContainerAndTestTypeRetrieval()
            {
                var serviceLocator = new ServiceLocator();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                ninjectContainer.Bind<ITestInterface>().To<TestClass1>();

                Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface)));
            }
Exemple #11
0
 public void RegisterExternalContainer_ExternalContainerNull()
 {
     var serviceLocator = new ServiceLocator();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serviceLocator.RegisterExternalContainer(null));
 }
Exemple #12
0
            public void ResolveType_RegisteredInExternalContainer()
            {
                var serviceLocator = new ServiceLocator();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                ninjectContainer.Bind<ITestInterface>().To<TestClass1>();

                var instance = serviceLocator.ResolveType<ITestInterface>();
                Assert.IsInstanceOfType(instance, typeof(TestClass1));
            }