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"); }
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"); }
public void TypeResolutionDetectsAmbigousTypes() { // --- Arrange var settings = new TypeResolverConfigurationSettings( (XElement)ConfigurationManager.GetSection("TypeResolver1")); var typeResolver = new DefaultTypeResolver(settings); // --- Act typeResolver.Resolve("MyType").ShouldBeNull(); }
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(); }
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(); }
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); }