Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #159

Closed
robertMSFTE opened this issue Apr 4, 2022 · 1 comment

Comments

@robertMSFTE
Copy link

robertMSFTE commented Apr 4, 2022

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 robertMSFTE changed the title uggestions 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 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 Apr 4, 2022
@Meir017
Copy link
Member

Meir017 commented May 27, 2023

@robertMSFTE this is working in v0.18.0

@Meir017 Meir017 closed this as completed May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants