· resharper visual-studio

Visual Studio/Resharper: Changing the order of arguments

We’ve recently run into some places in our tests where the expectation and actual values passed into NUnit’s ‘Assert.AreEqual’ are the wrong way round, therefore meaning that the error messages we get when tests fail are somewhat confusing!


Assert.AreEqual(theActualValue, "the expectation");

We can change the arguments around using Resharper by using the key combination ‘Ctrl-Alt-Shift-ArrowKey’ but you can only do this one line at a time which was a bit annoying as there were about 20 to change.

I got a bit bored of doing this after a while so I thought I’d look into whether it would be possible to do this with a ‘Find & Replace’.

After a bit of trial and error this is what I’ve ended up with:

The ‘{}’ define a matching group of which we define two in this case and then switch them around. Visual Studio’s regex seems a bit different than the one I’m used to - the reference list for the syntax is available on MSDN.

It’s not too complicated and I’m sure there are edge cases where it wouldn’t work but for the little case I had it did the job reasonably well.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket