├── .gitignore
├── LICENSE
├── README.md
├── UnitTestAnalyzers.sln
└── UnitTestAnalyzers
├── UnitTestAnalyzers.Test
├── App.config
├── Design
│ └── TestNameMustIncludeMemberUnderTestFunctionalTests.cs
├── Documentation
│ └── UseAAACommentsFunctionalTests.cs
├── GlobalSuppressions.cs
├── Helpers
│ ├── DiagnosticResult.cs
│ └── DiagnosticVerifier.Helper.cs
├── Naming
│ ├── UseCorrectTestNameFormatFunctionalTests.cs
│ └── UseUnitTestsSuffixFunctionalTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── TestData
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerMSTestInvalidData.cs
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerMSTestValidData.cs
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerNUnitTestInvalidData.cs
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerNUnitTestValidData.cs
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerXunitTestInvalidData.cs
│ ├── TestNameMustIncludeMemberUnderTestAnalyzerXunitTestValidData.cs
│ ├── TestSettingsData.cs
│ ├── UseAAACommentsAnalyzerMSTestInvalidData.cs
│ ├── UseAAACommentsAnalyzerMSTestValidData.cs
│ ├── UseAAACommentsAnalyzerNUnitTestInvalidData.cs
│ ├── UseAAACommentsAnalyzerNUnitTestValidData.cs
│ ├── UseAAACommentsAnalyzerXunitTestInvalidData.cs
│ ├── UseAAACommentsAnalyzerXunitTestValidData.cs
│ ├── UseCorrectTestNameFormatMSTestInvalidData.cs
│ ├── UseCorrectTestNameFormatMSTestValidData.cs
│ ├── UseCorrectTestNameFormatNUnitTestInvalidData.cs
│ ├── UseCorrectTestNameFormatNUnitTestValidData.cs
│ ├── UseCorrectTestNameFormatXunitTestInvalidData.cs
│ ├── UseCorrectTestNameFormatXunitTestValidData.cs
│ ├── UseUnitTestsSuffixMSTestInvalidData.cs
│ ├── UseUnitTestsSuffixMSTestValidData.cs
│ ├── UseUnitTestsSuffixNUnitTestInvalidData.cs
│ ├── UseUnitTestsSuffixNUnitTestValidData.cs
│ ├── UseUnitTestsSuffixXunitTestValidData.cs
│ └── UseUnitTestsSuffixxUnitTestInvalidData.cs
├── UnitTestAnalyzers.FunctionalTests.csproj
├── Verifiers
│ └── DiagnosticVerifier.cs
└── packages.config
├── UnitTestAnalyzers.Vsix
├── UnitTestAnalyzers.Vsix.csproj
└── source.extension.vsixmanifest
└── UnitTestAnalyzers
├── Design
└── TestNameMustIncludeMemberUnderTestAnalyzer.cs
├── Documentation
└── UseAAACommentsAnalyzer.cs
├── GlobalSuppressions.cs
├── Naming
├── UseCorrectTestNameFormatAnalyzer.cs
└── UseUnitTestsSuffixAnalyzer.cs
├── Parsers
├── AttributeBasedTestParser.cs
├── IUnitTestParser.cs
├── MSTestParser.cs
├── NUnitTestParser.cs
├── UnitTestParserFactory.cs
└── XUnitTestParser.cs
├── Properties
└── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings
├── ObjectModel
│ ├── AnalyzersSettings.cs
│ ├── SettingsFile.cs
│ └── UnitTestFramework.cs
├── SettingsProvider.cs
└── SettingsReader.cs
├── UnitTestAnalyzers.csproj
└── packages.config
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 |
24 | # Visual Studio 2015 cache/options directory
25 | .vs/
26 | # Uncomment if you have tasks that create the project's static files in wwwroot
27 | #wwwroot/
28 |
29 | # MSTest test Results
30 | [Tt]est[Rr]esult*/
31 | [Bb]uild[Ll]og.*
32 |
33 | # NUNIT
34 | *.VisualState.xml
35 | TestResult.xml
36 |
37 | # Build Results of an ATL Project
38 | [Dd]ebugPS/
39 | [Rr]eleasePS/
40 | dlldata.c
41 |
42 | # DNX
43 | project.lock.json
44 | artifacts/
45 |
46 | *_i.c
47 | *_p.c
48 | *_i.h
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.tmp_proj
63 | *.log
64 | *.vspscc
65 | *.vssscc
66 | .builds
67 | *.pidb
68 | *.svclog
69 | *.scc
70 |
71 | # Chutzpah Test files
72 | _Chutzpah*
73 |
74 | # Visual C++ cache files
75 | ipch/
76 | *.aps
77 | *.ncb
78 | *.opendb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 | # NuGet v3's project.json files produces more ignoreable files
154 | *.nuget.props
155 | *.nuget.targets
156 |
157 | # Microsoft Azure Build Output
158 | csx/
159 | *.build.csdef
160 |
161 | # Microsoft Azure Emulator
162 | ecf/
163 | rcf/
164 |
165 | # Microsoft Azure ApplicationInsights config file
166 | ApplicationInsights.config
167 |
168 | # Windows Store app package directory
169 | AppPackages/
170 | BundleArtifacts/
171 |
172 | # Visual Studio cache files
173 | # files ending in .cache can be ignored
174 | *.[Cc]ache
175 | # but keep track of directories ending in .cache
176 | !*.[Cc]ache/
177 |
178 | # Others
179 | ClientBin/
180 | ~$*
181 | *~
182 | *.dbmdl
183 | *.dbproj.schemaview
184 | *.pfx
185 | *.publishsettings
186 | node_modules/
187 | orleans.codegen.cs
188 |
189 | # RIA/Silverlight projects
190 | Generated_Code/
191 |
192 | # Backup & report files from converting an old project file
193 | # to a newer Visual Studio version. Backup files are not needed,
194 | # because we have git ;-)
195 | _UpgradeReport_Files/
196 | Backup*/
197 | UpgradeLog*.XML
198 | UpgradeLog*.htm
199 |
200 | # SQL Server files
201 | *.mdf
202 | *.ldf
203 |
204 | # Business Intelligence projects
205 | *.rdl.data
206 | *.bim.layout
207 | *.bim_*.settings
208 |
209 | # Microsoft Fakes
210 | FakesAssemblies/
211 |
212 | # GhostDoc plugin setting file
213 | *.GhostDoc.xml
214 |
215 | # Node.js Tools for Visual Studio
216 | .ntvs_analysis.dat
217 |
218 | # Visual Studio 6 build log
219 | *.plg
220 |
221 | # Visual Studio 6 workspace options file
222 | *.opt
223 |
224 | # Visual Studio LightSwitch build output
225 | **/*.HTMLClient/GeneratedArtifacts
226 | **/*.DesktopClient/GeneratedArtifacts
227 | **/*.DesktopClient/ModelManifest.xml
228 | **/*.Server/GeneratedArtifacts
229 | **/*.Server/ModelManifest.xml
230 | _Pvt_Extensions
231 |
232 | # Paket dependency manager
233 | .paket/paket.exe
234 |
235 | # FAKE - F# Make
236 | .fake/
237 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Emanoel Xavier
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnitTestAnalyzers
2 |
3 | [](https://gitter.im/DotNetAnalyzers/UnitTestAnalyzers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 | Analyzers for unit tests using the .NET Compiler Platform
5 |
--------------------------------------------------------------------------------
/UnitTestAnalyzers.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestAnalyzers", "UnitTestAnalyzers\UnitTestAnalyzers\UnitTestAnalyzers.csproj", "{F5D899DD-0AD6-4480-A0A8-7B5203D7BE9E}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestAnalyzers.FunctionalTests", "UnitTestAnalyzers\UnitTestAnalyzers.Test\UnitTestAnalyzers.FunctionalTests.csproj", "{B3517669-2026-4681-B5DB-A98C70EE1DA5}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestAnalyzers.Vsix", "UnitTestAnalyzers\UnitTestAnalyzers.Vsix\UnitTestAnalyzers.Vsix.csproj", "{1FB0E60C-FB26-4F04-B766-DFDFCB0EEE5C}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {F5D899DD-0AD6-4480-A0A8-7B5203D7BE9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {F5D899DD-0AD6-4480-A0A8-7B5203D7BE9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {F5D899DD-0AD6-4480-A0A8-7B5203D7BE9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {F5D899DD-0AD6-4480-A0A8-7B5203D7BE9E}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {B3517669-2026-4681-B5DB-A98C70EE1DA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {B3517669-2026-4681-B5DB-A98C70EE1DA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {B3517669-2026-4681-B5DB-A98C70EE1DA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {B3517669-2026-4681-B5DB-A98C70EE1DA5}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {1FB0E60C-FB26-4F04-B766-DFDFCB0EEE5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {1FB0E60C-FB26-4F04-B766-DFDFCB0EEE5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {1FB0E60C-FB26-4F04-B766-DFDFCB0EEE5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {1FB0E60C-FB26-4F04-B766-DFDFCB0EEE5C}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Design/TestNameMustIncludeMemberUnderTestFunctionalTests.cs:
--------------------------------------------------------------------------------
1 | namespace UnitTestAnalyzers.Test.Design
2 | {
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using Microsoft.CodeAnalysis.Diagnostics;
6 | using Settings.ObjectModel;
7 | using TestData;
8 | using TestHelper;
9 | using Xunit;
10 |
11 | public class TestNameMustIncludeMemberUnderTestFunctionalTests : DiagnosticVerifier
12 | {
13 | private string settings;
14 |
15 | [Theory]
16 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerMSTestInvalidData))]
17 | public async Task IncludeMemberUnderTestInTestName_MSTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, string testMethodNameMemberUnderTest, int violantioLine, int violationColumn, string settings)
18 | {
19 | this.settings = settings;
20 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodNameMemberUnderTest).WithLocation(violantioLine, violationColumn);
21 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
22 | }
23 |
24 | [Theory]
25 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerXunitTestInvalidData))]
26 | public async Task IncludeMemberUnderTestInTestName_XunitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, string testMethodNameMemberUnderTest, int violantioLine, int violationColumn, string settings)
27 | {
28 | this.settings = settings;
29 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodNameMemberUnderTest).WithLocation(violantioLine, violationColumn);
30 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
31 | }
32 |
33 | [Theory]
34 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerNUnitTestInvalidData))]
35 | public async Task IncludeMemberUnderTestInTestName_NUnitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, string testMethodNameMemberUnderTest, int violantioLine, int violationColumn, string settings)
36 | {
37 | this.settings = settings;
38 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodNameMemberUnderTest).WithLocation(violantioLine, violationColumn);
39 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
40 | }
41 |
42 | [Theory]
43 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerMSTestValidData))]
44 | public async Task IncludeMemberUnderTestInTestName_MSTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
45 | {
46 | this.settings = settings;
47 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
48 | }
49 |
50 | [Theory]
51 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerXunitTestValidData))]
52 | public async Task IncludeMemberUnderTestInTestName_XunitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
53 | {
54 | this.settings = settings;
55 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
56 | }
57 |
58 | [Theory]
59 | [ClassData(typeof(TestNameMustIncludeMemberUnderTestAnalyzerNUnitTestValidData))]
60 | public async Task IncludeMemberUnderTestInTestName_NUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
61 | {
62 | this.settings = settings;
63 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
64 | }
65 |
66 | ///
67 | /// Get the CSharp analyzer being tested.
68 | ///
69 | protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
70 | {
71 | return new TestNameMustIncludeMemberUnderTestAnalyzer();
72 | }
73 |
74 | ///
75 | protected override string GetSettings()
76 | {
77 | return this.settings;
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Documentation/UseAAACommentsFunctionalTests.cs:
--------------------------------------------------------------------------------
1 | namespace UnitTestAnalyzers.Test.Documentation
2 | {
3 | using System.Collections.Generic;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | using Microsoft.CodeAnalysis.Diagnostics;
7 | using Settings.ObjectModel;
8 | using TestData;
9 | using TestHelper;
10 | using Xunit;
11 |
12 | public class UseAAACommentsFunctionalTests : DiagnosticVerifier
13 | {
14 | private string settings;
15 |
16 | [Theory]
17 | [ClassData(typeof(UseAAACommentsAnalyzerMSTestInvalidData))]
18 | public async Task UseAAAComments_MSTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, bool hasValidAAAComments, bool firstLineIsArrangeComment)
19 | {
20 | this.settings = settings;
21 | var expectedDiagnostics = new List();
22 | if (!hasValidAAAComments)
23 | {
24 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.AAACommentsDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
25 | }
26 |
27 | if (!firstLineIsArrangeComment)
28 | {
29 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.ArrangeCommentFirstLineDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
30 | }
31 |
32 | await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics.ToArray(), CancellationToken.None).ConfigureAwait(false);
33 | }
34 |
35 | [Theory]
36 | [ClassData(typeof(UseAAACommentsAnalyzerXunitTestInvalidData))]
37 | public async Task UseAAAComments_XunitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, bool hasValidAAAComments, bool firstLineIsArrangeComment)
38 | {
39 | this.settings = settings;
40 | var expectedDiagnostics = new List();
41 | if (!hasValidAAAComments)
42 | {
43 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.AAACommentsDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
44 | }
45 |
46 | if (!firstLineIsArrangeComment)
47 | {
48 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.ArrangeCommentFirstLineDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
49 | }
50 |
51 | await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics.ToArray(), CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
52 | }
53 |
54 | [Theory]
55 | [ClassData(typeof(UseAAACommentsAnalyzerNUnitTestInvalidData))]
56 | public async Task UseAAAComments_NUnitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, bool hasValidAAAComments, bool firstLineIsArrangeComment)
57 | {
58 | this.settings = settings;
59 | var expectedDiagnostics = new List();
60 | if (!hasValidAAAComments)
61 | {
62 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.AAACommentsDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
63 | }
64 |
65 | if (!firstLineIsArrangeComment)
66 | {
67 | expectedDiagnostics.Add(this.CSharpDiagnostic(UseAAACommentsAnalyzer.ArrangeCommentFirstLineDiagnosticId).WithArguments(testMethodName).WithLocation(violantioLine, violationColumn));
68 | }
69 |
70 | await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics.ToArray(), CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
71 | }
72 |
73 | [Theory]
74 | [ClassData(typeof(UseAAACommentsAnalyzerMSTestValidData))]
75 | public async Task UseAAAComments_MSTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
76 | {
77 | this.settings = settings;
78 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
79 | }
80 |
81 | [Theory]
82 | [ClassData(typeof(UseAAACommentsAnalyzerXunitTestValidData))]
83 | public async Task UseAAAComments_XunitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
84 | {
85 | this.settings = settings;
86 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
87 | }
88 |
89 | [Theory]
90 | [ClassData(typeof(UseAAACommentsAnalyzerNUnitTestValidData))]
91 | public async Task UseAAAComments_NUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
92 | {
93 | this.settings = settings;
94 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
95 | }
96 |
97 | ///
98 | /// Get the CSharp analyzer being tested.
99 | ///
100 | protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
101 | {
102 | return new UseAAACommentsAnalyzer();
103 | }
104 |
105 | ///
106 | protected override string GetSettings()
107 | {
108 | return this.settings;
109 | }
110 | }
111 | }
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | // This file is used by Code Analysis to maintain SuppressMessage
2 | // attributes that are applied to this project.
3 | // Project-level suppressions either have no target or are given
4 | // a specific target and scoped to a namespace, type, member, etc.
5 |
6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File must have header", Justification = "")]
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements must be documented", Justification = "")]
8 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1615:Element return value must be documented", Justification = "")]
9 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1652:Enable XML documentation output", Justification = "")]
10 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("AsyncUsage.CSharp.Naming", "UseAsyncSuffix:Use Async suffix", Justification = "")]
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Helpers/DiagnosticResult.cs:
--------------------------------------------------------------------------------
1 | namespace TestHelper
2 | {
3 | using System;
4 | using Microsoft.CodeAnalysis;
5 |
6 | ///
7 | /// Struct that stores information about a Diagnostic appearing in a source
8 | ///
9 | public struct DiagnosticResult
10 | {
11 | private static readonly object[] EmptyArguments = new object[0];
12 | private DiagnosticResultLocation[] locations;
13 | private string message;
14 |
15 | internal DiagnosticResult(DiagnosticDescriptor descriptor)
16 | : this()
17 | {
18 | this.Id = descriptor.Id;
19 | this.Severity = descriptor.DefaultSeverity;
20 | this.MessageFormat = descriptor.MessageFormat;
21 | }
22 |
23 | internal DiagnosticResultLocation[] Locations
24 | {
25 | get
26 | {
27 | if (this.locations == null)
28 | {
29 | this.locations = new DiagnosticResultLocation[] { };
30 | }
31 |
32 | return this.locations;
33 | }
34 |
35 | set
36 | {
37 | this.locations = value;
38 | }
39 | }
40 |
41 | internal LocalizableString MessageFormat
42 | {
43 | get;
44 | set;
45 | }
46 |
47 | internal DiagnosticSeverity Severity { get; set; }
48 |
49 | internal string Id { get; set; }
50 |
51 | internal string Message
52 | {
53 | get
54 | {
55 | if (this.message != null)
56 | {
57 | return this.message;
58 | }
59 |
60 | if (this.MessageFormat != null)
61 | {
62 | return string.Format(this.MessageFormat.ToString(), this.MessageArguments ?? EmptyArguments);
63 | }
64 |
65 | return null;
66 | }
67 |
68 | set
69 | {
70 | this.message = value;
71 | }
72 | }
73 |
74 | internal string Path
75 | {
76 | get
77 | {
78 | return this.Locations.Length > 0 ? this.Locations[0].Path : string.Empty;
79 | }
80 | }
81 |
82 | internal object[] MessageArguments
83 | {
84 | get;
85 | set;
86 | }
87 |
88 | internal int Line
89 | {
90 | get
91 | {
92 | return this.Locations.Length > 0 ? this.Locations[0].Line : -1;
93 | }
94 | }
95 |
96 | internal int Column
97 | {
98 | get
99 | {
100 | return this.Locations.Length > 0 ? this.Locations[0].Column : -1;
101 | }
102 | }
103 |
104 | public DiagnosticResult WithArguments(params object[] arguments)
105 | {
106 | DiagnosticResult result = this;
107 | result.MessageArguments = arguments;
108 | return result;
109 | }
110 |
111 | public DiagnosticResult WithLocation(int line, int column)
112 | {
113 | return this.WithLocation("Test0.cs", line, column);
114 | }
115 |
116 | public DiagnosticResult WithLocation(string path, int line, int column)
117 | {
118 | DiagnosticResult result = this;
119 | Array.Resize(ref result.locations, (result.locations?.Length ?? 0) + 1);
120 | result.locations[result.locations.Length - 1] = new DiagnosticResultLocation(path, line, column);
121 | return result;
122 | }
123 | }
124 |
125 | ///
126 | /// Location where the diagnostic appears, as determined by path, line number, and column number.
127 | ///
128 | internal struct DiagnosticResultLocation
129 | {
130 | internal DiagnosticResultLocation(string path, int line, int column)
131 | {
132 | if (line < -1)
133 | {
134 | throw new ArgumentOutOfRangeException(nameof(line), "line must be >= -1");
135 | }
136 |
137 | if (column < -1)
138 | {
139 | throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1");
140 | }
141 |
142 | this.Path = path;
143 | this.Line = line;
144 | this.Column = column;
145 | }
146 |
147 | internal string Path { get; }
148 |
149 | internal int Line { get; }
150 |
151 | internal int Column { get; }
152 | }
153 | }
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Naming/UseCorrectTestNameFormatFunctionalTests.cs:
--------------------------------------------------------------------------------
1 | namespace UnitTestAnalyzers.Test.Naming
2 | {
3 | using Xunit;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 | using Microsoft.CodeAnalysis.Diagnostics;
7 | using Settings.ObjectModel;
8 | using TestData;
9 | using TestHelper;
10 |
11 | public class UseCorrectTestNameFormatFunctionalTests : DiagnosticVerifier
12 | {
13 | private string settings;
14 |
15 | [Theory]
16 | [ClassData(typeof(UseCorrectTestNameFormatMSTestInvalidData))]
17 | public async Task UseCorrectTestNameFormat_MSTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, string testMethodFormat, string[] testMethodNameExamples)
18 | {
19 | this.settings = settings;
20 | string testMethodNameExamplesArgument = string.Join(", ", testMethodNameExamples);
21 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodFormat, testMethodNameExamplesArgument).WithLocation(violantioLine, violationColumn);
22 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
23 | }
24 |
25 | [Theory]
26 | [ClassData(typeof(UseCorrectTestNameFormatMSTestValidData))]
27 | public async Task UseCorrectTestNameFormat_MSTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
28 | {
29 | this.settings = settings;
30 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
31 | }
32 |
33 | [Theory]
34 | [ClassData(typeof(UseCorrectTestNameFormatXunitTestInvalidData))]
35 | public async Task UseCorrectTestNameFormat_XunitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, string testMethodFormat, string[] testMethodNameExamples)
36 | {
37 | this.settings = settings;
38 | string testMethodNameExamplesArgument = string.Join(", ", testMethodNameExamples);
39 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodFormat, testMethodNameExamplesArgument).WithLocation(violantioLine, violationColumn);
40 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
41 | }
42 |
43 | [Theory]
44 | [ClassData(typeof(UseCorrectTestNameFormatXunitTestValidData))]
45 | public async Task UseCorrectTestNameFormat_UsingxUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
46 | {
47 | this.settings = settings;
48 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
49 | }
50 |
51 | [Theory]
52 | [ClassData(typeof(UseCorrectTestNameFormatNUnitTestInvalidData))]
53 | public async Task UseCorrectTestNameFormat_NUnitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testMethodName, int violantioLine, int violationColumn, string settings, string testMethodFormat, string[] testMethodNameExamples)
54 | {
55 | this.settings = settings;
56 | string testMethodNameExamplesArgument = string.Join(", ", testMethodNameExamples);
57 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testMethodName, testMethodFormat, testMethodNameExamplesArgument).WithLocation(violantioLine, violationColumn);
58 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
59 | }
60 |
61 | [Theory]
62 | [ClassData(typeof(UseCorrectTestNameFormatNUnitTestValidData))]
63 | public async Task UseCorrectTestNameFormat_UsingNUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
64 | {
65 | this.settings = settings;
66 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
67 | }
68 |
69 | ///
70 | /// Get the CSharp analyzer being tested.
71 | ///
72 | protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
73 | {
74 | return new UseCorrectTestNameFormatAnalyzer();
75 | }
76 |
77 | ///
78 | protected override string GetSettings()
79 | {
80 | return this.settings;
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Naming/UseUnitTestsSuffixFunctionalTests.cs:
--------------------------------------------------------------------------------
1 | namespace UnitTestAnalyzers.Test.Naming
2 | {
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using Microsoft.CodeAnalysis.Diagnostics;
6 | using Settings.ObjectModel;
7 | using TestData;
8 | using TestHelper;
9 | using Xunit;
10 |
11 | public class UseUnitTestsSuffixFunctionalTests : DiagnosticVerifier
12 | {
13 | private string settings;
14 |
15 | [Theory]
16 | [ClassData(typeof(UseUnitTestsSuffixMSTestValidData))]
17 | public async Task UseUnitTestsSuffix_MSTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
18 | {
19 | this.settings = settings;
20 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
21 | }
22 |
23 | [Theory]
24 | [ClassData(typeof(UseUnitTestsSuffixMSTestInvalidData))]
25 | public async Task UseUnitTestsSuffix_MSTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testClassName, int violantioLine, int violationColumn, string settings)
26 | {
27 | this.settings = settings;
28 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testClassName).WithLocation(violantioLine, violationColumn);
29 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
30 | }
31 |
32 | [Theory]
33 | [ClassData(typeof(UseUnitTestsSuffixXunitTestValidData))]
34 | public async Task UseUnitTestsSuffix_xUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
35 | {
36 | this.settings = settings;
37 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
38 | }
39 |
40 | [Theory]
41 | [ClassData(typeof(UseUnitTestsSuffixXunitTestInvalidData))]
42 | public async Task UseUnitTestsSuffix_xUnitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testClassName, int violantionLine, int violationColumn, string settings)
43 | {
44 | this.settings = settings;
45 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testClassName).WithLocation(violantionLine, violationColumn);
46 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.Xunit).ConfigureAwait(false);
47 | }
48 |
49 | [Theory]
50 | [ClassData(typeof(UseUnitTestsSuffixNUnitTestValidData))]
51 | public async Task UseUnitTestsSuffix_NUnitTestCodeWithoutViolation_ExpectsNoDiagnostic(string testCode, string settings)
52 | {
53 | this.settings = settings;
54 | await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
55 | }
56 |
57 | [Theory]
58 | [ClassData(typeof(UseUnitTestsSuffixNUnitTestInvalidData))]
59 | public async Task UseUnitTestsSuffix_NUnitTestCodeWithViolation_ExpectsDiagnostic(string testCode, string testClassName, int violantionLine, int violationColumn, string settings)
60 | {
61 | this.settings = settings;
62 | DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(testClassName).WithLocation(violantionLine, violationColumn);
63 | await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None, UnitTestFramework.NUnit).ConfigureAwait(false);
64 | }
65 |
66 | protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
67 | {
68 | return new UseUnitTestsSuffixAnalyzer();
69 | }
70 |
71 | protected override string GetSettings()
72 | {
73 | return this.settings;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("UnitTestAnalyzers.Test")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("UnitTestAnalyzers.Test")]
12 | [assembly: AssemblyCopyright("Copyright © 2016")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // Version information for an assembly consists of the following four values:
22 | //
23 | // Major Version
24 | // Minor Version
25 | // Build Number
26 | // Revision
27 | //
28 | // You can specify all the values or you can default the Build and Revision Numbers
29 | // by using the '*' as shown below:
30 | // [assembly: AssemblyVersion("1.0.*")]
31 | [assembly: AssemblyVersion("1.0.0.0")]
32 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/UnitTestAnalyzers/UnitTestAnalyzers.Test/TestData/TestNameMustIncludeMemberUnderTestAnalyzerMSTestInvalidData.cs:
--------------------------------------------------------------------------------
1 | namespace UnitTestAnalyzers.Test.TestData
2 | {
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | internal class TestNameMustIncludeMemberUnderTestAnalyzerMSTestInvalidData : IEnumerable