I tried writing the following TestCase for an NUnit test written in VB.net:
<TestCase("FirstNode", "<node id=\"FirstNode\">")> Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String, ByVal expectedXml as String) (Call the method under test and request the xmlNode with the provided id...) Assert.AreEqual(expectedXml, returnedXml) End Sub
The xml-node passed as the second parameter to the testcase is not valid however, as this clearly is not the correct way to escape double quotes. I'm sure I can find a workaround in order to check that the method under test returns the expected XML-node, but I'm curious:
Is there some clever way to pass a string such as this, containing double quotes, as a parameter to an NUnit test?
C# Language Verbatim Strings Escaping Double Quotes Double Quotes inside verbatim strings can be escaped by using 2 sequential double quotes "" to represent one double quote " in the resulting string.
Escaping double quotes with a double quote. To display a double quote, you need to escape the inner double quotes. Normally in most of the languages, the escape character is backslash ( \ ). In VBScript, the escape character is a double quote ( ” ) itself.
The correct way to escape double-quotes in VB is by doubling the double-quotes:
<TestCase("FirstNode", "<node id=""FirstNode"">")>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With