Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MSTEST0037 does not handle nullable arguments correctly #7618

Copy link
Copy link

Description

@stan-sz
Issue body actions

Describe the bug

The fixer for MSTEST0037 is not handling nullable args correctly.

Steps To Reproduce

[TestMethod]
public void TestMethod1()
{
    int? count = 3;
    Assert.AreEqual(count, new List<string>().Count);
}

Applying the fixer yields:

[TestMethod]
public void TestMethod1()
{
    int? count = 3;
    Assert.HasCount(count, new List<string>());
}

but this yields

CS1503 Argument 1: cannot convert from 'int?' to 'int'

The proper fix should be

[TestMethod]
public void TestMethod1()
{
    int? count = 3;
    Assert.IsTrue(count.HasValue); // or Assert.IsNotNull(count)
    Assert.HasCount(count.Value, new List<string>());
}
Reactions are currently unavailable

Metadata

Metadata

Labels

area/analyzersMSTest.Analyzers Roslyn analyzers and code fixes.MSTest.Analyzers Roslyn analyzers and code fixes.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.