From: <bo...@us...> - 2014-11-29 17:37:37
|
Revision: 555 http://sourceforge.net/p/xmlunit/code/555 Author: bodewig Date: 2014-11-29 17:37:30 +0000 (Sat, 29 Nov 2014) Log Message: ----------- System.Xml.Linq may provide input as well Modified Paths: -------------- trunk/xmlunit/src/main/net-core/builder/Input.cs trunk/xmlunit/src/tests/net-core/builder/InputTest.cs trunk/xmlunit/xmlunit.nant.build Added Paths: ----------- trunk/xmlunit/src/main/net-core/input/LinqSource.cs Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2014-11-29 16:35:47 UTC (rev 554) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2014-11-29 17:37:30 UTC (rev 555) @@ -14,6 +14,7 @@ using System; using System.IO; using System.Xml; +using System.Xml.Linq; using net.sf.xmlunit.exceptions; using net.sf.xmlunit.input; @@ -171,5 +172,30 @@ public static ITransformationBuilder ByTransforming(IBuilder b) { return ByTransforming(b.Build()); } + + internal class LinqBuilder : IBuilder { + private readonly ISource source; + internal LinqBuilder(XNode d) { + source = new LinqSource(d); + } + public ISource Build() { + return source; + } + } + + /// <summary> + /// Build an ISource from a System.Xml.Linq Document. + /// </summary> + public static IBuilder FromDocument(XDocument d) { + return new LinqBuilder(d); + } + + /// <summary> + /// Build an ISource from a System.Xml.Linq Node. + /// </summary> + public static IBuilder FromNode(XNode n) { + return new LinqBuilder(n); + } + } } Copied: trunk/xmlunit/src/main/net-core/input/LinqSource.cs (from rev 546, trunk/xmlunit/src/main/net-core/input/DOMSource.cs) =================================================================== --- trunk/xmlunit/src/main/net-core/input/LinqSource.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/input/LinqSource.cs 2014-11-29 17:37:30 UTC (rev 555) @@ -0,0 +1,36 @@ +/* + This file is licensed to You 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. +*/ +using System.Xml.Linq; + +namespace net.sf.xmlunit.input { + /// <summary> + /// ISource implementation encapsulating a System.Xml.Linq XNode. + /// </summary> + public class LinqSource : AbstractSource { + private readonly XNode node; + public LinqSource(XNode node) + : base(node.CreateReader()) { + this.node = node; + } + + /// <summary> + /// The node this source is wrapping + /// </summary> + public XNode Node { + get { + return node; + } + } + } +} Modified: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2014-11-29 16:35:47 UTC (rev 554) +++ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2014-11-29 17:37:30 UTC (rev 555) @@ -15,6 +15,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Linq; using NUnit.Framework; namespace net.sf.xmlunit.builder { @@ -28,12 +29,22 @@ return d; } + private static XDocument XParse(ISource s) { + return XDocument.Load(s.Reader); + } + [Test] public void ShouldParseADocument() { XmlDocument d = Parse(Input.FromFile(TestResources.ANIMAL_FILE) .Build()); AllIsWellFor(Input.FromDocument(d).Build()); } + [Test] public void ShouldParseAnXDocument() { + XDocument d = XParse(Input.FromFile(TestResources.ANIMAL_FILE) + .Build()); + AllIsWellFor(Input.FromDocument(d).Build()); + } + [Test] public void ShouldParseAnExistingFileByName() { ISource s = Input.FromFile(TestResources.ANIMAL_FILE).Build(); AllIsWellFor(s); Modified: trunk/xmlunit/xmlunit.nant.build =================================================================== --- trunk/xmlunit/xmlunit.nant.build 2014-11-29 16:35:47 UTC (rev 554) +++ trunk/xmlunit/xmlunit.nant.build 2014-11-29 17:37:30 UTC (rev 555) @@ -83,6 +83,9 @@ <include name="${gen.core.dir}**/*.cs"/> <include name="${core.src.dir}/**/*.cs"/> </sources> + <references> + <include name="System.Xml.Linq.dll"/> + </references> </csc> </target> @@ -129,6 +132,7 @@ <references basedir="${bin.dir}"> <include name="${project::get-name()}-core.dll"/> <include name="${nunit.v2.assembly}"/> + <include name="System.Xml.Linq.dll"/> </references> <sources basedir="${core.tests.src.dir}"> <include name="**/*.cs"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |