resolved SPRNET-912
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Core.IO
|
||||
{
|
||||
@@ -9,10 +12,42 @@ namespace Spring.Core.IO
|
||||
[TestFixture]
|
||||
public class ConfigSectionResourceTests
|
||||
{
|
||||
private ConfigSectionResource CreateConfigSectionResource(string filename)
|
||||
{
|
||||
ConfigXmlDocument xmlDoc = new ConfigXmlDocument();
|
||||
Uri testUri = TestResourceLoader.GetUri(this, filename);
|
||||
xmlDoc.Load( 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;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanCreate()
|
||||
{
|
||||
// TODO
|
||||
ConfigSectionResource csr = CreateConfigSectionResource("_config1.xml");
|
||||
Assert.IsFalse(csr.Exists);
|
||||
Assert.IsNull(csr.File); // always null
|
||||
Assert.IsNull(csr.Uri);
|
||||
Assert.IsTrue(csr.Description.StartsWith("config [") );
|
||||
Assert.IsTrue(csr.Description.EndsWith("#objects]") );
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ThrowsOnNullSectionName()
|
||||
{
|
||||
new ConfigSectionResource((string)null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ThrowsOnNullConfigElement()
|
||||
{
|
||||
new ConfigSectionResource((XmlElement)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace Spring.Core.IO
|
||||
Assert.AreEqual("C:\\temp", urlResource.File.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test, Explicit]
|
||||
public void ExistsValidHttp()
|
||||
{
|
||||
UrlResource urlResource = new UrlResource("http://www.springframework.net/");
|
||||
|
||||
@@ -673,6 +673,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Util\CollectionUtilsTests.cs" />
|
||||
<Compile Include="Util\ConfigXmlDocumentTests.cs" />
|
||||
<Compile Include="Util\ObjectUtilsTests.cs" />
|
||||
<Compile Include="Util\PatternMatchUtilsTests.cs" />
|
||||
<Compile Include="Util\DefensiveEventRaiserTests.cs">
|
||||
@@ -831,6 +832,7 @@
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithAllRequiredPropertiesProvided.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithCustomAttribute.xml" />
|
||||
<Content Include="Spring.Core.Tests.dll.config" />
|
||||
<EmbeddedResource Include="Util\ConfigXmlDocumentTests_SampleConfig.xml" />
|
||||
<EmbeddedResource Include="Context\contextlifecycle.xml" />
|
||||
<EmbeddedResource Include="Context\Support\objects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\TestResource.txt" />
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Spring
|
||||
public static Uri GetUri(object context, string ext)
|
||||
{
|
||||
string resname = context.GetType().AssemblyQualifiedName + "#" + ext;
|
||||
Uri uri = new Uri("testres://(local)/" + resname, false);
|
||||
Uri uri = new Uri("testres://./" + resname, false);
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
99
test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests.cs
Normal file
99
test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Util
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <author>Erich Eichinger</author>
|
||||
[TestFixture]
|
||||
public class ConfigXmlDocumentTests
|
||||
{
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoadReaderStoresTextPosition()
|
||||
{
|
||||
ConfigXmlDocument xmlDoc = new ConfigXmlDocument();
|
||||
Stream istm = TestResourceLoader.GetStream( this, "_SampleConfig.xml" );
|
||||
xmlDoc.Load( "MYXML", new XmlTextReader( istm ) );
|
||||
ITextPosition pos = ((ITextPosition)xmlDoc.SelectSingleNode("//property"));
|
||||
Assert.AreEqual("MYXML", pos.Filename);
|
||||
Assert.AreEqual(5, pos.LineNumber);
|
||||
Assert.AreEqual(14, pos.LinePosition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoadStreamStoresTextPosition()
|
||||
{
|
||||
ConfigXmlDocument xmlDoc = new ConfigXmlDocument();
|
||||
Stream istm = TestResourceLoader.GetStream( this, "_SampleConfig.xml" );
|
||||
xmlDoc.Load( "MYXML", istm );
|
||||
ITextPosition pos = ((ITextPosition)xmlDoc.SelectSingleNode("//property"));
|
||||
Assert.AreEqual("MYXML", pos.Filename);
|
||||
Assert.AreEqual(5, pos.LineNumber);
|
||||
Assert.AreEqual(14, pos.LinePosition);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<objects>
|
||||
<object>
|
||||
<property name="" value="" />
|
||||
</object>
|
||||
</objects>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user