I am trying to do a general Assert.AreEqual
call on some details in a table header, however I am struggling figuring out how to successfully format the expected results. The return value on the GetTableHeader
call is as follows:
"× •••\r\nAcme Health Fund\r\nBalance Date: 9/27/2017"
I ONLY want to assert that the Acme Health Fund text is present. My current call is this:
Assert.AreEqual("/.*Acme Health Fund.*/" , GetTableHeader() );
How can I format my first parameter in the AreEqual
call to ONLY expect "Acme Health Fund"
?
In regular expressions, the period ( . , also called "dot") is the wildcard pattern which matches any single character. Combined with the asterisk operator . * it will match any number of any characters.
Wildcards are different from the regular expressions used in grep (although they may look similar at times). Wildcards apply to all commands including grep and are used in place of or in combination with operands. Regular Expressions only apply to grep and a few other UNIX commands.
NUnit 3 has a much more powerful constraint syntax, I would recommend you use that instead. New features are added to the constraint syntax, not to the old Assert.AreEqual
style.
Regex is overkill for what you want, all you need to do is assert that the string Does.Contain
the name.
Assert.That(GetTableHeader(), Does.Contain("Acme Health Fund"));
If you really need to use a regex, first you don't need to surround it in the slashes and you use the Does.Match
syntax.
Assert.That(GetTableHeader(), Does.Match(".*Acme Health Fund.*"));
Note the fix in your regex.
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