Beispiel #1
0
        public void RegisterTypeMapping_K_IType_Test4()
        {
            ActivatingServiceLocator ASLocator  = new ActivatingServiceLocator();
            ActivatingServiceLocator ASLocator2 = ASLocator.RegisterTypeMapping(typeof(IInterface1), typeof(FirstClass1)
                                                                                , "Key1", InstantiationType.AsSingleton);


            Assert.IsNotNull(ASLocator2, "RegisterTypeMapping method returned null");
            Assert.AreEqual(ASLocator2.GetType().ToString(), ASLocator.GetType().ToString(), "Return type does not match ActivatingServiceLocator");
            Assert.IsTrue(ASLocator2.IsTypeRegistered <IInterface1>(), "Failed to register the type");
            object FirstClass1Object = ASLocator.GetInstance(typeof(IInterface1), "Key1");

            Assert.AreEqual(FirstClass1Object.GetType().Name, "FirstClass1");

            //Singleton instance check.
            object FirstClass1Object2 = ASLocator.GetInstance(typeof(IInterface1), "Key1");

            Assert.AreEqual(FirstClass1Object, FirstClass1Object2);

            //reregistration checking for Singleton.
            ASLocator.RegisterTypeMapping(typeof(IInterface1), typeof(FirstClass1), "Key1", InstantiationType.AsSingleton);
            object FirstClass1Object3 = ASLocator.GetInstance(typeof(IInterface1), "Key1");

            Assert.AreEqual(FirstClass1Object, FirstClass1Object3);
        }
Beispiel #2
0
        public void RegisterTypeMapping_Test1()
        {
            ActivatingServiceLocator ASLocator  = new ActivatingServiceLocator();
            ActivatingServiceLocator ASLocator2 = ASLocator.RegisterTypeMapping(typeof(IInterface1), typeof(FirstClass1));

            Assert.IsNotNull(ASLocator2, "RegisterTypeMapping method returned null");
            Assert.AreEqual(ASLocator2.GetType().ToString(), ASLocator.GetType().ToString(), "Return type does not match ActivatingServiceLocator");
            Assert.IsTrue(ASLocator2.IsTypeRegistered <IInterface1>(), "Failed to register the type");
            object FirstClass1Object = ASLocator.GetInstance(typeof(IInterface1));

            Assert.AreEqual(FirstClass1Object.GetType().Name, "FirstClass1");
        }
Beispiel #3
0
        public void RegisterTypeMapping_From_To_ITypeTestKey1()
        {
            ActivatingServiceLocator ASLocator  = new ActivatingServiceLocator();
            ActivatingServiceLocator ASLocator2 = ASLocator.RegisterTypeMapping <IInterface1, FirstClass1>("Key1", InstantiationType.NewInstanceForEachRequest);

            Assert.IsNotNull(ASLocator2, "RegisterTypeMapping method returned null");
            Assert.AreEqual(ASLocator2.GetType().ToString(), ASLocator.GetType().ToString(), "Return type does not match ActivatingServiceLocator");
            Assert.IsTrue(ASLocator2.IsTypeRegistered <IInterface1>(), "Failed to register the type");
            object FirstClass1Object = ASLocator.GetInstance(typeof(IInterface1), "Key1");

            Assert.AreEqual(FirstClass1Object.GetType().Name, "FirstClass1");

            //Code to check for new instance. Objects should be different instances of same class, not a singleton.
            object FirstClass1Object2 = ASLocator.GetInstance(typeof(IInterface1), "Key1");

            Assert.AreNotEqual(FirstClass1Object, FirstClass1Object2);
        }