コード例 #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);
        }
コード例 #2
0
        public void IsTypeRegistered_Test2()
        {
            TypeMapping TMapping = new TypeMapping(typeof(IInterface1), typeof(SecondClass1), "Key1");

            ActivatingServiceLocator ASLocator = new ActivatingServiceLocator();

            ASLocator.RegisterTypeMapping(TMapping);

            Assert.IsFalse(ASLocator.IsTypeRegistered <IInterface1>(), "IsTypeRegistered returned true for an invalid TypeMapping Registration input. Should be verified");
        }
コード例 #3
0
        public void IsTypeRegistered_Test1()
        {
            TypeMapping TMapping = new TypeMapping(typeof(IInterface1), typeof(FirstClass1), "Key1");

            ActivatingServiceLocator ASLocator = new ActivatingServiceLocator();

            ASLocator.RegisterTypeMapping(TMapping);

            Assert.IsTrue(ASLocator.IsTypeRegistered <IInterface1>(), "IsTypeRegistered returned false for a valid TypeMapping Registration. Should be verified");
        }
コード例 #4
0
        public void IsTypeRegistered_WithoutRegisteredService_returnsFalse()
        {
            //Arrange
            ActivatingServiceLocator locator = new ActivatingServiceLocator();

            //Act
            locator.RegisterTypeMapping(typeof(IMyObject2), typeof(MyObject3));
            bool target = locator.IsTypeRegistered(typeof(IMyObject));

            //Assert
            Assert.IsFalse(target);
        }
コード例 #5
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");
        }
コード例 #6
0
        public void IsTypeRegistered_WithKeyAndRegisteredService_returnsTrue()
        {
            //Arrange
            ActivatingServiceLocator locator = new ActivatingServiceLocator();
            string key = "foobar";

            //Act
            locator.RegisterTypeMapping(typeof(IMyObject2), typeof(MyObject3), key, InstantiationType.NewInstanceForEachRequest);
            bool target = locator.IsTypeRegistered(typeof(IMyObject2), key);

            //Assert
            Assert.IsTrue(target);
        }
コード例 #7
0
        public void CanLoadTypeMappings()
        {
            var target = new ActivatingServiceLocatorFactory();

            List <TypeMapping> typeMappings = new List <TypeMapping>();

            typeMappings.Add(TypeMapping.Create <ISomething, Something>());

            var serviceLocator = new ActivatingServiceLocator();

            target.LoadTypeMappings(serviceLocator, typeMappings);

            Assert.IsTrue(serviceLocator.IsTypeRegistered <ISomething>());
        }
コード例 #8
0
        public void ServiceLocatorIsLoadedWithTypes()
        {
            var typeMappings = new List <TypeMapping>
            {
                TypeMapping.Create <ISomething, Something>("key")
            };

            SetupConfigToReturnTypeMappings(typeMappings);

            Assert.IsInstanceOfType(SharePointServiceLocator.Current, typeof(ActivatingServiceLocator));

            ActivatingServiceLocator target = SharePointServiceLocator.Current as ActivatingServiceLocator;

            Assert.IsTrue(target.IsTypeRegistered <ISomething>());
        }
コード例 #9
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);
        }
        public void LoadTypeMappings2_Test()
        {
            ActivatingServiceLocatorFactory factory = new ActivatingServiceLocatorFactory();
            IServiceLocator servicelocator          = factory.Create();

            List <TypeMapping> typeMappings = new List <TypeMapping>();

            typeMappings.Add(new TypeMapping(typeof(IInterface1), typeof(FirstClass1), null));

            factory.LoadTypeMappings(servicelocator, typeMappings);
            ActivatingServiceLocator AserviceLoc = servicelocator as ActivatingServiceLocator;

            Assert.IsTrue(AserviceLoc.IsTypeRegistered <IInterface1>(), "Failed to register the type");
            object FirstClass1Object = AserviceLoc.GetInstance(typeof(IInterface1));

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