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 "using Microsoft.VisualStudio.TestTools.UnitTesting;" is located inside of the namespace. #152

Closed
robertMSFTE opened this issue Mar 30, 2022 · 8 comments · Fixed by #154 or #157

Comments

@robertMSFTE
Copy link

robertMSFTE commented Mar 30, 2022

Description

Newly added functionality enabling easy move from MSTest Asserts to fluent assertions does not work if "using Microsoft.VisualStudio.TestTools.UnitTesting;" is located inside of the namespace.

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()
        {
            Assert.AreEqual(1, 1);
        }
    }
}

Expected behavior:

Suggestion to use fluent assertions instead of Assert is shown when "using Microsoft.VisualStudio.TestTools.UnitTesting;" is located inside of the namespace.

Actual behavior:

Suggestion to use fluent assertions instead of Assert is not shown when "using Microsoft.VisualStudio.TestTools.UnitTesting;" is located inside of the namespace.

Versions

  • Which version of Fluent Assertions Analyzers are you using? FluentAssertions.Analyzers 0.16.0
  • Which .NET runtime and version are you targeting? .NET Core 3.1.
@Meir017
Copy link
Member

Meir017 commented Mar 31, 2022

@robertMSFTE version 0.17.0 was just release

@robertMSFTE
Copy link
Author

Awesome :)
Thank you on the extremely quick turnaround!

@robertMSFTE
Copy link
Author

@Meir017 I've tried version 0.17.0 and it seems in that version I am not getting suggestions in either case.

Also seems like something is wrong with the package metadata FluentAssertions.Analyzers.

image

Let me know if you want for me to create a new issue.

@Meir017
Copy link
Member

Meir017 commented Apr 1, 2022

@robertMSFTE just published version 0.17.1 with fixed package

@robertMSFTE
Copy link
Author

robertMSFTE commented Apr 1, 2022

@Meir017 After updating to 0.17.1 the package information issue seems to be fixed. But sadly, the issue from the original post still reproduces (aka. if the using is inside of the namespace then we don't get the suggestion).

@Meir017
Copy link
Member

Meir017 commented Apr 1, 2022

@robertMSFTE my bad, My fix only worked when the namespace is part of the unit testing library's namespace
something like this:

namespace Microsoft
{
    using VisualStudio.TestTools.UnitTesting;

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

fix coming up

@Meir017
Copy link
Member

Meir017 commented Apr 1, 2022

@robertMSFTE should be working now with version 0.17.2

@robertMSFTE
Copy link
Author

@Meir017 Just tested. Seems like my example works right now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants