private XmlDocument GetValidatedXmlResource(string resourceExtension) { AssemblyResource validationSchema = new AssemblyResource("assembly://Spring.Core/Spring.Validation.Config/spring-validation-1.3.xsd"); AssemblyResource objectsSchema = new AssemblyResource("assembly://Spring.Core/Spring.Objects.Factory.Xml/spring-objects-1.3.xsd"); return(TestResourceLoader.GetXmlValidated(this, resourceExtension, objectsSchema, validationSchema)); }
public void Host_StartupOk_RespondsOnHttpRequest() { const string content = "<h1>Test</h1>"; var options = new StonehengeHostOptions { Title = "Test" }; var loader = new TestResourceLoader(content); var host = new KestrelHost(loader, options); var startOk = host.Start("localhost", 32001); Assert.True(startOk, "Start failed"); var response = string.Empty; try { using var client = new RedirectableWebClient(); response = client.DownloadString(host.BaseUrl); } catch (Exception ex) { _logger.LogError(ex, nameof(Host_StartupOk_RespondsOnHttpRequest)); } Assert.Equal(content, response); host.Terminate(); }
public void SunnyDay() { FileInfo resFile = TestResourceLoader.ExportResource(this, ".config", new FileInfo(Path.GetTempFileName() + ".config")); string exePath = resFile.FullName.Substring(0, resFile.FullName.Length - ".config".Length); Assert.IsTrue(resFile.Exists); IInternalConfigSystem prevConfig = null; try { ExeConfigurationSystem ccs = new ExeConfigurationSystem(exePath); prevConfig = ConfigurationUtils.SetConfigurationSystem(ccs, true); LogSetting settings = (LogSetting)ConfigurationManager.GetSection("logging"); Assert.AreEqual(typeof(TraceLoggerFactoryAdapter), settings.FactoryAdapterType); Assert.AreEqual("from custom config!", ConfigurationManager.AppSettings["key"]); Assert.IsNull(ConfigurationManager.GetSection("spring/context")); } finally { if (prevConfig != null) { ConfigurationUtils.SetConfigurationSystem(prevConfig, true); } resFile.Delete(); } }
public void LoadXmlStoresTextPosition() { ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); string xmlText = TestResourceLoader.GetText( this, "_SampleConfig.xml" ); xmlDoc.LoadXml( "MYXML", xmlText ); ITextPosition pos = ((ITextPosition)xmlDoc.SelectSingleNode("//property")); Assert.AreEqual("MYXML", pos.Filename); Assert.AreEqual(5, pos.LineNumber); Assert.AreEqual(14, pos.LinePosition); }
public void LoadTextReaderStoresTextPosition() { ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); Stream istm = TestResourceLoader.GetStream( this, "_SampleConfig.xml" ); xmlDoc.Load( "MYXML", new StreamReader(istm) ); ITextPosition pos = ((ITextPosition)xmlDoc.SelectSingleNode("//property")); Assert.AreEqual("MYXML", pos.Filename); Assert.AreEqual(5, pos.LineNumber); Assert.AreEqual(14, pos.LinePosition); }
public void CanConfigFilenameAndLine() { ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); Stream istm = TestResourceLoader.GetStream( this, "_SampleConfig.xml" ); xmlDoc.Load( "MYXML", new StreamReader(istm) ); XmlNode node = xmlDoc.SelectSingleNode("//property"); Assert.AreEqual("MYXML", ConfigurationUtils.GetFileName(node) ); Assert.AreEqual(5, ConfigurationUtils.GetLineNumber(node) ); //Assert.AreEqual(14, pos.LinePosition); <- IConfigErrorInfo/IConfigXmlNode do not support LinePosition }
public void CanLoadSchemaImportingOtherSchemaByRelativePath() { string schemaLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "NamespaceParserRegistryTests_TestSchema.xsd"); NamespaceParserRegistry.RegisterParser(new TestNamespaceParser(), "http://www.example.com/brief", schemaLocation); XmlReader vr = XmlUtils.CreateValidatingReader(new StringResource( @"<?xml version='1.0' encoding='UTF-8' ?> <brief class='foo' /> ").InputStream, NamespaceParserRegistry.GetSchemas(), null); ConfigXmlDocument newDoc = new ConfigXmlDocument(); newDoc.Load(vr); }
public void Host_MultipleInstances_StartupOk_RespondsOnHttpRequest() { const string content1 = "<h1>Test 01</h1>"; const string content2 = "<h1>Test II</h1>"; var options = new StonehengeHostOptions { Title = "Test" }; var loader1 = new TestResourceLoader(content1); var host1 = new KestrelHost(loader1, options); var startOk = host1.Start("localhost", 32002); Assert.True(startOk, "Start host1 failed"); var loader2 = new TestResourceLoader(content2); var host2 = new KestrelHost(loader2, options); startOk = host2.Start("localhost", 32003); Assert.True(startOk, "Start host2 failed"); Assert.NotEqual(host1.BaseUrl, host2.BaseUrl); var response1 = string.Empty; var response2 = string.Empty; try { using (var client = new RedirectableWebClient()) { response1 = client.DownloadString(host1.BaseUrl); } using (var client = new RedirectableWebClient()) { response2 = client.DownloadString(host2.BaseUrl); } } catch (Exception ex) { _logger.LogError(ex, nameof(Host_MultipleInstances_StartupOk_RespondsOnHttpRequest)); Assert.True(false, ex.Message); } Assert.Equal(content1, response1); Assert.Equal(content2, response2); host1.Terminate(); host2.Terminate(); }
private ConfigSectionResource CreateConfigSectionResource(string filename) { ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); Uri testUri = TestResourceLoader.GetUri(this, filename); xmlDoc.Load("test config section", testUri.AbsoluteUri); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("od", "http://www.springframework.net"); XmlElement configElement = (XmlElement)xmlDoc.SelectSingleNode("//configuration/spring/od:objects", nsmgr); ConfigSectionResource csr = new ConfigSectionResource(configElement); return(csr); }
public void SPRNET1231_DoesNotInvokeFactoryMethodDuringObjectFactoryPostProcessing() { string configLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "XmlApplicationContextTests-SPRNET1231.xml"); XmlApplicationContext ctx = new XmlApplicationContext(configLocation); }