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));
        }
Пример #2
0
        public void SerLocConfigRemoveTypeMappingKey()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IConfig, ConfigTest>();
            target.RegisterTypeMapping <IConfig, ConfigTest>("key");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));

            actual = new List <TypeMapping>(target.GetTypeMappings());

            target.RemoveTypeMapping <IConfig>("key");
            Assert.AreEqual(actual.Count - 1, target.GetTypeMappings().Count());
        }
Пример #3
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]);
        }
Пример #4
0
 /// <summary>
 /// Removes the specified name.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="name">The name.</param>
 public void Remove <TService>(string name)
 {
     _registrar.RemoveTypeMapping <TService>(name);
 }