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

[bug] Code fix for NUnit2005 does not correctly fix Assert.AreEqual if named parameters are used in unexpected order #712

Closed
Bartleby2718 opened this issue Mar 31, 2024 · 4 comments · Fixed by #716
Assignees
Labels
Milestone

Comments

@Bartleby2718
Copy link
Contributor

Given the following (note the order of named parameters)

    [Test]
    public void Test1()
    {
        var actual = 1;
        Assert.AreEqual(actual: actual, expected: 1);
    }

NUnit.Analyzers cannot fix NUnit2005 correctly.

The above should suffice, but I also created a repo: https://github.com/Bartleby2718/NUnit2005-Assert-AreEqual-repro

@Bartleby2718 Bartleby2718 changed the title [bug] Assert.AreEqual isn't correctly fixed if named parameters are used in unexpected order [bug] Code fix for NUnit2005 does not correctly fix Assert.AreEqual if named parameters are used in unexpected order Mar 31, 2024
@mikkelbu
Copy link
Member

I guess we need to add some logic to ClassicModelAssertUsageCodeFix, so it will use NameColon if it is supplied, then this will also fix the same issue in other codefixes deriving from this base-class. I'll see if I have time for this next week.

@mikkelbu mikkelbu added the bug label Mar 31, 2024
Bartleby2718 added a commit to Bartleby2718/nunit.analyzers that referenced this issue Mar 31, 2024
…es that the first argument is expected and the second argument is actual
@Bartleby2718
Copy link
Contributor Author

@mikkelbu I just filed a PR for this!

@Bartleby2718
Copy link
Contributor Author

@mikkelbu @manfred-brands Can you assign this issue and the corresponding PR to me?

@manfred-brands
Copy link
Member

@Bartleby2718 Done. I'm in the process of reviewing your PR.

manfred-brands pushed a commit to Bartleby2718/nunit.analyzers that referenced this issue Apr 10, 2024
…es that the first argument is expected and the second argument is actual
manfred-brands added a commit that referenced this issue Apr 12, 2024
…#716)

* Fix #712: AreEqualClassicModelAssertUsageCodeFix no longer assumes that the first argument is expected and the second argument is actual

* Add a new overload for UpdateArguments

* Make all code functional but not yet readable/maintainable

* Refactoring

* Handle out-of-order arguments in all ClassicModelAssertUsageCodeFixes

* Add out-of-order test cases to CollectionAssertUsageCodeFixTests

* Update all other CodeFixTests, fixing CodeFixes to account for bugs found

* Remove an extra whitespace

* Code review changes

* Omit named parameters for the constraint model

* Add test case: two arguments for params in all ClassicAssert tests

* Omit named parameters in StringAssertUsageCodeFix

* Consistently use WithNameColon

Update Tests to remove named parameters

* Code review changes

* We no longer need HasToleranceValue

* We no longer need ComparerParameterIndex

* Update param tags for GetInterpolatedMessageArgumentOrDefault

---------

Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com>
@mikkelbu mikkelbu added this to the Release 4.2 milestone Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants