Skip to content

refactor: add FluentAssertions.Analyzers and fix some warnings #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.21.0" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Microsoft.ComponentDetection.Contracts.Tests;

using FluentAssertions;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Microsoft.VisualStudio.TestTools.UnitTesting;

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

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

Assert.IsNotNull(component.FilePaths);
Assert.AreEqual(0, component.FilePaths.Count);
component.FilePaths.Should().NotBeNull().And.HaveCount(0);

component.AddComponentFilePath(filePathToAdd);

Assert.AreEqual(1, component.FilePaths.Count);
Assert.IsTrue(component.FilePaths.Contains(filePathToAdd));
component.FilePaths.Should().HaveCount(1).And.Contain(filePathToAdd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="System.Reactive" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
<PackageReference Include="packageurl-dotnet" />
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public void ExperimentDiff_DiffsAddedRootIds()
diff.RemovedRootIds.Should().BeEmpty();

var addedRoot = diff.AddedRootIds[componentA.Component.Id];
addedRoot.Should().HaveCount(1);
addedRoot.Should().BeEquivalentTo(rootComponent.Id);
addedRoot.Should().ContainSingle().And.BeEquivalentTo(rootComponent.Id);

diff.AddedIds.Should().BeEmpty();
diff.RemovedIds.Should().BeEmpty();
Expand All @@ -118,8 +117,7 @@ public void ExperimentDiff_DiffsRemovedRootIds()
diff.AddedRootIds.Should().BeEmpty();

var removedRoot = diff.RemovedRootIds[componentA.Component.Id];
removedRoot.Should().HaveCount(1);
removedRoot.Should().BeEquivalentTo(rootComponent.Id);
removedRoot.Should().ContainSingle().And.BeEquivalentTo(rootComponent.Id);

diff.AddedIds.Should().BeEmpty();
diff.RemovedIds.Should().BeEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
<PackageReference Include="FluentAssertions.Analyzers" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public async Task DetectComponents_Graph_Happy_PathAsync()
var matchingGraph = result.DependencyGraphs.First();
matchingGraph.Key.Should().Be(mockGraphLocation);
var explicitlyReferencedComponents = matchingGraph.Value.ExplicitlyReferencedComponentIds;
explicitlyReferencedComponents.Count.Should().Be(1);
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[0].Component.Id);
explicitlyReferencedComponents.Should().ContainSingle().And.Contain(this.detectedComponents[0].Component.Id);

var actualGraph = matchingGraph.Value.Graph;
actualGraph.Keys.Count.Should().Be(2);
Expand Down Expand Up @@ -331,7 +330,7 @@ public async Task DetectComponents_Graph_AccumulatesGraphsOnSameLocationAsync()
var matchingGraph = result.DependencyGraphs.First();
matchingGraph.Key.Should().Be(mockGraphLocation);
var explicitlyReferencedComponents = matchingGraph.Value.ExplicitlyReferencedComponentIds;
explicitlyReferencedComponents.Count.Should().Be(2);
explicitlyReferencedComponents.Should().HaveCount(2);
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[0].Component.Id);
explicitlyReferencedComponents.Should().Contain(this.detectedComponents[1].Component.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,32 +348,32 @@ public void GenerateDirectoryExclusionPredicate_IgnoreCaseAndAllowWindowsPathsWo
// 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
args.DirectoryExclusionList = new[] { @"**\source\**" };
var exclusionPredicate = this.serviceUnderTest.GenerateDirectoryExclusionPredicate(@"C:\somefake\dir", args.DirectoryExclusionList, args.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: false);
Assert.IsFalse(exclusionPredicate(dn, dp));
exclusionPredicate(dn, dp).Should().BeFalse();

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

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

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

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

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

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

isPresent.All(discovered => shouldBePresent.Contains(discovered));
shouldBePresent.Should().HaveCount(isPresent.Count());
shouldBePresent.Should().HaveSameCount(isPresent);
}

private Mock<IComponentDetector> SetupCommandDetectorMock(string id)
Expand Down