fluentassertions.analyzers icon indicating copy to clipboard operation
fluentassertions.analyzers copied to clipboard

Suggestions to use fluent assertions instead of MSTest Asserts do not work if Assert is not on the top level of nesting in a test method

Open robertMSFTE opened this issue 3 years ago • 0 comments

Description

Newly added functionality enabling easy move from MSTest Asserts to fluent assertions does not work if Assert is not on the top level of nesting in a test method.

Complete minimal example reproducing the issue

This will get a suggestion:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Assert.AreEqual(1, 1);
        }
    }
}

But this will not:

namespace TestProject1
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            if (true == true)
            {
                Assert.AreEqual(1, 1);
            }
        }
    }
}

Expected behavior:

Suggestion to use fluent assertions instead of Assert is shown when Assert is not on the top level of nesting in a test method.

Actual behavior:

Suggestion to use fluent assertions instead of Assert is not shown when Assert is not on the top level of nesting in a test method.

Versions

  • Which version of Fluent Assertions Analyzers are you using? FluentAssertions.Analyzers 0.17.2
  • Which .NET runtime and version are you targeting? .NET Core 3.1.

robertMSFTE avatar Apr 04 '22 22:04 robertMSFTE