-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathSA1649CSharp10UnitTests.cs
More file actions
63 lines (52 loc) · 2.5 KB
/
SA1649CSharp10UnitTests.cs
File metadata and controls
63 lines (52 loc) · 2.5 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
57
58
59
60
61
62
63
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace StyleCop.Analyzers.Test.CSharp10.DocumentationRules
{
using System.Threading;
using System.Threading.Tasks;
using StyleCop.Analyzers.Test.CSharp9.DocumentationRules;
using StyleCop.Analyzers.Test.Helpers;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<
StyleCop.Analyzers.DocumentationRules.SA1649FileNameMustMatchTypeName>;
public partial class SA1649CSharp10UnitTests : SA1649CSharp9UnitTests
{
/// <summary>
/// Verifies that the file name is based on the first type.
/// </summary>
/// <param name="typeKeyword">The type keyword to use during the test.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Theory]
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
[WorkItem(3435, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3435")]
public async Task VerifyFirstTypeIsUsedWithFileScopedNamespacesAsync(string typeKeyword)
{
var testCode = $@"namespace TestNamespace;
public enum IgnoredEnum {{ }}
public delegate void IgnoredDelegate();
{GetTypeDeclaration(typeKeyword, "TestType", diagnosticKey: 0)}
{GetTypeDeclaration(typeKeyword, "TestType2")}
";
var fixedCode = $@"namespace TestNamespace;
public enum IgnoredEnum {{ }}
public delegate void IgnoredDelegate();
{GetTypeDeclaration(typeKeyword, "TestType")}
{GetTypeDeclaration(typeKeyword, "TestType2")}
";
var expectedDiagnostic = Diagnostic().WithLocation(0);
await VerifyCSharpFixAsync("TestType2.cs", testCode, StyleCopSettings, expectedDiagnostic, "TestType.cs", fixedCode, CancellationToken.None).ConfigureAwait(false);
}
[Fact]
[WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")]
public async Task VerifyMappedLineDirectiveDoesNotChangeFileNameCheckAsync()
{
var testCode = @"#line 1 ""DifferentName.cs""
public class {|#0:NotMatching|}
{
}
#line default";
var expectedDiagnostic = Diagnostic().WithLocation(0);
await VerifyCSharpDiagnosticAsync("ActualFile.cs", testCode, testSettings: null, new[] { expectedDiagnostic }, CancellationToken.None).ConfigureAwait(false);
}
}
}