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());
        }
        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));
        }
        public void RegisteringTypeMappingTwiceOverwritesLastOne()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>();
            target.RegisterTypeMapping <ISomething, SomethingElse>();

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping = typeMappings.First();

            Assert.IsTrue(mapping.ToType.Contains("SomethingElse"));
        }
        public void CanRegisterTypeMappingWithKey()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>("key1");
            target.RegisterTypeMapping <ISomething, Something>("key2");

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping1 = typeMappings.First();
            TypeMapping mapping2 = typeMappings.Skip(1).First();

            Assert.AreEqual("key1", mapping1.Key);
            Assert.AreEqual("key2", mapping2.Key);
        }
        public void CanRegisterTypeMapping()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>();

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping = typeMappings.First();

            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromAssembly);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests.ServiceLocation.ISomething, Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromType);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToAssembly);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests.ServiceLocation.Something, Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToType);
        }