This commit is contained in:
Enji Eid 2024-07-03 16:14:01 +02:00
Родитель d1351a1ca1
Коммит 338aef8139
1 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier<
MSTest.Analyzers.UseNullableForIsNullAndIsNotNullAssertionsAnalyzer,
Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>;
namespace MSTest.Analyzers.Test;
[TestGroup]
public sealed class UseNullableForIsNullAndIsNotNullAssertionsAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext)
{
public async Task WhenIsNullAssertion_ValueParameterIsNullable_NoDiagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class MyTestClass
{
[TestMethod]
public void MyTestMethod()
{
string? var = null;
Assert.IsNull(var);
}
}
""";
await VerifyCS.VerifyAnalyzerAsync(code);
}
public async Task WhenIsNullAssertion_ValueParameterIsNotNullable_Diagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class MyTestClass
{
[TestMethod]
public void MyTestMethod()
{
string var = "value";
Assert.[|IsNull|](var);
}
}
""";
await VerifyCS.VerifyAnalyzerAsync(code);
}
}