From: <bo...@us...> - 2009-05-20 15:47:31
|
Revision: 331 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=331&view=rev Author: bodewig Date: 2009-05-20 15:47:19 +0000 (Wed, 20 May 2009) Log Message: ----------- port input builder test to .NET Modified Paths: -------------- trunk/xmlunit/xmlunit.nant.build Added Paths: ----------- trunk/xmlunit/src/tests/net-core/ trunk/xmlunit/src/tests/net-core/builder/ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs Copied: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs (from rev 329, trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/builder/InputTest.java) =================================================================== --- trunk/xmlunit/src/tests/net-core/builder/InputTest.cs (rev 0) +++ trunk/xmlunit/src/tests/net-core/builder/InputTest.cs 2009-05-20 15:47:19 UTC (rev 331) @@ -0,0 +1,106 @@ +/* + 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; +using System.IO; +using System.Text; +using System.Xml; +using NUnit.Framework; + +namespace net.sf.xmlunit.builder { + +[TestFixture] +public class InputTest { + + private const string TEST_FILE = "../../../src/tests/resources/test1.xml"; + + private static XmlDocument Parse(ISource s) { + XmlDocument d = new XmlDocument(); + d.Load(s.Reader); + return d; + } + + [Test] public void ShouldParseADocument() { + XmlDocument d = Parse(Input.FromFile(TEST_FILE).Build()); + AllIsWellFor(Input.FromDocument(d).Build()); + } + + [Test] public void ShouldParseAnExistingFileByName() { + AllIsWellFor(Input.FromFile(TEST_FILE).Build()); + } + + [Test] public void ShouldParseAnExistingFileFromStream() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) { + AllIsWellFor(Input.FromStream(fs).Build()); + } + } + + [Test] public void ShouldParseAnExistingFileFromReader() { + using (StreamReader r = new StreamReader(TEST_FILE)) { + AllIsWellFor(Input.FromReader(r).Build()); + } + } + + [Test] public void ShouldParseString() { + AllIsWellFor(Input.FromMemory(Encoding.UTF8.GetString(ReadTestFile())) + .Build()); + } + + [Test] public void ShouldParseBytes() { + AllIsWellFor(Input.FromMemory(ReadTestFile()).Build()); + } + + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURIString() { + AllIsWellFor(Input.FromURI("file:" + TEST_FILE).Build()); + } + + [Ignore("looks as if file-URIs didn't work, revisit")] + [Test] public void ShouldParseFileFromURI() { + AllIsWellFor(Input.FromURI(new Uri("file:" + TEST_FILE)).Build()); + } + + [Test] public void ShouldParseATransformation() { + ISource input = Input.FromMemory("<animal>furry</animal>").Build(); + ISource s = Input.ByTransforming(input) + .WithStylesheet(Input.FromFile("../../../src/tests/resources/animal.xsl") + .Build()) + .Build(); + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("furry")); + } + + private static void AllIsWellFor(ISource s) { + Assert.That(s, Is.Not.Null); + XmlDocument d = Parse(s); + Assert.That(d, Is.Not.Null); + Assert.That(d.DocumentElement.Name, Is.EqualTo("animal")); + } + + private static byte[] ReadTestFile() { + using (FileStream fs = new FileStream(TEST_FILE, FileMode.Open, + FileAccess.Read)) + using (MemoryStream ms = new MemoryStream()) { + byte[] buffer = new byte[1024]; + int read = -1; + while ((read = fs.Read(buffer, 0, buffer.Length)) > 0) { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } +} +} \ No newline at end of file Property changes on: trunk/xmlunit/src/tests/net-core/builder/InputTest.cs ___________________________________________________________________ Added: svn:mergeinfo + Added: svn:eol-style + native Modified: trunk/xmlunit/xmlunit.nant.build =================================================================== --- trunk/xmlunit/xmlunit.nant.build 2009-05-20 15:24:44 UTC (rev 330) +++ trunk/xmlunit/xmlunit.nant.build 2009-05-20 15:47:19 UTC (rev 331) @@ -4,8 +4,10 @@ overwrite="false"/> <property name="core.src.dir" value="${base.dir}/src/main/net-core" overwrite="false"/> <property name="legacy.src.dir" value="${base.dir}/src/main/net-legacy" overwrite="false"/> - <property name="tests.src.dir" value="${base.dir}/src/tests/net-legacy" + <property name="core.tests.src.dir" value="${base.dir}/src/tests/net-core" overwrite="false"/> + <property name="legacy.tests.src.dir" value="${base.dir}/src/tests/net-legacy" + overwrite="false"/> <property name="build.dir" value="${base.dir}/build/net" overwrite="false"/> <property name="bin.dir" value="${build.dir}/bin" overwrite="false"/> @@ -56,14 +58,25 @@ </csc> <csc target="library" - output="${bin.dir}/${project::get-name()}.tests.dll" + output="${bin.dir}/${project::get-name()}-core.tests.dll" debug="true" verbose="${csc.verbose}"> <references basedir="${bin.dir}"> <include name="${project::get-name()}-core.dll"/> + <include name="${nunit.v2.assembly}"/> + </references> + <sources basedir="${core.tests.src.dir}"> + <include name="**/*.cs"/> + </sources> + </csc> + <csc target="library" + output="${bin.dir}/${project::get-name()}-legacy.tests.dll" + debug="true" verbose="${csc.verbose}"> + <references basedir="${bin.dir}"> + <include name="${project::get-name()}-core.dll"/> <include name="${project::get-name()}-legacy.dll"/> <include name="${nunit.v2.assembly}"/> </references> - <sources basedir="${tests.src.dir}"> + <sources basedir="${legacy.tests.src.dir}"> <include name="*.cs"/> <exclude name="AllTests.cs"/> </sources> @@ -73,7 +86,8 @@ <target name="test" description="run all tests" depends="compile"> <nunit2> <formatter type="Plain"/> - <test assemblyname="${bin.dir}/${project::get-name()}.tests.dll"/> + <test assemblyname="${bin.dir}/${project::get-name()}-core.tests.dll"/> + <test assemblyname="${bin.dir}/${project::get-name()}-legacy.tests.dll"/> </nunit2> </target> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |