示例#1
0
        public void WriteXmlAndReadXmlWorksAsExpected()
        {
            // --- Arrange
            var setting = new TypeResolverConfigurationSettings(
                new List <string> {
                "Asm1", "Asm2"
            },
                new List <string> {
                "Ns1", "Ns2", "Ns3"
            }
                );

            // --- Act
            var element = setting.WriteToXml("Test");

            // --- Assert
            var newSettings = new TypeResolverConfigurationSettings(element);

            newSettings.AssemblyNames.ShouldHaveCountOf(2);
            newSettings.AssemblyNames[0].ShouldEqual("Asm1");
            newSettings.AssemblyNames[1].ShouldEqual("Asm2");
            newSettings.Namespaces.ShouldHaveCountOf(3);
            newSettings.Namespaces[0].ShouldEqual("Ns1");
            newSettings.Namespaces[1].ShouldEqual("Ns2");
            newSettings.Namespaces[2].ShouldEqual("Ns3");
        }
示例#2
0
        public void SetSettingsWorksAsExpected()
        {
            // --- Arrange
            const string KEY      = "TypeResolverBackup";
            var          settings = new TypeResolverConfigurationSettings(new List <string> {
                "System"
            },
                                                                          new List <string> {
                "TypeResolution"
            });
            var provider = new AppConfigProvider();

            // --- Act
            provider.SetSetting(KEY, settings);

            // --- Assert
            ConfigurationManager.RefreshSection(KEY);
            var config = ConfigurationManager.GetSection(KEY) as XElement;

            config.ShouldNotBeNull();
            settings = new TypeResolverConfigurationSettings(config);
            settings.AssemblyNames.ShouldHaveCountOf(1);
            settings.AssemblyNames[0].ShouldEqual("System");
            settings.Namespaces.ShouldHaveCountOf(1);
            settings.Namespaces[0].ShouldEqual("TypeResolution");
        }
示例#3
0
        public void TypeResolutionDetectsAmbigousTypes()
        {
            // --- Arrange
            var settings = new TypeResolverConfigurationSettings(
                (XElement)ConfigurationManager.GetSection("TypeResolver1"));
            var typeResolver = new DefaultTypeResolver(settings);

            // --- Act
            typeResolver.Resolve("MyType").ShouldBeNull();
        }
示例#4
0
        public void UnloadableAssembliesDoNotFail()
        {
            // --- Arrange
            var settings = new TypeResolverConfigurationSettings(
                (XElement)ConfigurationManager.GetSection("TypeResolver1"));
            var typeResolver = new DefaultTypeResolver(settings);

            // --- Act
            var type = typeResolver.Resolve("ThisIsADummyType, ThisIsADummyType.dll");

            // --- Assert
            type.ShouldBeNull();
        }
示例#5
0
        public void UnknownTypesAreResolvedToNull()
        {
            // --- Arrange
            var settings = new TypeResolverConfigurationSettings(
                (XElement)ConfigurationManager.GetSection("TypeResolver1"));
            var typeResolver = new DefaultTypeResolver(settings);

            // --- Act
            var type = typeResolver.Resolve("ThisIsADummyType");

            // --- Assert
            type.ShouldBeNull();
        }
示例#6
0
        public void TypeResolutionWorksFromAppConfig()
        {
            // --- Arrange
            var settings = new TypeResolverConfigurationSettings(
                (XElement)ConfigurationManager.GetSection("TypeResolver1"));
            var typeResolver = new DefaultTypeResolver(settings);

            // --- Act
            var type1 = typeResolver.Resolve("Int32");
            var type2 = typeResolver.Resolve("String");
            var type3 = typeResolver.Resolve("uint");

            // --- Assert
            type1.ShouldEqual(typeof(int));
            type2.ShouldEqual(typeof(string));
            type3.ShouldEqual(typeof(uint));
        }
        public void ConfigurationWithSettingsResolverToDefaultTypeResolver()
        {
            // --- Arrange
            var settings = new TypeResolverConfigurationSettings(
                (XElement)ConfigurationManager.GetSection(SECTION_NAME));

            // --- Act
            var before = TypeResolver.Current;

            TypeResolver.Configure(settings);
            var after = TypeResolver.Current;

            // --- Assert
            after.ShouldBeOfType(typeof(DefaultTypeResolver));
            _configurationChangedVisited.ShouldBeTrue();
            before.ShouldBeNull();
            _before.ShouldBeNull();
            _after.ShouldEqual(after);
        }