From: <bo...@us...> - 2007-04-30 13:49:32
|
Revision: 203 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=203&view=rev Author: bodewig Date: 2007-04-30 06:49:32 -0700 (Mon, 30 Apr 2007) Log Message: ----------- Properly check for assertion failures Modified Paths: -------------- trunk/xmlunit/tests/csharp/DiffConfigurationTests.cs trunk/xmlunit/tests/csharp/XmlAssertionTests.cs Modified: trunk/xmlunit/tests/csharp/DiffConfigurationTests.cs =================================================================== --- trunk/xmlunit/tests/csharp/DiffConfigurationTests.cs 2007-04-30 13:40:12 UTC (rev 202) +++ trunk/xmlunit/tests/csharp/DiffConfigurationTests.cs 2007-04-30 13:49:32 UTC (rev 203) @@ -21,7 +21,8 @@ new XmlDiff("", "").OptionalDescription); } - [Test] public void DefaultConfiguredToUseValidatingParser() { + [Test][ExpectedException(typeof(XmlSchemaValidationException))] + public void DefaultConfiguredToUseValidatingParser() { DiffConfiguration diffConfiguration = new DiffConfiguration(); Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER, diffConfiguration.UseValidatingParser); @@ -34,16 +35,14 @@ XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream), new StreamReader(testFileStream)); diff.Compare(); - Assert.Fail("Expected validation failure"); - } catch (XmlSchemaException e) { - string message = e.Message; // to prevent 'unused variable' compiler warning } finally { controlFileStream.Close(); testFileStream.Close(); } } - [Test] public void CanConfigureNotToUseValidatingParser() { + [Test] + public void CanConfigureNotToUseValidatingParser() { DiffConfiguration diffConfiguration = new DiffConfiguration(false); Assert.AreEqual(false, diffConfiguration.UseValidatingParser); Modified: trunk/xmlunit/tests/csharp/XmlAssertionTests.cs =================================================================== --- trunk/xmlunit/tests/csharp/XmlAssertionTests.cs 2007-04-30 13:40:12 UTC (rev 202) +++ trunk/xmlunit/tests/csharp/XmlAssertionTests.cs 2007-04-30 13:49:32 UTC (rev 203) @@ -22,24 +22,30 @@ [Test] public void AssertXmlIdenticalUsesOptionalDescription() { string description = "An Optional Description"; + bool caughtException = true; try { XmlDiff diff = new XmlDiff(new XmlInput("<a/>"), new XmlInput("<b/>"), new DiffConfiguration(description)); XmlAssertion.AssertXmlIdentical(diff); + caughtException = false; } catch (NUnit.Framework.AssertionException e) { Assert.IsTrue(e.Message.StartsWith(description)); } + Assert.IsTrue(caughtException); } [Test] public void AssertXmlEqualsUsesOptionalDescription() { string description = "Another Optional Description"; + bool caughtException = true; try { XmlDiff diff = new XmlDiff(new XmlInput("<a/>"), new XmlInput("<b/>"), new DiffConfiguration(description)); XmlAssertion.AssertXmlEquals(diff); + caughtException = false; } catch (NUnit.Framework.AssertionException e) { Assert.AreEqual(true, e.Message.StartsWith(description)); } + Assert.IsTrue(caughtException); } [Test] public void AssertXmlValidTrueForValidFile() { @@ -53,14 +59,16 @@ [Test] public void AssertXmlValidFalseForInvalidFile() { StreamReader reader = GetStreamReader(ValidatorTests.INVALID_FILE); + bool caughtException = true; try { XmlAssertion.AssertXmlValid(reader); - Assert.Fail("Expected assertion failure"); + caughtException = false; } catch(AssertionException e) { AvoidUnusedVariableCompilerWarning(e); } finally { reader.Close(); } + Assert.IsTrue(caughtException); } private StreamReader GetStreamReader(string file) { @@ -76,13 +84,15 @@ } [Test] public void AssertXPathExistsFailsForNonExistentXPath() { + bool caughtException = true; try { XmlAssertion.AssertXPathExists("//star[@name='alpha centauri']", MY_SOLAR_SYSTEM); - Assert.Fail("Expected assertion failure"); + caughtException = false; } catch (AssertionException e) { AvoidUnusedVariableCompilerWarning(e); } + Assert.IsTrue(caughtException); } [Test] public void AssertXPathEvaluatesToWorksForMatchingExpression() { @@ -127,17 +137,14 @@ StreamReader xml = GetStreamReader(".\\..\\tests\\etc\\testAnimal.xml"); XmlInput xmlToTransform = new XmlInput(xml); XmlInput expectedXml = new XmlInput("<cat/>"); - bool exceptionExpected = true; + bool caughtException = true; try { XmlAssertion.AssertXslTransformResults(xslt, xmlToTransform, expectedXml); - exceptionExpected = false; - Assert.Fail("Expected dog not cat!"); + caughtException = false; } catch (AssertionException e) { AvoidUnusedVariableCompilerWarning(e); - if (!exceptionExpected) { - throw e; - } } + Assert.IsTrue(caughtException); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |