diff --git a/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs b/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
index af5e99ca..db343ac4 100644
--- a/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
+++ b/src/Spring/Spring.Core/Core/IO/ConfigSectionResource.cs
@@ -139,7 +139,7 @@ namespace Spring.Core.IO
{
get
{
- return StringUtils.Surround("config [", sectionName, "]");
+ return string.Format("config [{0}#{1}]", ConfigurationUtils.GetFileName(configElement), sectionName);
}
}
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/XmlObjectDefinitionReader.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/XmlObjectDefinitionReader.cs
index e3097d01..6c6396c0 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Xml/XmlObjectDefinitionReader.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Xml/XmlObjectDefinitionReader.cs
@@ -208,9 +208,17 @@ namespace Spring.Objects.Factory.Xml
{
try
{
- XmlReader reader =
- XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(),
- new ValidationEventHandler(HandleValidation));
+ XmlReader reader;
+
+ if (SystemUtils.MonoRuntime)
+ {
+ reader = XmlUtils.CreateReader(stream);
+ }
+ else
+ {
+ reader = XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(),
+ new ValidationEventHandler(HandleValidation));
+ }
#region Instrumentation
@@ -221,7 +229,7 @@ namespace Spring.Objects.Factory.Xml
#endregion
- XmlDocument doc = new XmlDocument();
+ XmlDocument doc = new ConfigXmlDocument();
doc.Load(reader);
return RegisterObjectDefinitions(doc, resource);
}
diff --git a/src/Spring/Spring.Core/Spring.Core.2003.csproj b/src/Spring/Spring.Core/Spring.Core.2003.csproj
index a137cda4..8dfbe7b7 100644
--- a/src/Spring/Spring.Core/Spring.Core.2003.csproj
+++ b/src/Spring/Spring.Core/Spring.Core.2003.csproj
@@ -2361,6 +2361,21 @@
SubType = "Code"
BuildAction = "Compile"
/>
+
+
+
+
+
Local
- 9.0.21022
+ 9.0.30729
2.0
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}
Debug
@@ -999,13 +999,18 @@
+
+
+
+
+
diff --git a/src/Spring/Spring.Core/Util/ConfigXmlAttribute.cs b/src/Spring/Spring.Core/Util/ConfigXmlAttribute.cs
new file mode 100644
index 00000000..f574a799
--- /dev/null
+++ b/src/Spring/Spring.Core/Util/ConfigXmlAttribute.cs
@@ -0,0 +1,87 @@
+#region License
+
+/*
+ * Copyright © 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.Xml;
+
+#endregion
+
+namespace Spring.Util
+{
+ ///
+ /// An holding information about its original text source location.
+ ///
+ /// Erich Eichinger
+ public class ConfigXmlAttribute : XmlAttribute, ITextPosition
+ {
+ private ITextPosition _textPositionInfo;
+
+ ///
+ /// Creates a new instance of , storing a copy of the passed
+ /// .
+ ///
+ public ConfigXmlAttribute(ITextPosition currentTextPositionPositionInfo, string prefix, string localName, string namespaceURI, XmlDocument doc)
+ : base(prefix, localName, namespaceURI, doc)
+ {
+ // TODO: for NET 2.0 may check for "System.Configuration.Internal.IConfigErrorInfo"
+ _textPositionInfo = new TextPositionInfo(currentTextPositionPositionInfo);
+ }
+
+ ///
+ /// The name of the resource this element was read from
+ ///
+ public string Filename
+ {
+ get { return _textPositionInfo.Filename; }
+ }
+
+ ///
+ /// The line number within the resource this element was read from
+ ///
+ public int LineNumber
+ {
+ get { return _textPositionInfo.LineNumber; }
+ }
+
+ ///
+ /// The line position within the resource this element was read from.
+ ///
+ public int LinePosition
+ {
+ get { return _textPositionInfo.LinePosition; }
+ }
+
+ ///
+ ///Creates a duplicate of this node.
+ ///
+ ///true to recursively clone the subtree under the specified node; false to clone only the node itself
+ public override XmlNode CloneNode(bool deep)
+ {
+ XmlNode node = base.CloneNode(deep);
+ ConfigXmlAttribute element = node as ConfigXmlAttribute;
+ if (element != null)
+ {
+ element._textPositionInfo = new TextPositionInfo(this._textPositionInfo);
+ }
+ return node;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Spring/Spring.Core/Util/ConfigXmlDocument.cs b/src/Spring/Spring.Core/Util/ConfigXmlDocument.cs
new file mode 100644
index 00000000..8fa527c4
--- /dev/null
+++ b/src/Spring/Spring.Core/Util/ConfigXmlDocument.cs
@@ -0,0 +1,248 @@
+#region License
+
+/*
+ * Copyright © 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.IO;
+using System.Xml;
+
+#endregion
+
+namespace Spring.Util
+{
+ ///
+ /// An implementation, who's elements retain information
+ /// about their location in the original XML text document the were read from.
+ ///
+ ///
+ /// When loading a document, the used must implement .
+ /// Typical XmlReader implementations like support this interface.
+ ///
+ /// Erich Eichinger
+ public class ConfigXmlDocument : XmlDocument
+ {
+ ///
+ /// Holds the current text position during loading a document
+ ///
+ private class CurrentTextPositionHolder : ITextPosition
+ {
+ private string _currentResourceName;
+ private IXmlLineInfo _currentXmlLineInfo;
+
+ public IXmlLineInfo CurrentXmlLineInfo
+ {
+ //get { return _currentXmlLineInfo; }
+ set { _currentXmlLineInfo = value; }
+ }
+
+ public string CurrentResourceName
+ {
+ //get { return _currentResourceName; }
+ set { _currentResourceName = value; }
+ }
+
+ public string Filename
+ {
+ get { return _currentResourceName; }
+ }
+
+ public int LineNumber
+ {
+ get { return (_currentXmlLineInfo != null) ? _currentXmlLineInfo.LineNumber : 0; }
+ }
+
+ public int LinePosition
+ {
+ get { return (_currentXmlLineInfo != null) ? _currentXmlLineInfo.LinePosition : 0; }
+ }
+ }
+
+ private readonly CurrentTextPositionHolder _currentTextPositionHolder = new CurrentTextPositionHolder();
+
+ ///
+ /// Get info about the current text position during loading a document.
+ /// Outside loading a document, the properties of
+ /// will always be null.
+ ///
+ protected ITextPosition CurrentTextPosition
+ {
+ get { return _currentTextPositionHolder; }
+ }
+
+ ///
+ /// Overridden to create a retaining the current
+ /// text position information.
+ ///
+ public override XmlElement CreateElement(string prefix, string localName, string namespaceURI)
+ {
+ return new ConfigXmlElement(this.CurrentTextPosition, prefix, localName, namespaceURI, this);
+ }
+
+ ///
+ /// Overridden to create a retaining the current
+ /// text position information.
+ ///
+ public override XmlAttribute CreateAttribute(string prefix, string localName, string namespaceURI)
+ {
+ return new ConfigXmlAttribute(this.CurrentTextPosition, prefix, localName, namespaceURI, this);
+ }
+
+ ///
+ /// Load the document from the given .
+ /// Child nodes will store as their property.
+ ///
+ ///the name of the resource
+ ///The XML source
+ public void LoadXml(string resourceName, string xml)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentResourceName = resourceName;
+ base.LoadXml(xml);
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentResourceName = null;
+ }
+ }
+
+ ///
+ /// Load the document from the given .
+ /// Child nodes will store as their property.
+ ///
+ ///the name of the resource
+ ///The XML source
+ public void Load(string resourceName, Stream stream)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentResourceName = resourceName;
+ base.Load (stream );
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentResourceName = null;
+ }
+ }
+
+ ///
+ /// Load the document from the given .
+ /// Child nodes will store as their property.
+ ///
+ ///the name of the resource
+ ///The XML source
+ public void Load(string resourceName, TextReader reader)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentResourceName = resourceName;
+ base.Load (reader );
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentResourceName = null;
+ }
+ }
+
+ ///
+ /// Load the document from the given .
+ /// Child nodes will store as their property.
+ ///
+ ///the name of the resource
+ ///The XML source
+ public void Load(string resourceName, XmlReader reader)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentResourceName = resourceName;
+ this.Load (reader);
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentResourceName = null;
+ }
+ }
+
+ ///
+ /// Load the document from the given .
+ /// Child nodes will store null as their property.
+ ///
+ /// The XML source
+ public override void Load(XmlReader reader)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
+ base.Load (reader);
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentXmlLineInfo = null;
+ }
+ }
+
+ ///
+ ///Creates an object based on the information in the . The reader must be positioned on a node or attribute.
+ ///Child nodes will store as their property.
+ ///
+ ///
+ ///The new XmlNode or null if no more nodes exist.
+ ///
+ ///the name of the resource
+ ///The XML source
+ ///The reader is positioned on a node type that does not translate to a valid DOM node (for example, EndElement or EndEntity).
+ public XmlNode ReadNode(string resourceName, XmlReader reader)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentResourceName = resourceName;
+ _currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
+ return this.ReadNode (reader);
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentXmlLineInfo = null;
+ }
+ }
+
+ ///
+ ///Creates an object based on the information in the . The reader must be positioned on a node or attribute.
+ ///Child nodes will store null as their property.
+ ///
+ ///
+ ///The new XmlNode or null if no more nodes exist.
+ ///
+ ///The XML source
+ ///The reader is positioned on a node type that does not translate to a valid DOM node (for example, EndElement or EndEntity).
+ public override XmlNode ReadNode(XmlReader reader)
+ {
+ try
+ {
+ _currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
+ return base.ReadNode (reader);
+ }
+ finally
+ {
+ _currentTextPositionHolder.CurrentXmlLineInfo = null;
+ }
+ }
+
+ }
+}
diff --git a/src/Spring/Spring.Core/Util/ConfigXmlElement.cs b/src/Spring/Spring.Core/Util/ConfigXmlElement.cs
new file mode 100644
index 00000000..b2a92962
--- /dev/null
+++ b/src/Spring/Spring.Core/Util/ConfigXmlElement.cs
@@ -0,0 +1,86 @@
+#region License
+
+/*
+ * Copyright © 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.Xml;
+
+#endregion
+
+namespace Spring.Util
+{
+ ///
+ /// An holding information about its original text source location.
+ ///
+ /// Erich Eichinger
+ public class ConfigXmlElement : XmlElement, ITextPosition
+ {
+ private ITextPosition _textPositionInfo;
+
+ ///
+ /// Creates a new instance of , storing a copy of the passed
+ /// .
+ ///
+ public ConfigXmlElement(ITextPosition currentTextPositionPositionInfo, string prefix, string localName, string namespaceURI, XmlDocument doc)
+ : base(prefix, localName, namespaceURI, doc)
+ {
+ _textPositionInfo = new TextPositionInfo(currentTextPositionPositionInfo);
+ }
+
+ ///
+ /// The name of the resource this element was read from
+ ///
+ public string Filename
+ {
+ get { return _textPositionInfo.Filename; }
+ }
+
+ ///
+ /// The line number within the resource this element was read from
+ ///
+ public int LineNumber
+ {
+ get { return _textPositionInfo.LineNumber; }
+ }
+
+ ///
+ /// The line position within the resource this element was read from.
+ ///
+ public int LinePosition
+ {
+ get { return _textPositionInfo.LinePosition; }
+ }
+
+ ///
+ ///Creates a duplicate of this node.
+ ///
+ ///true to recursively clone the subtree under the specified node; false to clone only the node itself
+ public override XmlNode CloneNode(bool deep)
+ {
+ XmlNode node = base.CloneNode(deep);
+ ConfigXmlElement element = node as ConfigXmlElement;
+ if (element != null)
+ {
+ element._textPositionInfo = new TextPositionInfo(this._textPositionInfo);
+ }
+ return node;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Spring/Spring.Core/Util/ConfigurationUtils.cs b/src/Spring/Spring.Core/Util/ConfigurationUtils.cs
index a4d05948..07919497 100644
--- a/src/Spring/Spring.Core/Util/ConfigurationUtils.cs
+++ b/src/Spring/Spring.Core/Util/ConfigurationUtils.cs
@@ -196,6 +196,10 @@ namespace Spring.Util
/// The line number of the specified node.
public static int GetLineNumber(XmlNode node)
{
+ if (node is ITextPosition)
+ {
+ return ((ITextPosition)node).LineNumber;
+ }
#if !NET_2_0
return ConfigurationException.GetXmlNodeLineNumber(node);
#else
@@ -210,6 +214,10 @@ namespace Spring.Util
/// The name of the file specified node is defined in.
public static string GetFileName(XmlNode node)
{
+ if (node is ITextPosition)
+ {
+ return ((ITextPosition)node).Filename;
+ }
#if !NET_2_0
return ConfigurationException.GetXmlNodeFilename(node);
#else
diff --git a/src/Spring/Spring.Core/Util/ITextPosition.cs b/src/Spring/Spring.Core/Util/ITextPosition.cs
new file mode 100644
index 00000000..806736d0
--- /dev/null
+++ b/src/Spring/Spring.Core/Util/ITextPosition.cs
@@ -0,0 +1,48 @@
+using System;
+
+namespace Spring.Util
+{
+#if NET_2_0
+ ///
+ /// Holds text position information for e.g. error reporting purposes.
+ ///
+ ///
+ ///
+ public interface ITextPosition : System.Configuration.Internal.IConfigErrorInfo
+ {
+ ///
+ /// Gets a string specifying the file/resource name related to the configuration details.
+ ///
+ new string Filename { get; }
+ ///
+ /// Gets an integer specifying the line number related to the configuration details.
+ ///
+ new int LineNumber { get; }
+ ///
+ /// Gets an integer specifying the line position related to the configuration details.
+ ///
+ int LinePosition { get; }
+ }
+#else
+ ///
+ /// Holds text position information for e.g. error reporting purposes.
+ ///
+ ///
+ ///
+ public interface ITextPosition
+ {
+ ///
+ /// Gets a string specifying the file/resource name related to the configuration details.
+ ///
+ string Filename { get; }
+ ///
+ /// Gets an integer specifying the line number related to the configuration details.
+ ///
+ int LineNumber { get; }
+ ///
+ /// Gets an integer specifying the line position related to the configuration details.
+ ///
+ int LinePosition { get; }
+ }
+#endif
+}
diff --git a/src/Spring/Spring.Core/Util/TextPositionInfo.cs b/src/Spring/Spring.Core/Util/TextPositionInfo.cs
new file mode 100644
index 00000000..efd8a779
--- /dev/null
+++ b/src/Spring/Spring.Core/Util/TextPositionInfo.cs
@@ -0,0 +1,85 @@
+#region License
+
+/*
+ * Copyright © 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
+
+#endregion
+
+namespace Spring.Util
+{
+ ///
+ /// Holds text position information for e.g. error reporting purposes.
+ ///
+ ///
+ ///
+ public class TextPositionInfo : ITextPosition
+ {
+ private readonly string _filename;
+ private readonly int _lineNumber;
+ private readonly int _linePosition;
+
+ ///
+ /// Creates a new TextPositionInfo instance.
+ ///
+ public TextPositionInfo(string filename, int lineNumber, int linePosition)
+ {
+ _filename = filename;
+ _lineNumber = lineNumber;
+ _linePosition = linePosition;
+ }
+
+ ///
+ /// Creates a new TextPositionInfo instance, copying values from another instance.
+ ///
+ public TextPositionInfo(ITextPosition other)
+ {
+ if (other != null)
+ {
+ this._filename = other.Filename;
+ this._lineNumber = other.LineNumber;
+ this._linePosition = other.LinePosition;
+ }
+ }
+
+ ///
+ /// The filename related to this text position
+ ///
+ public string Filename
+ {
+ get { return _filename; }
+ }
+
+ ///
+ /// The line number related to this text position
+ ///
+ public int LineNumber
+ {
+ get { return _lineNumber; }
+ }
+
+ ///
+ /// The line position related to this text position
+ ///
+ public int LinePosition
+ {
+ get { return _linePosition; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs b/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
index 85804285..93b22b55 100644
--- a/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
+++ b/test/Spring/Spring.Core.Tests/Core/IO/ConfigSectionResourceTests.cs
@@ -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);
}
}
}
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Core/IO/UrlResourceTest.cs b/test/Spring/Spring.Core.Tests/Core/IO/UrlResourceTest.cs
index e986f107..773a1808 100644
--- a/test/Spring/Spring.Core.Tests/Core/IO/UrlResourceTest.cs
+++ b/test/Spring/Spring.Core.Tests/Core/IO/UrlResourceTest.cs
@@ -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/");
diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
index 9a08df84..2661588e 100644
--- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
+++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj
@@ -673,6 +673,7 @@
Code
+
@@ -831,6 +832,7 @@
+
diff --git a/test/Spring/Spring.Core.Tests/TestResourceLoader.cs b/test/Spring/Spring.Core.Tests/TestResourceLoader.cs
index 19b680e6..289b5f8b 100644
--- a/test/Spring/Spring.Core.Tests/TestResourceLoader.cs
+++ b/test/Spring/Spring.Core.Tests/TestResourceLoader.cs
@@ -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;
}
diff --git a/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests.cs b/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests.cs
new file mode 100644
index 00000000..27925f3f
--- /dev/null
+++ b/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests.cs
@@ -0,0 +1,99 @@
+#region License
+
+/*
+ * Copyright © 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
+{
+ ///
+ ///
+ ///
+ /// Erich Eichinger
+ [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
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests_SampleConfig.xml b/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests_SampleConfig.xml
new file mode 100644
index 00000000..242bf3bd
--- /dev/null
+++ b/test/Spring/Spring.Core.Tests/Util/ConfigXmlDocumentTests_SampleConfig.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
\ No newline at end of file