Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape double quotes in as a parameter to an NUnit TestCase?

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?

like image 325
Kjartan Avatar asked Oct 11 '11 12:10

Kjartan


People also ask

How do you escape double quotes in C#?

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.

How do you escape double quotes in a string in VB net?

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.


1 Answers

The correct way to escape double-quotes in VB is by doubling the double-quotes:

<TestCase("FirstNode", "<node id=""FirstNode"">")> 
like image 52
Meta-Knight Avatar answered Oct 15 '22 17:10

Meta-Knight