-
Notifications
You must be signed in to change notification settings - Fork 291
Closed
Description
The following analyzer unit test should pass
[TestMethod]
public async Task WhenUsingConditionalsAccess_In_Message_NoDiagnostic()
{
string code = """
#nullable enable
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
public class A
{
public string? S { get; set; }
public Regex? R { get; set; }
}
[TestClass]
public class MyTestClass
{
[TestMethod]
public void Compliant()
{
Assert.AreEqual(new object(), new object(), new A().S?.Length.ToString());
}
}
""";
await VerifyCS.VerifyAnalyzerAsync(code);
}But it fails:
Test method MSTest.Analyzers.UnitTests.AssertionArgsShouldAvoidConditionalAccessAnalyzerTests.WhenUsingConditionalsAccess_In_Message_NoDiagnostic threw exception:
System.InvalidOperationException: Context: Diagnostics of test state
Mismatch between number of diagnostics returned, expected "0" actual "1"
Diagnostics:
// /0/Test0.cs(18,9): info MSTEST0026: Prefer adding an additional assertion that checks for null
VerifyCS.Diagnostic().WithSpan(18, 9, 18, 82),