resolved SPRNET-912

This commit is contained in:
eeichinger
2008-10-25 15:57:12 +00:00
parent 038bcb17c0
commit ae5426aa76
16 changed files with 753 additions and 9 deletions

View File

@@ -139,7 +139,7 @@ namespace Spring.Core.IO
{
get
{
return StringUtils.Surround("config [", sectionName, "]");
return string.Format("config [{0}#{1}]", ConfigurationUtils.GetFileName(configElement), sectionName);
}
}

View File

@@ -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);
}

View File

@@ -2361,6 +2361,21 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\ConfigXmlAttribute.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\ConfigXmlDocument.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\ConfigXmlElement.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\DelegateInfo.cs"
SubType = "Code"
@@ -2381,6 +2396,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\ITextPosition.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\NumberUtils.cs"
SubType = "Code"
@@ -2426,6 +2446,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\TextPositionInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Util\UniqueKey.cs"
SubType = "Code"

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -999,13 +999,18 @@
</Compile>
<Compile Include="Util\CompareUtils.cs" />
<Compile Include="Util\ConfigurationUtils.cs" />
<Compile Include="Util\ConfigXmlAttribute.cs" />
<Compile Include="Util\ConfigXmlDocument.cs" />
<Compile Include="Util\ConfigXmlElement.cs" />
<Compile Include="Util\FatalReflectionException.cs" />
<Compile Include="Util\ITextPosition.cs" />
<Compile Include="Util\ObjectUtils.cs" />
<Compile Include="Util\ReflectionException.cs" />
<Compile Include="Util\SystemUtils.cs" />
<Compile Include="Util\DynamicCodeManager.cs" />
<Compile Include="Util\Generic\CollectionUtils.cs" />
<Compile Include="Util\PatternMatchUtils.cs" />
<Compile Include="Util\TextPositionInfo.cs" />
<Compile Include="Util\UniqueKey.cs" />
<Compile Include="Core\TypeConversion\UniqueKeyConverter.cs" />
<Compile Include="Util\XmlUtils.cs" />

View File

@@ -0,0 +1,87 @@
#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.Xml;
#endregion
namespace Spring.Util
{
/// <summary>
/// An <see cref="XmlAttribute"/> holding information about its original text source location.
/// </summary>
/// <author>Erich Eichinger</author>
public class ConfigXmlAttribute : XmlAttribute, ITextPosition
{
private ITextPosition _textPositionInfo;
///<summary>
/// Creates a new instance of <see cref="ConfigXmlAttribute"/>, storing a copy of the passed
/// <paramref name="currentTextPositionPositionInfo"/>.
///</summary>
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);
}
/// <summary>
/// The name of the resource this element was read from
/// </summary>
public string Filename
{
get { return _textPositionInfo.Filename; }
}
/// <summary>
/// The line number within the resource this element was read from
/// </summary>
public int LineNumber
{
get { return _textPositionInfo.LineNumber; }
}
/// <summary>
/// The line position within the resource this element was read from.
/// </summary>
public int LinePosition
{
get { return _textPositionInfo.LinePosition; }
}
///<summary>
///Creates a duplicate of this node.
///</summary>
///<param name="deep">true to recursively clone the subtree under the specified node; false to clone only the node itself </param>
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;
}
}
}

View File

@@ -0,0 +1,248 @@
#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.IO;
using System.Xml;
#endregion
namespace Spring.Util
{
/// <summary>
/// An <see cref="XmlDocument"/> implementation, who's elements retain information
/// about their location in the original XML text document the were read from.
/// </summary>
/// <remarks>
/// When loading a document, the used <see cref="XmlReader"/> must implement <see cref="IXmlLineInfo"/>.
/// Typical XmlReader implementations like <see cref="XmlTextReader"/> support this interface.
/// </remarks>
/// <author>Erich Eichinger</author>
public class ConfigXmlDocument : XmlDocument
{
/// <summary>
/// Holds the current text position during loading a document
/// </summary>
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();
/// <summary>
/// Get info about the current text position during loading a document.
/// Outside loading a document, the properties of <see cref="CurrentTextPosition"/>
/// will always be <c>null</c>.
/// </summary>
protected ITextPosition CurrentTextPosition
{
get { return _currentTextPositionHolder; }
}
/// <summary>
/// Overridden to create a <see cref="ConfigXmlElement"/> retaining the current
/// text position information.
/// </summary>
public override XmlElement CreateElement(string prefix, string localName, string namespaceURI)
{
return new ConfigXmlElement(this.CurrentTextPosition, prefix, localName, namespaceURI, this);
}
/// <summary>
/// Overridden to create a <see cref="ConfigXmlAttribute"/> retaining the current
/// text position information.
/// </summary>
public override XmlAttribute CreateAttribute(string prefix, string localName, string namespaceURI)
{
return new ConfigXmlAttribute(this.CurrentTextPosition, prefix, localName, namespaceURI, this);
}
/// <summary>
/// Load the document from the given <see cref="XmlReader"/>.
/// Child nodes will store <paramref name="resourceName"/> as their <see cref="ITextPosition.Filename"/> property.
/// </summary>
///<param name="resourceName">the name of the resource</param>
///<param name="xml">The XML source </param>
public void LoadXml(string resourceName, string xml)
{
try
{
_currentTextPositionHolder.CurrentResourceName = resourceName;
base.LoadXml(xml);
}
finally
{
_currentTextPositionHolder.CurrentResourceName = null;
}
}
/// <summary>
/// Load the document from the given <see cref="XmlReader"/>.
/// Child nodes will store <paramref name="resourceName"/> as their <see cref="ITextPosition.Filename"/> property.
/// </summary>
///<param name="resourceName">the name of the resource</param>
///<param name="stream">The XML source </param>
public void Load(string resourceName, Stream stream)
{
try
{
_currentTextPositionHolder.CurrentResourceName = resourceName;
base.Load (stream );
}
finally
{
_currentTextPositionHolder.CurrentResourceName = null;
}
}
/// <summary>
/// Load the document from the given <see cref="XmlReader"/>.
/// Child nodes will store <paramref name="resourceName"/> as their <see cref="ITextPosition.Filename"/> property.
/// </summary>
///<param name="resourceName">the name of the resource</param>
///<param name="reader">The XML source </param>
public void Load(string resourceName, TextReader reader)
{
try
{
_currentTextPositionHolder.CurrentResourceName = resourceName;
base.Load (reader );
}
finally
{
_currentTextPositionHolder.CurrentResourceName = null;
}
}
/// <summary>
/// Load the document from the given <see cref="XmlReader"/>.
/// Child nodes will store <paramref name="resourceName"/> as their <see cref="ITextPosition.Filename"/> property.
/// </summary>
///<param name="resourceName">the name of the resource</param>
///<param name="reader">The XML source </param>
public void Load(string resourceName, XmlReader reader)
{
try
{
_currentTextPositionHolder.CurrentResourceName = resourceName;
this.Load (reader);
}
finally
{
_currentTextPositionHolder.CurrentResourceName = null;
}
}
/// <summary>
/// Load the document from the given <see cref="XmlReader"/>.
/// Child nodes will store <c>null</c> as their <see cref="ITextPosition.Filename"/> property.
/// </summary>
/// <param name="reader">The XML source </param>
public override void Load(XmlReader reader)
{
try
{
_currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
base.Load (reader);
}
finally
{
_currentTextPositionHolder.CurrentXmlLineInfo = null;
}
}
///<summary>
///Creates an <see cref="T:System.Xml.XmlNode"></see> object based on the information in the <see cref="T:System.Xml.XmlReader"></see>. The reader must be positioned on a node or attribute.
///Child nodes will store <paramref name="resourceName"/> as their <see cref="ITextPosition.Filename"/> property.
///</summary>
///<returns>
///The new XmlNode or null if no more nodes exist.
///</returns>
///<param name="resourceName">the name of the resource</param>
///<param name="reader">The XML source </param>
///<exception cref="T:System.InvalidOperationException">The reader is positioned on a node type that does not translate to a valid DOM node (for example, EndElement or EndEntity). </exception>
public XmlNode ReadNode(string resourceName, XmlReader reader)
{
try
{
_currentTextPositionHolder.CurrentResourceName = resourceName;
_currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
return this.ReadNode (reader);
}
finally
{
_currentTextPositionHolder.CurrentXmlLineInfo = null;
}
}
///<summary>
///Creates an <see cref="T:System.Xml.XmlNode"></see> object based on the information in the <see cref="T:System.Xml.XmlReader"></see>. The reader must be positioned on a node or attribute.
///Child nodes will store <c>null</c> as their <see cref="ITextPosition.Filename"/> property.
///</summary>
///<returns>
///The new XmlNode or null if no more nodes exist.
///</returns>
///<param name="reader">The XML source </param>
///<exception cref="T:System.InvalidOperationException">The reader is positioned on a node type that does not translate to a valid DOM node (for example, EndElement or EndEntity). </exception>
public override XmlNode ReadNode(XmlReader reader)
{
try
{
_currentTextPositionHolder.CurrentXmlLineInfo = reader as IXmlLineInfo;
return base.ReadNode (reader);
}
finally
{
_currentTextPositionHolder.CurrentXmlLineInfo = null;
}
}
}
}

View File

@@ -0,0 +1,86 @@
#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.Xml;
#endregion
namespace Spring.Util
{
/// <summary>
/// An <see cref="XmlElement"/> holding information about its original text source location.
/// </summary>
/// <author>Erich Eichinger</author>
public class ConfigXmlElement : XmlElement, ITextPosition
{
private ITextPosition _textPositionInfo;
///<summary>
/// Creates a new instance of <see cref="ConfigXmlElement"/>, storing a copy of the passed
/// <paramref name="currentTextPositionPositionInfo"/>.
///</summary>
public ConfigXmlElement(ITextPosition currentTextPositionPositionInfo, string prefix, string localName, string namespaceURI, XmlDocument doc)
: base(prefix, localName, namespaceURI, doc)
{
_textPositionInfo = new TextPositionInfo(currentTextPositionPositionInfo);
}
/// <summary>
/// The name of the resource this element was read from
/// </summary>
public string Filename
{
get { return _textPositionInfo.Filename; }
}
/// <summary>
/// The line number within the resource this element was read from
/// </summary>
public int LineNumber
{
get { return _textPositionInfo.LineNumber; }
}
/// <summary>
/// The line position within the resource this element was read from.
/// </summary>
public int LinePosition
{
get { return _textPositionInfo.LinePosition; }
}
///<summary>
///Creates a duplicate of this node.
///</summary>
///<param name="deep">true to recursively clone the subtree under the specified node; false to clone only the node itself </param>
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;
}
}
}

View File

@@ -196,6 +196,10 @@ namespace Spring.Util
/// <returns>The line number of the specified node.</returns>
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
/// <returns>The name of the file specified node is defined in.</returns>
public static string GetFileName(XmlNode node)
{
if (node is ITextPosition)
{
return ((ITextPosition)node).Filename;
}
#if !NET_2_0
return ConfigurationException.GetXmlNodeFilename(node);
#else

View File

@@ -0,0 +1,48 @@
using System;
namespace Spring.Util
{
#if NET_2_0
/// <summary>
/// Holds text position information for e.g. error reporting purposes.
/// </summary>
/// <seealso cref="ConfigXmlElement" />
/// <seealso cref="ConfigXmlAttribute" />
public interface ITextPosition : System.Configuration.Internal.IConfigErrorInfo
{
///<summary>
/// Gets a string specifying the file/resource name related to the configuration details.
///</summary>
new string Filename { get; }
///<summary>
/// Gets an integer specifying the line number related to the configuration details.
///</summary>
new int LineNumber { get; }
/// <summary>
/// Gets an integer specifying the line position related to the configuration details.
/// </summary>
int LinePosition { get; }
}
#else
/// <summary>
/// Holds text position information for e.g. error reporting purposes.
/// </summary>
/// <seealso cref="ConfigXmlElement" />
/// <seealso cref="ConfigXmlAttribute" />
public interface ITextPosition
{
/// <summary>
/// Gets a string specifying the file/resource name related to the configuration details.
/// </summary>
string Filename { get; }
/// <summary>
/// Gets an integer specifying the line number related to the configuration details.
/// </summary>
int LineNumber { get; }
/// <summary>
/// Gets an integer specifying the line position related to the configuration details.
/// </summary>
int LinePosition { get; }
}
#endif
}

View File

@@ -0,0 +1,85 @@
#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
#endregion
namespace Spring.Util
{
/// <summary>
/// Holds text position information for e.g. error reporting purposes.
/// </summary>
/// <seealso cref="ConfigXmlElement" />
/// <seealso cref="ConfigXmlAttribute" />
public class TextPositionInfo : ITextPosition
{
private readonly string _filename;
private readonly int _lineNumber;
private readonly int _linePosition;
/// <summary>
/// Creates a new TextPositionInfo instance.
/// </summary>
public TextPositionInfo(string filename, int lineNumber, int linePosition)
{
_filename = filename;
_lineNumber = lineNumber;
_linePosition = linePosition;
}
/// <summary>
/// Creates a new TextPositionInfo instance, copying values from another instance.
/// </summary>
public TextPositionInfo(ITextPosition other)
{
if (other != null)
{
this._filename = other.Filename;
this._lineNumber = other.LineNumber;
this._linePosition = other.LinePosition;
}
}
/// <summary>
/// The filename related to this text position
/// </summary>
public string Filename
{
get { return _filename; }
}
/// <summary>
/// The line number related to this text position
/// </summary>
public int LineNumber
{
get { return _lineNumber; }
}
/// <summary>
/// The line position related to this text position
/// </summary>
public int LinePosition
{
get { return _linePosition; }
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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/");

View File

@@ -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" />

View File

@@ -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;
}

View 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
}
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<objects>
<object>
<property name="" value="" />
</object>
</objects>
</configuration>