Skip to content

MSTEST0037 does not handle nullable arguments correctly #7618

@stan-sz

Description

@stan-sz

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>());
}

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions