Global Convertion from MStest Assert to FluentAssertions

I found that FluentAssertions http://www.fluentassertions.com/ provide more descriptive logs in case of assertion failure.
However most of our test methods use MSTest Assert class.
For example statement
 Assert.IsTrue(string.IsNullOrEmpty(discountItemRecord.DiscountCode));
should  be changed to
(string.IsNullOrEmpty(discountItemRecord.DiscountCode)).Should().BeTrue();
They can be easily converted with the help of Visual Studio Replace. Just  select “use Regular Expressions”
For example
Search for:   \s*Assert.IsTrue\((.*)\);             replace to:      ($1).Should().BeTrue();
Search for:   \s*Assert.IsFalse\((.*)\);            replace to:      ($1).Should().BeFalse();
Search for:   \s*Assert.IsNotNull\((.*)\);        replace to:   ($1).Should().NotBeNull();
Search for:  (\s*)Assert.AreEqual\((.*),(.*)\);replace to:    $1($3).Should().Be($2);
I’ve used only most common asserts,that we are using,but they can be extended for other asserts.
Example of regular expression can be found on regex101

#fluentassertions, #regex, #unit-tests

Advertisements