コード例 #1
0
        public void SerLocConfigRegisterTypeMappingTestHelper()
        {
            int beforeCount;
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            actual      = new List <TypeMapping>(target.GetTypeMappings());
            beforeCount = actual.Count;
            target.RegisterTypeMapping <IConfig, ConfigTest>();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            Assert.AreEqual(beforeCount + 1, actual.Count);
        }
コード例 #2
0
        public void SerLocConfigRemoveTypeMappings()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IConfig, ConfigTest>();
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            target.RemoveTypeMappings <IConfig>();
            SharePointServiceLocator.Reset();
            Assert.AreEqual(actual.Count - 1, target.GetTypeMappings().Count());
        }
コード例 #3
0
        public void CanGetTypeMappings()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();

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

            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "1"
            });
            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "2"
            });
            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "3"
            });

            hierarchicalConfig.Value = typeMappings;

            var target = new ServiceLocatorConfig(hierarchicalConfig);
            IEnumerable <TypeMapping> registeredTypeMappings = target.GetTypeMappings();

            Assert.AreEqual(3, registeredTypeMappings.Count());
        }
コード例 #4
0
        public void CanRemoveTypeMapping()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();

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

            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "1"
            });
            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "2"
            });
            typeMappings.Add(new TypeMapping()
            {
                FromAssembly = "3"
            });

            hierarchicalConfig.Value = new List <TypeMapping>(typeMappings);

            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RemoveTypeMapping(typeMappings[0]);
            IEnumerable <TypeMapping> registeredTypeMappings = target.GetTypeMappings();

            Assert.AreEqual(2, registeredTypeMappings.Count());
            Assert.AreSame(typeMappings[1], registeredTypeMappings.First());
            Assert.AreSame(typeMappings[2], registeredTypeMappings.ElementAt(1));
        }
コード例 #5
0
        public void TheServiceLocatorFromCommonServiceLocatorThrowsClearErrorMessage()
        {
            Isolate.WhenCalled(() => SPFarm.Local).WillReturn(Isolate.Fake.Instance <SPFarm>());
            ServiceLocatorConfig fakeConfig = Isolate.Fake.Instance <ServiceLocatorConfig>();

            Isolate.Swap.NextInstance <ServiceLocatorConfig>().With(fakeConfig);
            Isolate.WhenCalled(() => fakeConfig.GetTypeMappings()).WillReturn(null);
            SharePointServiceLocator.Reset();
            var sl = SharePointServiceLocator.Current;

            try
            {
                var sl1 = ServiceLocator.Current;
                Assert.Fail();
            }
            catch (NotSupportedException ex)
            {
                Assert.AreEqual(ex.Message,
                                "ServiceLocator.Current is not supported. Use SharePointServiceLocator.Current instead.");
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
コード例 #6
0
        public void RemoveTypeMappingsGeneric_RemoveAMapping()
        {
            //Arrange
            var typeMappings = new List <TypeMapping> {
                TypeMapping.Create <ILogger, SharePointLogger>(),
                TypeMapping.Create <IConfigManager, ConfigManager>(),
                TypeMapping.Create <IHierarchicalConfig, HierarchicalConfig>()
            };

            var config = new ServiceLocationConfigData(typeMappings);
            var bag    = new BIPropertyBag();

            BSPFarm.SetLocal();
            var cfgMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) => true,
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => bag,
            };

            cfgMgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, propetyBag) => config);
            cfgMgr.BehaveAsDefaultValue();

            //Act
            var target = new ServiceLocatorConfig(cfgMgr);

            target.RemoveTypeMappings <ILogger>();
            List <TypeMapping> registeredTypeMappings =
                target.GetTypeMappings().ToList();

            //Assert
            Assert.AreEqual(2, registeredTypeMappings.Count);
            Assert.AreSame(typeMappings[1], registeredTypeMappings[0]);
            Assert.AreSame(typeMappings[2], registeredTypeMappings[1]);
        }
コード例 #7
0
        public void SerLocConfigGetTypeMappingsTest()
        {
            ServiceLocatorConfig target = new ServiceLocatorConfig();
            List <TypeMapping>   actual;

            actual = new List <TypeMapping>(target.GetTypeMappings());
            Assert.IsTrue(actual.Count > 0);
        }
コード例 #8
0
        public void SerLocConfigRegisterTypeMappingOverwritekey()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();
            int beforeCount;

            target.RegisterTypeMapping <IConfig, ConfigTest>("key");
            actual = new List <TypeMapping>(target.GetTypeMappings());

            beforeCount = actual.Count;
            target.RegisterTypeMapping <IConfig, ConfigTest1>("key");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>("key"), typeof(ConfigTest1));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            Assert.AreEqual(beforeCount, actual.Count);
        }
コード例 #9
0
        public void RemoveTypeMapping_RemoveAMapping()
        {
            //Arrange
            var typeMappings = new List <TypeMapping> {
                new TypeMapping()
                {
                    FromAssembly = "1"
                },
                new TypeMapping()
                {
                    FromAssembly = "2"
                },
                new TypeMapping()
                {
                    FromAssembly = "3"
                }
            };
            var config = new ServiceLocationConfigData(typeMappings);
            var bag    = new BIPropertyBag();

            BSPFarm.SetLocal();
            var cfgMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) => true,
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => bag,
            };

            cfgMgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, propetyBag) => config);
            cfgMgr.BehaveAsDefaultValue();

            //Act
            var target = new ServiceLocatorConfig(cfgMgr);

            target.RemoveTypeMapping(typeMappings[0]);
            List <TypeMapping> registeredTypeMappings =
                target.GetTypeMappings().ToList();

            //Assert
            Assert.AreEqual(2, registeredTypeMappings.Count);
            Assert.AreSame(typeMappings[1], registeredTypeMappings[0]);
            Assert.AreSame(typeMappings[2], registeredTypeMappings[1]);
        }
コード例 #10
0
        public void GetTypeMappings_GetAllMappings()
        {
            //Arrange
            var setMappings = new List <TypeMapping> {
                new TypeMapping {
                    FromAssembly = "1"
                },
                new TypeMapping {
                    FromAssembly = "2"
                },
                new TypeMapping {
                    FromAssembly = "3"
                }
            };
            var configData = new ServiceLocationConfigData(setMappings);
            var bag        = new BIPropertyBag();

            BSPFarm.SetLocal();

            var cfgMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (strValue, propertyBag) => true,
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => bag
            };

            cfgMgr.BehaveAsDefaultValue();
            cfgMgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((strValue, property) => configData);

            //Act
            var target = new ServiceLocatorConfig(cfgMgr);
            IEnumerable <TypeMapping> registeredTypeMappings = target.GetTypeMappings();

            //Assert
            Assert.AreEqual(3, registeredTypeMappings.Count());
        }