From: Oleg T. <he...@us...> - 2004-10-13 17:47:09
|
Update of /cvsroot/mvp-xml/XInclude/v1/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6609/v1/test Modified Files: XIncludeTest.csproj Added Files: XIncludeReaderTests.cs XIncludeSyntaxTests.cs Log Message: Added some basic tests. Index: XIncludeTest.csproj =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/test/XIncludeTest.csproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XIncludeTest.csproj 29 Sep 2004 07:46:16 -0000 1.1 +++ XIncludeTest.csproj 13 Oct 2004 17:46:59 -0000 1.2 @@ -9,7 +9,7 @@ <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" - AssemblyName = "XIncludeTest" + AssemblyName = "Mvp.Xml.XInclude.Test" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" @@ -18,7 +18,7 @@ OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" - RootNamespace = "XIncludeTest" + RootNamespace = "Mvp.Xml.XInclude.Test" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > @@ -79,11 +79,80 @@ AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> + <Reference + Name = "nunit.framework" + AssemblyName = "nunit.framework" + HintPath = "..\..\..\..\..\Program Files\NUnit 2.2\bin\nunit.framework.dll" + AssemblyFolderKey = "hklm\dn\nunit.framework" + /> + <Reference + Name = "XInclude" + Project = "{3750FAB1-FD0E-425A-9DAA-87543A556319}" + Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" + /> </References> </Build> <Files> <Include> <File + RelPath = "XIncludeReaderTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "XIncludeSyntaxTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "tests\binary.bin" + BuildAction = "None" + /> + <File + RelPath = "tests\disclaimer.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\document.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\fallbacknotchildinclude.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\filenotfound.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\includechildofinclude.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\includesitself.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\nohref.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\nonxmlchar.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\result.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\twofallbacks.xml" + BuildAction = "Content" + /> + <File + RelPath = "tests\unknownparseattr.xml" + BuildAction = "Content" + /> + <File RelPath = "XInclude-Test-Suite\README.cvs" BuildAction = "None" /> --- NEW FILE: XIncludeReaderTests.cs --- using System; using System.Diagnostics; using System.Xml; using System.IO; using System.Text; using Mvp.Xml.XInclude; using NUnit.Framework; namespace Mvp.Xml.XInclude.Test { /// <summary> /// XIncludeReader general tests. /// </summary> [TestFixture] public class XIncludeReaderTests { public XIncludeReaderTests() { Debug.Listeners.Add(new TextWriterTraceListener(Console.Error)); } /// <summary> /// Utility method for running tests. /// </summary> public static void RunAndCompare(string source, string result) { XIncludingReader xir = new XIncludingReader(source); XmlDocument doc = new XmlDocument(); doc.Load(xir); MemoryStream ms = new MemoryStream(); doc.Save(new StreamWriter(ms, Encoding.UTF8)); ms.Position = 0; string actualResult = new StreamReader(ms).ReadToEnd(); StreamReader sr = new StreamReader(result); string expectedResult = sr.ReadToEnd(); sr.Close(); if (actualResult != expectedResult) { Console.WriteLine("Actual Result was {0}", actualResult); Console.WriteLine("Expected Result was {0}", expectedResult); } Assert.IsTrue(actualResult == expectedResult); } /// <summary> /// General test - it should work actually. /// </summary> [Test] public void ItWorksAtLeast() { RunAndCompare("../../tests/document.xml", "../../tests/result.xml"); } /// <summary> /// Non XML character in the included document. /// </summary> [Test] [ExpectedException(typeof(NonXmlCharacterException))] public void NonXMLChar() { RunAndCompare("../../tests/nonxmlchar.xml", "../../tests/result.xml"); } /// <summary> /// File not found and no fallback. /// </summary> [Test] [ExpectedException(typeof(FatalResourceException))] public void FileNotFound() { RunAndCompare("../../tests/filenotfound.xml", "../../tests/result.xml"); } /// <summary> /// Circular inclusion. /// </summary> [Test] [ExpectedException(typeof(CircularInclusionException))] public void IncludesItself() { RunAndCompare("../../tests/includesitself.xml", "../../tests/result.xml"); } } } --- NEW FILE: XIncludeSyntaxTests.cs --- using System; using System.Diagnostics; using Mvp.Xml.XInclude; using NUnit.Framework; namespace Mvp.Xml.XInclude.Test { /// <summary> /// XInclude syntax tests. /// </summary> [TestFixture] public class XIncludeSyntaxTests { public XIncludeSyntaxTests() { Debug.Listeners.Add(new TextWriterTraceListener(Console.Error)); } /// <summary> /// No href and no xpointer attribute. /// </summary> [Test] [ExpectedException(typeof(MissingHrefAndXpointerException))] public void NoHrefAndNoXPointerAttributes() { XIncludingReader xir = new XIncludingReader("../../tests/nohref.xml"); while (xir.Read()); xir.Close(); } /// <summary> /// xi:include child of xi:include. /// </summary> [Test] [ExpectedException(typeof(SyntaxError))] public void IncludeChildOfInclude() { XIncludingReader xir = new XIncludingReader("../../tests/includechildofinclude.xml"); while (xir.Read()); xir.Close(); } /// <summary> /// xi:fallback not child of xi:include. /// </summary> [Test] [ExpectedException(typeof(SyntaxError))] public void FallbackNotChildOfInclude() { XIncludingReader xir = new XIncludingReader("../../tests/fallbacknotchildinclude.xml"); while (xir.Read()); xir.Close(); } /// <summary> /// Unknown value of parse attribute. /// </summary> [Test] [ExpectedException(typeof(UnknownParseAttributeValueException))] public void UnknownParseAttribute() { XIncludingReader xir = new XIncludingReader("../../tests/unknownparseattr.xml"); while (xir.Read()); xir.Close(); } /// <summary> /// Two xi:fallback. /// </summary> [Test] [ExpectedException(typeof(SyntaxError))] public void TwoFallbacks() { XIncludingReader xir = new XIncludingReader("../../tests/twofallbacks.xml"); while (xir.Read()); xir.Close(); } } } |