Skip to content

Commit 240da58

Browse files
authored
refactor: add FluentAssertions.Analyzers and fix some warnings (#634)
1 parent f8f8383 commit 240da58

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
1111
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
1212
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
13+
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.21.0" />
1314
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
1415
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
1516
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />

test/Microsoft.ComponentDetection.Contracts.Tests/DetectedComponentTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Microsoft.ComponentDetection.Contracts.Tests;
22

3+
using FluentAssertions;
34
using Microsoft.ComponentDetection.Contracts.TypedComponent;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
56

@@ -17,12 +18,10 @@ public void AddComponentFilePath_AddsPathsCorrectly()
1718

1819
var component = new DetectedComponent(new NpmComponent(componentName, componentVersion));
1920

20-
Assert.IsNotNull(component.FilePaths);
21-
Assert.AreEqual(0, component.FilePaths.Count);
21+
component.FilePaths.Should().NotBeNull().And.HaveCount(0);
2222

2323
component.AddComponentFilePath(filePathToAdd);
2424

25-
Assert.AreEqual(1, component.FilePaths.Count);
26-
Assert.IsTrue(component.FilePaths.Contains(filePathToAdd));
25+
component.FilePaths.Should().HaveCount(1).And.Contain(filePathToAdd);
2726
}
2827
}

test/Microsoft.ComponentDetection.Contracts.Tests/Microsoft.ComponentDetection.Contracts.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageReference Include="System.Reactive" />
1111
<PackageReference Include="System.Threading.Tasks.Dataflow" />
1212
<PackageReference Include="packageurl-dotnet" />
13+
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
1314
</ItemGroup>
1415

1516
</Project>

test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentDiffTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public void ExperimentDiff_DiffsAddedRootIds()
9090
diff.RemovedRootIds.Should().BeEmpty();
9191

9292
var addedRoot = diff.AddedRootIds[componentA.Component.Id];
93-
addedRoot.Should().HaveCount(1);
94-
addedRoot.Should().BeEquivalentTo(rootComponent.Id);
93+
addedRoot.Should().ContainSingle().And.BeEquivalentTo(rootComponent.Id);
9594

9695
diff.AddedIds.Should().BeEmpty();
9796
diff.RemovedIds.Should().BeEmpty();
@@ -118,8 +117,7 @@ public void ExperimentDiff_DiffsRemovedRootIds()
118117
diff.AddedRootIds.Should().BeEmpty();
119118

120119
var removedRoot = diff.RemovedRootIds[componentA.Component.Id];
121-
removedRoot.Should().HaveCount(1);
122-
removedRoot.Should().BeEquivalentTo(rootComponent.Id);
120+
removedRoot.Should().ContainSingle().And.BeEquivalentTo(rootComponent.Id);
123121

124122
diff.AddedIds.Should().BeEmpty();
125123
diff.RemovedIds.Should().BeEmpty();

test/Microsoft.ComponentDetection.Orchestrator.Tests/Microsoft.ComponentDetection.Orchestrator.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<PackageReference Include="Microsoft.Extensions.Logging" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1111
<PackageReference Include="System.Threading.Tasks.Dataflow" />
12+
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
1213
</ItemGroup>
1314

1415
</Project>

test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/BcdeScanExecutionServiceTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ public async Task DetectComponents_Graph_Happy_PathAsync()
257257
var matchingGraph = result.DependencyGraphs.First();
258258
matchingGraph.Key.Should().Be(mockGraphLocation);
259259
var explicitlyReferencedComponents = matchingGraph.Value.ExplicitlyReferencedComponentIds;
260-
explicitlyReferencedComponents.Count.Should().Be(1);
261-
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[0].Component.Id);
260+
explicitlyReferencedComponents.Should().ContainSingle().And.Contain(this.detectedComponents[0].Component.Id);
262261

263262
var actualGraph = matchingGraph.Value.Graph;
264263
actualGraph.Keys.Count.Should().Be(2);
@@ -331,7 +330,7 @@ public async Task DetectComponents_Graph_AccumulatesGraphsOnSameLocationAsync()
331330
var matchingGraph = result.DependencyGraphs.First();
332331
matchingGraph.Key.Should().Be(mockGraphLocation);
333332
var explicitlyReferencedComponents = matchingGraph.Value.ExplicitlyReferencedComponentIds;
334-
explicitlyReferencedComponents.Count.Should().Be(2);
333+
explicitlyReferencedComponents.Should().HaveCount(2);
335334
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[0].Component.Id);
336335
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[1].Component.Id);
337336

test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,32 +348,32 @@ public void GenerateDirectoryExclusionPredicate_IgnoreCaseAndAllowWindowsPathsWo
348348
// Exclusion predicate is case sensitive and allow windows path, the exclusion list follow the windows path structure and has a case mismatch with the directory path, should not exclude
349349
args.DirectoryExclusionList = new[] { @"**\source\**" };
350350
var exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: false);
351-
Assert.IsFalse(exclusionPredicate(dn, dp));
351+
exclusionPredicate(dn, dp).Should().BeFalse();
352352

353353
// Exclusion predicate is case sensitive and allow windows path, the exclusion list follow the windows path structure and match directory path case, should exclude
354354
args.DirectoryExclusionList = new[] { @"**\Source\**" };
355355
exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: false);
356-
Assert.IsTrue(exclusionPredicate(dn, dp));
356+
exclusionPredicate(dn, dp).Should().BeTrue();
357357

358358
// Exclusion predicate is not case sensitive and allow windows path, the exclusion list follow the windows path, should exclude
359359
args.DirectoryExclusionList = new[] { @"**\sOuRce\**" };
360360
exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: true);
361-
Assert.IsTrue(exclusionPredicate(dn, dp));
361+
exclusionPredicate(dn, dp).Should().BeTrue();
362362

363363
// Exclusion predicate does not support windows path and the exclusion list define the path as a windows path, should not exclude
364364
args.DirectoryExclusionList = new[] { @"**\Source\**" };
365365
exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: false, ignoreCase: true);
366-
Assert.IsFalse(exclusionPredicate(dn, dp));
366+
exclusionPredicate(dn, dp).Should().BeFalse();
367367

368368
// Exclusion predicate support windows path and the exclusion list define the path as a windows path, should exclude
369369
args.DirectoryExclusionList = new[] { @"**\Source\**" };
370370
exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: true);
371-
Assert.IsTrue(exclusionPredicate(dn, dp));
371+
exclusionPredicate(dn, dp).Should().BeTrue();
372372

373373
// Exclusion predicate support windows path and the exclusion list does not define a windows path, should exclude
374374
args.DirectoryExclusionList = new[] { @"**/Source/**", @"**/Source\**" };
375375
exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: true);
376-
Assert.IsTrue(exclusionPredicate(dn, dp));
376+
exclusionPredicate(dn, dp).Should().BeTrue();
377377
}
378378

379379
[TestMethod]
@@ -602,7 +602,7 @@ private void ValidateExpectedComponents(DetectorProcessingResult result, IEnumer
602602
var check = isPresent.Select(i => i.GetType());
603603

604604
isPresent.All(discovered => shouldBePresent.Contains(discovered));
605-
shouldBePresent.Should().HaveCount(isPresent.Count());
605+
shouldBePresent.Should().HaveSameCount(isPresent);
606606
}
607607

608608
private Mock<IComponentDetector> SetupCommandDetectorMock(string id)

0 commit comments

Comments
 (0)