Using Resharper to convert to NUnit Fluent Interface?
I want to exclusively use the NUnit Fluent Interface for my unit tests. So en masse I want to convert code like this:
Assert.AreEqual(expected, actual);
To this:
Assert.That(actual, Is.EqualTo(expected));
Is there an easy way to use the plugins to do this? Or is it a feature request? A change like this would be along the lines of suggesting a foreach loop be turned into a LINQ query.
Please sign in to leave a comment.
You'll want to use the structural search and replace feature. They can sort of be thought of as "regular expressions for code". There is even a video of your specific case available here.
Thanks for the excellent video. I was able to do that task in very little time. For anyone doing a search and finding this, I've attached a patterns xml to import to get you started.
One thing I struggled with and couldn't find a solution:
I had a hard time handling format parameters. For example, I couldn't get a good match for this situation:
Assert.AreEqual(expected, actual, "Expecting price to be {0} but it was {1}", expected, actual);
Is this supported?
Attachment(s):
ResharperPatternsCatalog.xml
Use an Argument placeholder to represent the format string and all remaining arguments.