Skip to content

MSTEST0037 [DoesNot]Starts/EndsWith unhandled char case #7205

@LukasGelke

Description

@LukasGelke

Describe the bug

The codefix ignores the case of string.StartsWith(char)

Steps To Reproduce

[TestMethod]
public void TestMethod2()
{
  string myText = "abc";
  Assert.IsTrue(myText.StartsWith('a'));
}

Expected behavior

a)

[TestMethod]
public void TestMethod2()
{
  string myText = "abc";
  Assert.StartsWith("a", myText);
}

or b)
overloads akin to StartsWith(char substring, string? value, ..., which would also solve the problem with chars in variables

Actual behavior

[TestMethod]
public void TestMethod2()
{
  string myText = "abc";
  Assert.StartsWith('a', myText);
  //                ^^^--- Error CS1503 Argument 1: cannot convert from 'char' to 'string?'
}

Additional context

prior analyzers complained about a string with a single char inside the .Contains(..) method

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions