-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathIDE0058SuppressorTests.cs
More file actions
56 lines (52 loc) · 1.8 KB
/
IDE0058SuppressorTests.cs
File metadata and controls
56 lines (52 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#if ROSLYN_4_10_OR_GREATER
using System.Threading.Tasks;
using Meziantou.Analyzer.Suppressors;
using Microsoft.CodeAnalysis;
using TestHelper;
using Xunit;
namespace Meziantou.Analyzer.Test.Suppressors;
public sealed class IDE0058SuppressorTests
{
private static ProjectBuilder CreateProjectBuilder()
=> new ProjectBuilder()
.WithMicrosoftCodeAnalysisCSharpCodeStyleAnalyzers("IDE0058")
.WithAnalyzer<IDE0058Suppressor>()
.WithOutputKind(OutputKind.ConsoleApplication);
// Ensure the diagnostic is reported without the suppressor
[Fact]
public async Task IDE0058IsReported()
=> await new ProjectBuilder()
.WithMicrosoftCodeAnalysisCSharpCodeStyleAnalyzers("IDE0058")
.WithOutputKind(OutputKind.ConsoleApplication)
.WithSourceCode("""
static void A()
{
[|new System.Text.StringBuilder().Append("Hello")|];
[|System.IO.Directory.CreateDirectory("dir")|];
}
""")
.ValidateAsync();
[Fact]
public async Task StringBuilder_Append()
=> await CreateProjectBuilder()
.WithSourceCode("""
static void A()
{
var sb = new System.Text.StringBuilder();
sb.Append("Hello");
System.Console.WriteLine(sb.ToString());
}
""")
.ValidateAsync();
[Fact]
public async Task Directory_CreateDirectory()
=> await CreateProjectBuilder()
.WithSourceCode("""
static void A()
{
System.IO.Directory.CreateDirectory("dir");
}
""")
.ValidateAsync();
}
#endif