spectre.console/src/Spectre.Console.Tests/CodeAnalyzer/Analyzers/UseSpectreInsteadOfSystemConsoleAnalyzerTests.cs
Phil Scott 4f293d887d Adding analyzer project
Contains two analyzers with fixes

* Use AnsiConsole over System.Console
* Favor local instance over static implementation
2021-06-23 16:36:48 +02:00

53 lines
1.4 KiB
C#

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Spectre.Console.Analyzer;
using Xunit;
using AnalyzerVerify =
Spectre.Console.Tests.CodeAnalyzers.SpectreAnalyzerVerifier<
Spectre.Console.Analyzer.UseSpectreInsteadOfSystemConsoleAnalyzer>;
namespace Spectre.Console.Tests.CodeAnalyzers.Analyzers
{
public class UseSpectreInsteadOfSystemConsoleAnalyzerTests
{
private static readonly DiagnosticResult _expectedDiagnostics = new(
Descriptors.S1000_UseAnsiConsoleOverSystemConsole.Id,
DiagnosticSeverity.Warning);
[Fact]
public async void Console_Write_Has_Warning()
{
const string Source = @"
using System;
class TestClass {
void TestMethod()
{
Console.Write(""Hello, World"");
}
}";
await AnalyzerVerify
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9))
.ConfigureAwait(false);
}
[Fact]
public async void Console_WriteLine_Has_Warning()
{
const string Source = @"
using System;
class TestClass
{
void TestMethod() {
Console.WriteLine(""Hello, World"");
}
}";
await AnalyzerVerify
.VerifyAnalyzerAsync(Source, _expectedDiagnostics.WithLocation(7, 9))
.ConfigureAwait(false);
}
}
}