Skip to content

Commit d5af334

Browse files
authored
docs: add test project for FluentAssertionsAnalyzer (#304)
* docs: add test project for FluentAssertionsAnalyzer
1 parent b15a52e commit d5af334

17 files changed

+117
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
with:
2525
dotnet-version: 6.0.x
2626
- run: dotnet build
27-
- run: dotnet test --configuration Release --filter 'TestCategory=Completed' /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
27+
- run: dotnet test src/FluentAssertions.Analyzers.Tests --configuration Release --filter 'TestCategory=Completed' /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
2828
- run: dotnet pack src/FluentAssertions.Analyzers/FluentAssertions.Analyzers.csproj

.github/workflows/integration.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Integration
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- main
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
runs-on: ${{ matrix.os }}
15+
env:
16+
NUGET_CERT_REVOCATION_MODE: offline
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
- name: Setup .NET 6
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 6.0.x
25+
- run: dotnet test src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs # before formatting
26+
- run: dotnet format analyzers src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs --diagnostics FAA0001 --severity info --verbosity normal
27+
- run: dotnet test src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs # after formatting

FluentAssertions.Analyzers.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Analyzers.
1919
EndProject
2020
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Analyzers.BenchmarkTests", "src\FluentAssertions.Analyzers.BenchmarkTests\FluentAssertions.Analyzers.BenchmarkTests.csproj", "{FE6D8A05-1383-4BCD-AD65-2EF741E48F44}"
2121
EndProject
22+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8EFE7955-E63C-4055-A9FF-76C7CE0A1151}"
23+
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs", "src\FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs\FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.csproj", "{2F84FE09-8CB4-48AE-A119-671C509213CF}"
25+
EndProject
2226
Global
2327
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2428
Debug|Any CPU = Debug|Any CPU
@@ -41,11 +45,18 @@ Global
4145
{FE6D8A05-1383-4BCD-AD65-2EF741E48F44}.Debug|Any CPU.Build.0 = Debug|Any CPU
4246
{FE6D8A05-1383-4BCD-AD65-2EF741E48F44}.Release|Any CPU.ActiveCfg = Release|Any CPU
4347
{FE6D8A05-1383-4BCD-AD65-2EF741E48F44}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{2F84FE09-8CB4-48AE-A119-671C509213CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{2F84FE09-8CB4-48AE-A119-671C509213CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{2F84FE09-8CB4-48AE-A119-671C509213CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{2F84FE09-8CB4-48AE-A119-671C509213CF}.Release|Any CPU.Build.0 = Release|Any CPU
4452
EndGlobalSection
4553
GlobalSection(SolutionProperties) = preSolution
4654
HideSolutionNode = FALSE
4755
EndGlobalSection
4856
GlobalSection(ExtensibilityGlobals) = postSolution
4957
SolutionGuid = {4BF3D005-625C-4CEC-B3FB-298B956402BE}
5058
EndGlobalSection
59+
GlobalSection(NestedProjects) = preSolution
60+
{2F84FE09-8CB4-48AE-A119-671C509213CF} = {8EFE7955-E63C-4055-A9FF-76C7CE0A1151}
61+
EndGlobalSection
5162
EndGlobal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs;
6+
7+
[TestClass]
8+
public class CollectionTests
9+
{
10+
[TestMethod]
11+
public void CollectionsShouldNotBeEmpty()
12+
{
13+
// arrange
14+
IList<TestComplexClass> collection = new List<TestComplexClass>
15+
{
16+
new TestComplexClass { BooleanProperty = true, Message = 1 },
17+
new TestComplexClass { BooleanProperty = false, Message = 2 }
18+
};
19+
20+
// assert
21+
collection.Any().Should().BeTrue();
22+
}
23+
24+
public class TestComplexClass
25+
{
26+
public bool BooleanProperty { get; set; }
27+
public int Message { get; set; }
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
<IsTestProject>true</IsTestProject>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
13+
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
14+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
15+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\FluentAssertions.Analyzers\FluentAssertions.Analyzers.csproj" />
20+
<Analyzer Include="..\FluentAssertions.Analyzers\bin\Debug\netstandard2.0\FluentAssertions.Analyzers.dll" />
21+
</ItemGroup>
22+
23+
</Project>

src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR
597597

598598
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
599599
{
600-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
600+
Id = FluentAssertionsAnalyzer.DiagnosticId,
601601
Message = DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1.Message,
602602
VisitorName = DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1.Name,
603603
Locations = new DiagnosticResultLocation[]
@@ -986,7 +986,7 @@ private void VerifyCSharpDiagnosticCodeBlock(string sourceAssertion, DiagnosticM
986986

987987
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
988988
{
989-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
989+
Id = FluentAssertionsAnalyzer.DiagnosticId,
990990
Message = metadata.Message,
991991
VisitorName = metadata.Name,
992992
Locations = new DiagnosticResultLocation[]
@@ -1003,7 +1003,7 @@ private void VerifyCSharpDiagnosticExpressionBody(string sourceAssertion, Diagno
10031003

10041004
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
10051005
{
1006-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
1006+
Id = FluentAssertionsAnalyzer.DiagnosticId,
10071007
VisitorName = metadata.Name,
10081008
Message = metadata.Message,
10091009
Locations = new DiagnosticResultLocation[]
@@ -1020,7 +1020,7 @@ private void VerifyArrayCSharpDiagnosticCodeBlock(string sourceAssertion, Diagno
10201020

10211021
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
10221022
{
1023-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
1023+
Id = FluentAssertionsAnalyzer.DiagnosticId,
10241024
Message = metadata.Message,
10251025
VisitorName = metadata.Name,
10261026
Locations = new DiagnosticResultLocation[]
@@ -1059,7 +1059,7 @@ private void VerifyFix(string oldSource, string newSource)
10591059
{
10601060
DiagnosticVerifier.VerifyFix(new CodeFixVerifierArguments()
10611061
.WithCodeFixProvider<FluentAssertionsCodeFixProvider>()
1062-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
1062+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
10631063
.WithSources(oldSource)
10641064
.WithFixedSources(newSource)
10651065
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)

src/FluentAssertions.Analyzers.Tests/Tips/DictionaryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void VerifyCSharpDiagnostic(string sourceAssersion, DiagnosticMetadata m
165165

166166
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
167167
{
168-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
168+
Id = FluentAssertionsAnalyzer.DiagnosticId,
169169
Message = metadata.Message,
170170
VisitorName = metadata.Name,
171171
Locations = new DiagnosticResultLocation[]
@@ -184,7 +184,7 @@ private void VerifyCSharpFix(string oldSourceAssertion, string newSourceAssertio
184184
DiagnosticVerifier.VerifyFix(new CodeFixVerifierArguments()
185185
.WithSources(oldSource)
186186
.WithFixedSources(newSource)
187-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
187+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
188188
.WithCodeFixProvider<FluentAssertionsCodeFixProvider>()
189189
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
190190
);

src/FluentAssertions.Analyzers.Tests/Tips/ExceptionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private void VerifyCSharpDiagnostic(string sourceAssertion, DiagnosticMetadata m
285285

286286
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
287287
{
288-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
288+
Id = FluentAssertionsAnalyzer.DiagnosticId,
289289
Message = metadata.Message,
290290
VisitorName = metadata.Name,
291291
Locations = new DiagnosticResultLocation[]
@@ -304,7 +304,7 @@ private void VerifyCSharpFix(string oldSourceAssertion, string newSourceAssertio
304304
DiagnosticVerifier.VerifyFix(new CodeFixVerifierArguments()
305305
.WithSources(oldSource)
306306
.WithFixedSources(newSource)
307-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
307+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
308308
.WithCodeFixProvider<FluentAssertionsCodeFixProvider>()
309309
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
310310
);

src/FluentAssertions.Analyzers.Tests/Tips/FluentAssertionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class TestClass
1919
}";
2020

2121
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
22-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
22+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
2323
.WithSources(source)
2424
);
2525
}
@@ -51,7 +51,7 @@ public void BeTrue() { }
5151
}";
5252

5353
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
54-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
54+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
5555
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
5656
.WithSources(source)
5757
);

src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class NullConditionalAssertionTests
1818
public void NullConditionalMayNotExecuteTest(string assertion)
1919
{
2020
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
21-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
21+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
2222
.WithSources(Code(assertion))
2323
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
2424
.WithExpectedDiagnostics(new DiagnosticResult
2525
{
26-
Id = FluentAssertionsOperationAnalyzer.DiagnosticId,
26+
Id = FluentAssertionsAnalyzer.DiagnosticId,
2727
Message = DiagnosticMetadata.NullConditionalMayNotExecute.Message,
2828
Severity = Microsoft.CodeAnalysis.DiagnosticSeverity.Info, // TODO: change to warning
2929
VisitorName = nameof(DiagnosticMetadata.NullConditionalMayNotExecute),
@@ -43,7 +43,7 @@ public void NullConditionalMayNotExecuteTest(string assertion)
4343
public void NullConditionalWillStillExecuteTest(string assertion)
4444
{
4545
DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
46-
.WithDiagnosticAnalyzer<FluentAssertionsOperationAnalyzer>()
46+
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
4747
.WithSources(Code(assertion))
4848
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
4949
);

0 commit comments

Comments
 (0)