From 37e0b73df5236a30a632a67faf5680c7cdfd7b2d Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 5 Mar 2026 20:27:59 -0800 Subject: [PATCH 1/6] refactor: standardize InternalsVisibleTo in csproj files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consolidate all [assembly: InternalsVisibleTo] attributes from scattered .cs files into their respective .csproj files using MSBuild items. Add cross-project InternalsVisibleTo entries to enable future phases of making implementation details internal: - Detectors → Orchestrator, Tests, TestsUtilities - Common → Tests, Orchestrator, Detectors, TestsUtilities - Orchestrator → Tests, CLI entry point, TestsUtilities - Contracts → Tests, TestsUtilities Remove scattered attributes from: - ComponentRecorder.cs - DependencyGraph.cs - TelemetryConstants.cs - IPyPiClient.cs Part of #455 --- .../DependencyGraph/ComponentRecorder.cs | 11 ++++------- .../DependencyGraph/DependencyGraph.cs | 8 +++----- .../Microsoft.ComponentDetection.Common.csproj | 7 +++++++ .../Telemetry/TelemetryConstants.cs | 7 ++----- .../Microsoft.ComponentDetection.Contracts.csproj | 1 + .../Microsoft.ComponentDetection.Detectors.csproj | 6 ++++++ .../pip/IPyPiClient.cs | 8 +++----- .../Microsoft.ComponentDetection.Orchestrator.csproj | 6 ++++++ 8 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs b/src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs index 664ed310f..851520d4c 100644 --- a/src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs +++ b/src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs @@ -1,19 +1,16 @@ #nullable disable + +namespace Microsoft.ComponentDetection.Common.DependencyGraph; + using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; +using System.Collections.ObjectModel; using System.Linq; -using System.Runtime.CompilerServices; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.BcdeModels; using Microsoft.ComponentDetection.Contracts.TypedComponent; - -[assembly: InternalsVisibleTo("Microsoft.ComponentDetection.Common.Tests")] - -namespace Microsoft.ComponentDetection.Common.DependencyGraph; - -using System.Collections.ObjectModel; using Microsoft.Extensions.Logging; public class ComponentRecorder : IComponentRecorder diff --git a/src/Microsoft.ComponentDetection.Common/DependencyGraph/DependencyGraph.cs b/src/Microsoft.ComponentDetection.Common/DependencyGraph/DependencyGraph.cs index d4ad20433..eb42ae101 100644 --- a/src/Microsoft.ComponentDetection.Common/DependencyGraph/DependencyGraph.cs +++ b/src/Microsoft.ComponentDetection.Common/DependencyGraph/DependencyGraph.cs @@ -1,19 +1,17 @@ #nullable disable + +namespace Microsoft.ComponentDetection.Common.DependencyGraph; + using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Runtime.CompilerServices; using System.Text; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.BcdeModels; using Microsoft.ComponentDetection.Contracts.TypedComponent; -[assembly: InternalsVisibleTo("Microsoft.ComponentDetection.Common.Tests")] - -namespace Microsoft.ComponentDetection.Common.DependencyGraph; - internal class DependencyGraph : IDependencyGraph { private static readonly CompositeFormat MissingNodeFormat = CompositeFormat.Parse(Resources.MissingNodeInDependencyGraph); diff --git a/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj b/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj index cf206abea..efdcd5363 100644 --- a/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj +++ b/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj @@ -1,5 +1,12 @@ + + + + + + + diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/TelemetryConstants.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/TelemetryConstants.cs index 1ba306666..1fa7c0065 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/TelemetryConstants.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/TelemetryConstants.cs @@ -1,10 +1,7 @@ -using System; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Microsoft.ComponentDetection.Orchestrator")] - namespace Microsoft.ComponentDetection.Common.Telemetry; +using System; + public static class TelemetryConstants { private static Guid correlationId; diff --git a/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj b/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj index 8c8924bf0..b43448711 100644 --- a/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj +++ b/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj @@ -6,6 +6,7 @@ + diff --git a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj index a0fb3f5e4..86d7e413a 100644 --- a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj +++ b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj @@ -1,5 +1,11 @@ + + + + + + diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs b/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs index 782d9e4b6..bfff00904 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs @@ -1,4 +1,7 @@ #nullable disable + +namespace Microsoft.ComponentDetection.Detectors.Pip; + using System; using System.Collections.Generic; using System.IO; @@ -7,7 +10,6 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text.Encodings.Web; using System.Text.Json; using System.Threading; @@ -18,10 +20,6 @@ using Microsoft.Extensions.Logging; using Polly; -[assembly: InternalsVisibleTo("Microsoft.ComponentDetection.Detectors.Tests")] - -namespace Microsoft.ComponentDetection.Detectors.Pip; - public interface IPyPiClient { Task> FetchPackageDependenciesAsync(string name, string version, PythonProjectRelease release); diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj index 81d898362..8305338d5 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj +++ b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj @@ -1,5 +1,11 @@ + + + + + + From cf7335a8dee597aa7260ce589fd34747e5a4bc83 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 5 Mar 2026 20:34:49 -0800 Subject: [PATCH 2/6] Make data model/contract classes internal in Detectors project Change public to internal for deserialization model classes that are implementation details across multiple detector ecosystems: conan, pnpm, swiftpm, vcpkg, rust (CargoLock, CargoToml, CargoSbom), poetry, yarn (Berry contracts, TypeConverter), npm (converters), pip (PipReportGraphNode, PythonVersion), and uv model classes. Types exposed through public interfaces/APIs are left public to maintain build compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../conan/Contracts/ConanLock.cs | 2 +- .../conan/Contracts/ConanLockGraph.cs | 2 +- .../conan/Contracts/ConanLockNode.cs | 2 +- .../npm/Contracts/PackageJsonAuthorConverter.cs | 2 +- .../npm/Contracts/PackageJsonEnginesConverter.cs | 2 +- .../npm/Contracts/PackageJsonWorkspacesConverter.cs | 2 +- .../pip/Contracts/PipReportGraphNode.cs | 2 +- .../pip/Contracts/PythonVersion.cs | 2 +- .../pnpm/Contracts/PnpmYamlV5.cs | 2 +- .../pnpm/Contracts/V6/PnpmHasDependenciesV6.cs | 2 +- .../pnpm/Contracts/V6/PnpmYamlV6.cs | 2 +- .../pnpm/Contracts/V6/PnpmYamlV6Dependency.cs | 2 +- .../pnpm/Contracts/V9/PnpmHasDependenciesV9.cs | 2 +- .../pnpm/Contracts/V9/PnpmYamlV9.cs | 2 +- .../pnpm/Contracts/V9/PnpmYamlV9Dependency.cs | 2 +- .../poetry/Contracts/PoetryLock.cs | 2 +- .../poetry/Contracts/PoetryPackage.cs | 2 +- .../poetry/Contracts/PoetrySource.cs | 2 +- .../rust/Contracts/CargoLock.cs | 2 +- .../rust/Contracts/CargoSbom.cs | 10 +++++----- .../rust/Contracts/CargoToml.cs | 2 +- .../swiftpm/Contracts/SwiftResolvedFile.cs | 6 +++--- .../uv/UvDependency.cs | 2 +- .../uv/UvLock.cs | 2 +- .../uv/UvPackage.cs | 2 +- .../uv/UvSource.cs | 2 +- .../vcpkg/Contracts/Annotation.cs | 2 +- .../vcpkg/Contracts/ManifestInfo.cs | 2 +- .../vcpkg/Contracts/Package.cs | 2 +- .../vcpkg/Contracts/VcpkgSBOM.cs | 2 +- .../yarn/Contracts/YarnBerryDependencyMeta.cs | 2 +- .../yarn/Contracts/YarnBerryLockfile.cs | 2 +- .../yarn/Contracts/YarnBerryLockfileEntry.cs | 2 +- .../yarn/Contracts/YarnBerryLockfileMetadata.cs | 2 +- .../yarn/Contracts/YarnBerryPeerDependencyMeta.cs | 2 +- .../yarn/Contracts/YarnBerryTypeConverter.cs | 2 +- 36 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLock.cs b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLock.cs index b9fa91c6b..17e8c7a26 100644 --- a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLock.cs +++ b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLock.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Conan.Contracts; using System.Text.Json.Serialization; -public class ConanLock +internal class ConanLock { [JsonPropertyName("version")] public string Version { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockGraph.cs b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockGraph.cs index 83620fd05..4ac8ee563 100644 --- a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockGraph.cs +++ b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockGraph.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Conan.Contracts; using System.Collections.Generic; using System.Text.Json.Serialization; -public class ConanLockGraph +internal class ConanLockGraph { [JsonPropertyName("revisions_enabled")] public bool RevisionsEnabled { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockNode.cs b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockNode.cs index 59607137b..9b2ecb181 100644 --- a/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockNode.cs +++ b/src/Microsoft.ComponentDetection.Detectors/conan/Contracts/ConanLockNode.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Conan.Contracts; using System.Text.Json.Serialization; using Microsoft.ComponentDetection.Contracts.TypedComponent; -public class ConanLockNode +internal class ConanLockNode { [JsonPropertyName("context")] public string Context { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonAuthorConverter.cs b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonAuthorConverter.cs index 103949514..baab2feb7 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonAuthorConverter.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonAuthorConverter.cs @@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm.Contracts; /// Converts the author field in a package.json file, which can be either a string or an object. /// String format: "Name <email> (url)" where email and url are optional. /// -public sealed partial class PackageJsonAuthorConverter : JsonConverter +internal sealed partial class PackageJsonAuthorConverter : JsonConverter { // Matches: Name (url) where email and url are optional // Examples: diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonEnginesConverter.cs b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonEnginesConverter.cs index 1fba1821d..cbf5bc84a 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonEnginesConverter.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonEnginesConverter.cs @@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm.Contracts; /// Engines is typically an object mapping engine names to version ranges, /// but can occasionally be an array of strings in malformed package.json files. /// -public sealed class PackageJsonEnginesConverter : JsonConverter?> +internal sealed class PackageJsonEnginesConverter : JsonConverter?> { /// public override IDictionary? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonWorkspacesConverter.cs b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonWorkspacesConverter.cs index ef30f7eef..8e5f0af8c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonWorkspacesConverter.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/Contracts/PackageJsonWorkspacesConverter.cs @@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm.Contracts; /// - An array of glob patterns: ["packages/*"] /// - An object with a packages field: { "packages": ["packages/*"] }. /// -public sealed class PackageJsonWorkspacesConverter : JsonConverter?> +internal sealed class PackageJsonWorkspacesConverter : JsonConverter?> { /// public override IList? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipReportGraphNode.cs b/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipReportGraphNode.cs index 867b5121a..19c9afaa9 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipReportGraphNode.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PipReportGraphNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; /// Internal state used by PipReportDetector to hold intermediate structure info until the final /// combination of dependencies and relationships is determined and can be returned. /// -public sealed record PipReportGraphNode +internal sealed record PipReportGraphNode { public PipReportGraphNode(PipComponent value, bool requested) { diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PythonVersion.cs b/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PythonVersion.cs index ce69b95b9..07ed07761 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PythonVersion.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/Contracts/PythonVersion.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using System.Linq; using System.Text.RegularExpressions; -public class PythonVersion : IComparable +internal class PythonVersion : IComparable { // This is a light C# port of the python version capture regex described here: // https://www.python.org/dev/peps/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/PnpmYamlV5.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/PnpmYamlV5.cs index 9dcd0f9dc..ad90eab2c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/PnpmYamlV5.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/PnpmYamlV5.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; /// /// Format for a Pnpm lock file version 5 as defined in https://github.com/pnpm/spec/blob/master/lockfile/5.md. /// -public class PnpmYamlV5 : PnpmYaml +internal class PnpmYamlV5 : PnpmYaml { [YamlMember(Alias = "dependencies")] public Dictionary Dependencies { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmHasDependenciesV6.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmHasDependenciesV6.cs index f53ce309f..ea88568dd 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmHasDependenciesV6.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmHasDependenciesV6.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using System.Collections.Generic; using YamlDotNet.Serialization; -public class PnpmHasDependenciesV6 : PnpmYaml +internal class PnpmHasDependenciesV6 : PnpmYaml { [YamlMember(Alias = "dependencies")] public Dictionary Dependencies { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6.cs index a0b6e80ff..fdda5a1e5 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6.cs @@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; /// In the "dedicated shrinkwrap", the inherited members from PnpmHasDependenciesV6 will be used. /// In the "shared shrinkwrap", the importers member will be used. /// -public class PnpmYamlV6 : PnpmHasDependenciesV6 +internal class PnpmYamlV6 : PnpmHasDependenciesV6 { [YamlMember(Alias = "importers")] public Dictionary Importers { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6Dependency.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6Dependency.cs index c931ba8e8..ecb011f8d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6Dependency.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V6/PnpmYamlV6Dependency.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using YamlDotNet.Serialization; -public class PnpmYamlV6Dependency +internal class PnpmYamlV6Dependency { [YamlMember(Alias = "version")] public string Version { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmHasDependenciesV9.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmHasDependenciesV9.cs index d087a16b5..f0e266e91 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmHasDependenciesV9.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmHasDependenciesV9.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using System.Collections.Generic; using YamlDotNet.Serialization; -public class PnpmHasDependenciesV9 : PnpmYaml +internal class PnpmHasDependenciesV9 : PnpmYaml { [YamlMember(Alias = "dependencies")] public Dictionary Dependencies { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9.cs index 34a20a34a..4efbbe345 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9.cs @@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; /// Issue tracking v9 specs: https://github.com/pnpm/spec/issues/6 /// Format should eventually get updated here: https://github.com/pnpm/spec/blob/master/lockfile/6.0.md. /// -public class PnpmYamlV9 : PnpmHasDependenciesV9 +internal class PnpmYamlV9 : PnpmHasDependenciesV9 { [YamlMember(Alias = "importers")] public Dictionary Importers { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9Dependency.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9Dependency.cs index 5722cd9d1..db819d131 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9Dependency.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/V9/PnpmYamlV9Dependency.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using YamlDotNet.Serialization; -public class PnpmYamlV9Dependency +internal class PnpmYamlV9Dependency { [YamlMember(Alias = "version")] public string Version { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryLock.cs b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryLock.cs index 679f65918..85e37a5be 100644 --- a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryLock.cs +++ b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryLock.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry.Contracts; // Represents Poetry.Lock file structure. [DataContract] -public class PoetryLock +internal class PoetryLock { [DataMember(Name = "Package")] public List Package { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryPackage.cs b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryPackage.cs index 9c5ca94d7..a0ef874e1 100644 --- a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryPackage.cs +++ b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetryPackage.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry.Contracts; using System.Runtime.Serialization; [DataContract] -public class PoetryPackage +internal class PoetryPackage { [DataMember(Name = "name")] public string Name { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetrySource.cs b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetrySource.cs index 146673bde..8b5bb26b5 100644 --- a/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetrySource.cs +++ b/src/Microsoft.ComponentDetection.Detectors/poetry/Contracts/PoetrySource.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry.Contracts; using System.Runtime.Serialization; -public class PoetrySource +internal class PoetrySource { [DataMember(Name = "type")] public string Type { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoLock.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoLock.cs index 3a8045421..a9205db00 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoLock.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoLock.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.Contracts; // Represents Cargo.Lock file structure. [DataContract] -public class CargoLock +internal class CargoLock { [DataMember(Name = "package")] public List Package { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoSbom.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoSbom.cs index 96c092193..6dee01b5d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoSbom.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoSbom.cs @@ -14,7 +14,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.Sbom.Contracts; /// /// Type of dependency. /// -public enum SbomKind +internal enum SbomKind { /// /// A dependency linked to the artifact produced by this crate. @@ -35,7 +35,7 @@ public enum SbomKind /// /// Represents the Cargo Software Bill of Materials (SBOM). /// -public class CargoSbom +internal class CargoSbom { /// /// Gets or sets the version of the SBOM. @@ -67,7 +67,7 @@ public class CargoSbom /// /// Represents a crate in the SBOM. /// -public class SbomCrate +internal class SbomCrate { /// /// Gets or sets the Cargo Package ID specification. @@ -93,7 +93,7 @@ public class SbomCrate /// /// Represents a dependency of a crate. /// -public class SbomDependency +internal class SbomDependency { /// /// Gets or sets the index into the crates array. @@ -109,7 +109,7 @@ public class SbomDependency /// /// Represents information about rustc used to perform the compilation. /// -public class Rustc +internal class Rustc { /// /// Gets or sets the compiler version. diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoToml.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoToml.cs index 9329d6364..9a3c57d31 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoToml.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Contracts/CargoToml.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.Contracts; using System.Runtime.Serialization; -public class CargoToml +internal class CargoToml { [DataMember(Name = "package")] public CargoPackage Package { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/swiftpm/Contracts/SwiftResolvedFile.cs b/src/Microsoft.ComponentDetection.Detectors/swiftpm/Contracts/SwiftResolvedFile.cs index 06b19e281..7cc0471ce 100644 --- a/src/Microsoft.ComponentDetection.Detectors/swiftpm/Contracts/SwiftResolvedFile.cs +++ b/src/Microsoft.ComponentDetection.Detectors/swiftpm/Contracts/SwiftResolvedFile.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent; /// /// Represents a Swift Package Manager component. /// -public class SwiftResolvedFile +internal class SwiftResolvedFile { [JsonPropertyName("pins")] public IList Pins { get; set; } @@ -15,7 +15,7 @@ public class SwiftResolvedFile [JsonPropertyName("version")] public int Version { get; set; } - public class SwiftDependency + internal class SwiftDependency { // The name of the package [JsonPropertyName("identity")] @@ -34,7 +34,7 @@ public class SwiftDependency [JsonPropertyName("state")] public SwiftState State { get; set; } - public class SwiftState + internal class SwiftState { // The commit hash of the package. [JsonPropertyName("revision")] diff --git a/src/Microsoft.ComponentDetection.Detectors/uv/UvDependency.cs b/src/Microsoft.ComponentDetection.Detectors/uv/UvDependency.cs index 442df6584..9d05954a2 100644 --- a/src/Microsoft.ComponentDetection.Detectors/uv/UvDependency.cs +++ b/src/Microsoft.ComponentDetection.Detectors/uv/UvDependency.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Detectors.Uv; -public class UvDependency +internal class UvDependency { public required string Name { get; init; } diff --git a/src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs b/src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs index 0f61f51d7..61ec1b532 100644 --- a/src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs +++ b/src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Uv; using Tomlyn; using Tomlyn.Model; -public class UvLock +internal class UvLock { // a list of packages with their dependencies public List Packages { get; set; } = []; diff --git a/src/Microsoft.ComponentDetection.Detectors/uv/UvPackage.cs b/src/Microsoft.ComponentDetection.Detectors/uv/UvPackage.cs index 9a1c9acd2..881a89869 100644 --- a/src/Microsoft.ComponentDetection.Detectors/uv/UvPackage.cs +++ b/src/Microsoft.ComponentDetection.Detectors/uv/UvPackage.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Detectors.Uv; using System.Collections.Generic; -public class UvPackage +internal class UvPackage { public required string Name { get; init; } diff --git a/src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs b/src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs index 80ea4ba15..75ebdaa0b 100644 --- a/src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs +++ b/src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Detectors.Uv; -public class UvSource +internal class UvSource { public string? Registry { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Annotation.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Annotation.cs index df17d80d4..dd80001e8 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Annotation.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Annotation.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg.Contracts; using System; using System.Text.Json.Serialization; -public class Annotation +internal class Annotation { [JsonPropertyName("annotationDate")] public DateTime Date { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/ManifestInfo.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/ManifestInfo.cs index 4fd150f98..29aad58e6 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/ManifestInfo.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/ManifestInfo.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg.Contracts; using System.Text.Json.Serialization; -public class ManifestInfo +internal class ManifestInfo { [JsonPropertyName("manifest-path")] public string ManifestPath { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Package.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Package.cs index bec371da8..7f55c1150 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Package.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/Package.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg.Contracts; using System.Text.Json.Serialization; -public class Package +internal class Package { [JsonPropertyName("SPDXID")] public string SPDXID { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/VcpkgSBOM.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/VcpkgSBOM.cs index 34bf19fd6..4b9601432 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/VcpkgSBOM.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/Contracts/VcpkgSBOM.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg.Contracts; /// /// Matches a subset of https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.1/schemas/spdx-schema.json. /// -public class VcpkgSBOM +internal class VcpkgSBOM { [JsonPropertyName("packages")] public Package[] Packages { get; set; } diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryDependencyMeta.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryDependencyMeta.cs index 0b8ca4fbd..a95c66f85 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryDependencyMeta.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryDependencyMeta.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; /// /// Represents the metadata of a dependency in the yarn.lock file for yarn v2+ (berry). /// -public sealed record YarnBerryDependencyMeta +internal sealed record YarnBerryDependencyMeta { /// /// Whether the dependency is pre-built. diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfile.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfile.cs index ec85bf709..6e8cec6a5 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfile.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfile.cs @@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; /// There is no official documentation for the format of the yarn.lock file. /// This is based on the source code of https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-core/sources/Project.ts. /// -public sealed record YarnBerryLockfile +internal sealed record YarnBerryLockfile { /// /// Gets the metadata of the yarn.lock file. diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileEntry.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileEntry.cs index 414a675b3..6ab98e3eb 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileEntry.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileEntry.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; /// Represents an entry in the yarn.lock file for yarn v2+ (berry). /// There is no official documentation for the format of the yarn.lock file. /// -public sealed record YarnBerryLockfileEntry +internal sealed record YarnBerryLockfileEntry { /// /// The version of the package, if available. diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileMetadata.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileMetadata.cs index e4f43f208..dad8077fd 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileMetadata.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryLockfileMetadata.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; /// /// Represents the metadata of the yarn.lock file for yarn v2+. /// -public sealed record YarnBerryLockfileMetadata +internal sealed record YarnBerryLockfileMetadata { /// /// Gets the version of the yarn.lock file. diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryPeerDependencyMeta.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryPeerDependencyMeta.cs index 85e35607a..ee9986f03 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryPeerDependencyMeta.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryPeerDependencyMeta.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; /// /// Represents the metadata of a peer dependency in the yarn.lock file for yarn v2+ (berry). /// -public sealed record YarnBerryPeerDependencyMeta +internal sealed record YarnBerryPeerDependencyMeta { /// /// Whether the dependency is optional. diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryTypeConverter.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryTypeConverter.cs index 09df6fdac..a915816be 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryTypeConverter.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Contracts/YarnBerryTypeConverter.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Contracts; using YamlDotNet.Serialization; /// -public class YarnBerryTypeConverter : IYamlTypeConverter +internal class YarnBerryTypeConverter : IYamlTypeConverter { private static readonly IDeserializer Deserializer = new DeserializerBuilder().Build(); From 7913f32e6c825eabb9f489b2f21cd99581f7a261 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 5 Mar 2026 20:51:13 -0800 Subject: [PATCH 3/6] refactor: make detector implementation details internal Make ~80 classes internal in the Detectors project: - Data model/contract classes (ConanLock, PnpmYaml variants, PoetryLock, SwiftResolvedFile, VcpkgSBOM, CargoToml/Sbom, YarnBerry types, npm converters, PipReportGraphNode, PythonVersion, UvLock/Package, etc.) - Parser implementations (GoModParser, YarnLockParser, RustCargoLockParser, MavenStyleDependencyGraphParserService, PnpmParsingUtilities, etc.) - Concrete detector classes (NpmComponentDetector, NuGetComponentDetector, GoComponentDetector, RustSbomDetector, etc.) - Linux scanner internals (LinuxScanner, all component factories, filters) - Service implementations (MavenCommandService, PythonCommandService, PyPiClient, PipCommandService, YarnLockFileFactory, etc.) Kept public (used by downstream consumers): - All interfaces (IComponentDetector, IMavenCommandService, etc.) - MvnCliComponentDetector, MavenWithFallbackDetector (used in is-checks) - PipComponentDetector, SimplePipComponentDetector, PipReportComponentDetector (mocked in tests by component-detection-internal) Updated test classes to work with internal types via InternalsVisibleTo. Part of #455 --- ...rosoft.ComponentDetection.Detectors.csproj | 2 + .../cocoapods/PodComponentDetector.cs | 2 +- .../conan/ConanLockComponentDetector.cs | 2 +- .../conda/CondaLockComponentDetector.cs | 2 +- .../dockerfile/DockerfileComponentDetector.cs | 2 +- .../dotnet/DotNetComponentDetector.cs | 2 +- .../go/GoComponentDetector.cs | 2 +- .../go/Parsers/GoCLIParser.cs | 2 +- .../go/Parsers/GoModParser.cs | 2 +- .../go/Parsers/GoParserFactory.cs | 2 +- .../go/Parsers/GoSumParser.cs | 2 +- .../gradle/GradleComponentDetector.cs | 2 +- .../ivy/IvyDetector.cs | 2 +- .../linux/Factories/CargoComponentFactory.cs | 2 +- .../linux/Factories/CondaComponentFactory.cs | 2 +- .../linux/Factories/DotnetComponentFactory.cs | 2 +- .../linux/Factories/GoComponentFactory.cs | 2 +- .../linux/Factories/LinuxComponentFactory.cs | 2 +- .../linux/Factories/MavenComponentFactory.cs | 2 +- .../linux/Factories/NpmComponentFactory.cs | 2 +- .../linux/Factories/PipComponentFactory.cs | 2 +- .../linux/Factories/PodComponentFactory.cs | 2 +- .../Factories/RubyGemsComponentFactory.cs | 2 +- .../linux/Filters/Mariner2ArtifactFilter.cs | 2 +- .../linux/LinuxApplicationLayerDetector.cs | 2 +- .../linux/LinuxContainerDetector.cs | 2 +- .../linux/LinuxScanner.cs | 2 +- .../maven/MavenCommandService.cs | 2 +- .../MavenStyleDependencyGraphParserService.cs | 2 +- .../npm/NpmComponentDetector.cs | 2 +- .../npm/NpmComponentDetectorWithRoots.cs | 2 +- .../npm/NpmLockfile3Detector.cs | 2 +- .../nuget/NuGetComponentDetector.cs | 2 +- .../nuget/NuGetPackagesConfigDetector.cs | 2 +- ...ectModelProjectCentricComponentDetector.cs | 2 +- .../pip/IPyPiClient.cs | 2 +- .../pip/PipCommandService.cs | 2 +- .../pip/PythonCommandService.cs | 2 +- .../pip/PythonResolver.cs | 2 +- .../pip/SimplePypiClient.cs | 2 +- .../pip/SimplePythonResolver.cs | 2 +- .../PnpmParsingUtilitiesBase.cs | 2 +- .../PnpmParsingUtilitiesFactory.cs | 2 +- .../PnpmV5ParsingUtilities.cs | 2 +- .../PnpmV6ParsingUtilities.cs | 2 +- .../PnpmV9ParsingUtilities.cs | 2 +- .../pnpm/PnpmComponentDetectorFactory.cs | 2 +- .../poetry/PoetryComponentDetector.cs | 2 +- .../ruby/RubyComponentDetector.cs | 2 +- .../rust/Parsers/RustCargoLockParser.cs | 2 +- .../rust/Parsers/RustCliParser.cs | 2 +- .../rust/Parsers/RustSbomParser.cs | 2 +- .../rust/RustMetadataContextBuilder.cs | 2 +- .../rust/RustSbomDetector.cs | 2 +- .../spdx/Spdx22ComponentDetector.cs | 2 +- .../swiftpm/SwiftResolvedComponentDetector.cs | 2 +- .../uv/UvLockComponentDetector.cs | 2 +- .../vcpkg/VcpkgComponentDetector.cs | 2 +- .../yarn/Parsers/YarnBlockFile.cs | 2 +- .../yarn/Parsers/YarnLockParser.cs | 2 +- .../yarn/YarnLockComponentDetector.cs | 2 +- .../yarn/YarnLockFileFactory.cs | 2 +- test/.editorconfig | 5 ++ .../ConanLockComponentDetectorTests.cs | 12 ++-- .../CondaLockComponentDetectorTests.cs | 6 +- .../DotNetComponentDetectorTests.cs | 40 +++++------ .../GoComponentDetectorTests.cs | 68 ++++++++++--------- .../GradleComponentDetectorTests.cs | 24 ++++--- .../IvyDetectorTests.cs | 16 +++-- .../NpmDetectorTests.cs | 32 +++++---- .../NpmDetectorWithRootsTests.cs | 38 ++++++----- .../NpmLockfile3DetectorTests.cs | 26 +++---- .../NuGetComponentDetectorTests.cs | 22 +++--- ...delProjectCentricComponentDetectorTests.cs | 36 +++++----- .../PnpmDetectorTests.cs | 50 +++++++------- .../PodDetectorTest.cs | 30 ++++---- .../PoetryComponentDetectorTests.cs | 8 ++- .../RubyDetectorTest.cs | 26 +++---- .../RustSbomDetectorTests.cs | 68 ++++++++++--------- .../SPDX22ComponentDetectorTests.cs | 12 ++-- .../SwiftResolvedDetectorTests.cs | 34 +++++----- .../UvLockDetectorTests.cs | 28 ++++---- .../VcpkgComponentDetectorTests.cs | 24 ++++--- .../YarnLockDetectorTests.cs | 42 ++++++------ .../nuget/NuGetPackagesConfigDetectorTests.cs | 8 ++- 85 files changed, 415 insertions(+), 364 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj index 86d7e413a..adebad6c7 100644 --- a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj +++ b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj @@ -2,8 +2,10 @@ + + diff --git a/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs index cf83f4a7d..8a23cad71 100644 --- a/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/cocoapods/PodComponentDetector.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; -public class PodComponentDetector : FileComponentDetector +internal class PodComponentDetector : FileComponentDetector { public PodComponentDetector( IComponentStreamEnumerableFactory componentStreamEnumerableFactory, diff --git a/src/Microsoft.ComponentDetection.Detectors/conan/ConanLockComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/conan/ConanLockComponentDetector.cs index b5a0a6b83..0181b843d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/conan/ConanLockComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/conan/ConanLockComponentDetector.cs @@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Detectors.Conan; using Microsoft.ComponentDetection.Detectors.Conan.Contracts; using Microsoft.Extensions.Logging; -public class ConanLockComponentDetector : FileComponentDetector, IDefaultOffComponentDetector +internal class ConanLockComponentDetector : FileComponentDetector, IDefaultOffComponentDetector { public ConanLockComponentDetector( IComponentStreamEnumerableFactory componentStreamEnumerableFactory, diff --git a/src/Microsoft.ComponentDetection.Detectors/conda/CondaLockComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/conda/CondaLockComponentDetector.cs index bb643e741..d6bf1bd7f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/conda/CondaLockComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/conda/CondaLockComponentDetector.cs @@ -14,7 +14,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry; using Microsoft.Extensions.Logging; using YamlDotNet.Serialization; -public class CondaLockComponentDetector : FileComponentDetector, IDefaultOffComponentDetector +internal class CondaLockComponentDetector : FileComponentDetector, IDefaultOffComponentDetector { public CondaLockComponentDetector( IComponentStreamEnumerableFactory componentStreamEnumerableFactory, diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index d1d19f3a9..5408a3783 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile; using Microsoft.Extensions.Logging; using Valleysoft.DockerfileModel; -public class DockerfileComponentDetector : FileComponentDetector, IDefaultOffComponentDetector +internal class DockerfileComponentDetector : FileComponentDetector, IDefaultOffComponentDetector { private readonly ICommandLineInvocationService commandLineInvocationService; private readonly IEnvironmentVariableService envVarService; diff --git a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs index 8770ce3bb..4e425531d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.DotNet; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class DotNetComponentDetector : FileComponentDetector +internal class DotNetComponentDetector : FileComponentDetector { private const string GlobalJsonFileName = "global.json"; private readonly ICommandLineInvocationService commandLineInvocationService; diff --git a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs index 2625d2f56..e99c82f28 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/GoComponentDetector.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class GoComponentDetector : FileComponentDetector +internal class GoComponentDetector : FileComponentDetector { private readonly HashSet projectRoots = []; diff --git a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoCLIParser.cs b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoCLIParser.cs index aea3c4355..7f194f109 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoCLIParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoCLIParser.cs @@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class GoCLIParser : IGoParser +internal class GoCLIParser : IGoParser { private readonly ILogger logger; private readonly IFileUtilityService fileUtilityService; diff --git a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoModParser.cs b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoModParser.cs index 2d3f98e45..f0972f755 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoModParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoModParser.cs @@ -12,7 +12,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class GoModParser : IGoParser +internal class GoModParser : IGoParser { private const string StartString = "require "; private readonly ILogger logger; diff --git a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoParserFactory.cs b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoParserFactory.cs index 336107d84..5c0b699d3 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoParserFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoParserFactory.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go; using Microsoft.ComponentDetection.Contracts; using Microsoft.Extensions.Logging; -public class GoParserFactory : IGoParserFactory +internal class GoParserFactory : IGoParserFactory { private readonly IFileUtilityService fileUtilityService; private readonly ICommandLineInvocationService commandLineInvocationService; diff --git a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoSumParser.cs b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoSumParser.cs index c612731a0..0efd43580 100644 --- a/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoSumParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/go/Parsers/GoSumParser.cs @@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class GoSumParser : IGoParser +internal class GoSumParser : IGoParser { private static readonly Regex GoSumRegex = new( @"(?.*)\s+(?.*?)(/go\.mod)?\s+(?.*)", diff --git a/src/Microsoft.ComponentDetection.Detectors/gradle/GradleComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/gradle/GradleComponentDetector.cs index 1d1da2124..3138f323c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/gradle/GradleComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/gradle/GradleComponentDetector.cs @@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Detectors.Gradle; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class GradleComponentDetector : FileComponentDetector, IComponentDetector +internal class GradleComponentDetector : FileComponentDetector, IComponentDetector { private const string DevConfigurationsEnvVar = "CD_GRADLE_DEV_CONFIGURATIONS"; private const string DevLockfilesEnvVar = "CD_GRADLE_DEV_LOCKFILES"; diff --git a/src/Microsoft.ComponentDetection.Detectors/ivy/IvyDetector.cs b/src/Microsoft.ComponentDetection.Detectors/ivy/IvyDetector.cs index d37cd86a9..e203849e2 100644 --- a/src/Microsoft.ComponentDetection.Detectors/ivy/IvyDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/ivy/IvyDetector.cs @@ -38,7 +38,7 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy; /// The file written out by the custom Ant task is a simple JSON file representing a series of calls to be made to /// the method. /// -public class IvyDetector : FileComponentDetector, IExperimentalDetector +internal class IvyDetector : FileComponentDetector, IExperimentalDetector { internal const string PrimaryCommand = "ant.bat"; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CargoComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CargoComponentFactory.cs index a76199aea..7f2a7c4f7 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CargoComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CargoComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Rust crate artifacts. /// -public class CargoComponentFactory : ArtifactComponentFactoryBase +internal class CargoComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Cargo; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CondaComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CondaComponentFactory.cs index 3d4be4d05..f9c2af303 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CondaComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/CondaComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Conda package artifacts. /// -public class CondaComponentFactory : ArtifactComponentFactoryBase +internal class CondaComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Conda; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs index 459f57f47..6cc5a88ca 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from .NET package artifacts. /// -public class DotnetComponentFactory : ArtifactComponentFactoryBase +internal class DotnetComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.NuGet; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/GoComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/GoComponentFactory.cs index d17163a10..9c19a8f3f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/GoComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/GoComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Go module artifacts. /// -public class GoComponentFactory : ArtifactComponentFactoryBase +internal class GoComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Go; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/LinuxComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/LinuxComponentFactory.cs index 3c20bc87f..606eb8db3 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/LinuxComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/LinuxComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from system package artifacts (apk, deb, rpm). /// -public class LinuxComponentFactory : ArtifactComponentFactoryBase +internal class LinuxComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Linux; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/MavenComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/MavenComponentFactory.cs index 4aa6fb64a..eee99074e 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/MavenComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/MavenComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Java archive artifacts. /// -public class MavenComponentFactory : ArtifactComponentFactoryBase +internal class MavenComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Maven; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/NpmComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/NpmComponentFactory.cs index 67505b7c1..79a94ead0 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/NpmComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/NpmComponentFactory.cs @@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from npm package artifacts. /// -public class NpmComponentFactory : ArtifactComponentFactoryBase +internal class NpmComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Npm; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PipComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PipComponentFactory.cs index b03bb3fb2..6f0e0086a 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PipComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PipComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Python package artifacts. /// -public class PipComponentFactory : ArtifactComponentFactoryBase +internal class PipComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Pip; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PodComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PodComponentFactory.cs index 48c4ef919..8d065fb8c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PodComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/PodComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from CocoaPods artifacts. /// -public class PodComponentFactory : ArtifactComponentFactoryBase +internal class PodComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.Pod; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/RubyGemsComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/RubyGemsComponentFactory.cs index f2774e0cb..b6954913f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/RubyGemsComponentFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/RubyGemsComponentFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; /// /// Factory for creating instances from Ruby gem artifacts. /// -public class RubyGemsComponentFactory : ArtifactComponentFactoryBase +internal class RubyGemsComponentFactory : ArtifactComponentFactoryBase { /// public override ComponentType SupportedComponentType => ComponentType.RubyGems; diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Filters/Mariner2ArtifactFilter.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Filters/Mariner2ArtifactFilter.cs index f772cc13a..b84e83b56 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/Filters/Mariner2ArtifactFilter.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Filters/Mariner2ArtifactFilter.cs @@ -14,7 +14,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Filters; /// but Mariner 2.0 no longer receives non-security updates and is deprecated as of July 2025. /// Related Syft PR: https://github.com/anchore/syft/pull/3008. /// -public class Mariner2ArtifactFilter : IArtifactFilter +internal class Mariner2ArtifactFilter : IArtifactFilter { /// public IEnumerable Filter(IEnumerable artifacts, Distro distro) diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs index 6f199c40f..b8144e596 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux; /// The Linux scanner service. /// The Docker service. /// The logger. -public class LinuxApplicationLayerDetector( +internal class LinuxApplicationLayerDetector( ILinuxScanner linuxScanner, IDockerService dockerService, ILogger logger diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs index 37f7b9a90..954c3a696 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs @@ -20,7 +20,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux; /// /// Detector for Linux container images. /// -public class LinuxContainerDetector( +internal class LinuxContainerDetector( ILinuxScanner linuxScanner, IDockerService dockerService, ILogger logger diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs index 8ff01a35f..959c2fb5c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs @@ -19,7 +19,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux; /// /// Scanner for Linux container layers using Syft. /// -public class LinuxScanner : ILinuxScanner +internal class LinuxScanner : ILinuxScanner { private const string ScannerImage = "governancecontainerregistry.azurecr.io/syft:v1.37.0@sha256:48d679480c6d272c1801cf30460556959c01d4826795be31d4fd8b53750b7d91"; diff --git a/src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs b/src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs index c585dd97a..5987b09ec 100644 --- a/src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs +++ b/src/Microsoft.ComponentDetection.Detectors/maven/MavenCommandService.cs @@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven; using Microsoft.ComponentDetection.Contracts.Internal; using Microsoft.Extensions.Logging; -public class MavenCommandService : IMavenCommandService +internal class MavenCommandService : IMavenCommandService { private const string DetectorLogPrefix = "MvnCli detector"; internal const string MvnCLIFileLevelTimeoutSecondsEnvVar = "MvnCLIFileLevelTimeoutSeconds"; diff --git a/src/Microsoft.ComponentDetection.Detectors/maven/MavenStyleDependencyGraphParserService.cs b/src/Microsoft.ComponentDetection.Detectors/maven/MavenStyleDependencyGraphParserService.cs index 885d99ea5..f77ed2eb1 100644 --- a/src/Microsoft.ComponentDetection.Detectors/maven/MavenStyleDependencyGraphParserService.cs +++ b/src/Microsoft.ComponentDetection.Detectors/maven/MavenStyleDependencyGraphParserService.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven; using Microsoft.ComponentDetection.Contracts; using Microsoft.Extensions.Logging; -public class MavenStyleDependencyGraphParserService : IMavenStyleDependencyGraphParserService +internal class MavenStyleDependencyGraphParserService : IMavenStyleDependencyGraphParserService { private readonly ILogger logger; diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs index d7e79f6cc..51b463919 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetector.cs @@ -12,7 +12,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm; using Microsoft.ComponentDetection.Detectors.Npm.Contracts; using Microsoft.Extensions.Logging; -public class NpmComponentDetector : FileComponentDetector +internal class NpmComponentDetector : FileComponentDetector { private static readonly JsonSerializerOptions JsonOptions = new() { diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetectorWithRoots.cs b/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetectorWithRoots.cs index 2ee6316c7..f9d529bb0 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetectorWithRoots.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/NpmComponentDetectorWithRoots.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm; using Microsoft.ComponentDetection.Detectors.Npm.Contracts; using Microsoft.Extensions.Logging; -public class NpmComponentDetectorWithRoots : NpmLockfileDetectorBase +internal class NpmComponentDetectorWithRoots : NpmLockfileDetectorBase { private static readonly JsonSerializerOptions JsonOptions = new() { diff --git a/src/Microsoft.ComponentDetection.Detectors/npm/NpmLockfile3Detector.cs b/src/Microsoft.ComponentDetection.Detectors/npm/NpmLockfile3Detector.cs index 5fbcdf0fd..723fc88f3 100644 --- a/src/Microsoft.ComponentDetection.Detectors/npm/NpmLockfile3Detector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/npm/NpmLockfile3Detector.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm; using Microsoft.ComponentDetection.Detectors.Npm.Contracts; using Microsoft.Extensions.Logging; -public class NpmLockfile3Detector : NpmLockfileDetectorBase +internal class NpmLockfile3Detector : NpmLockfileDetectorBase { private static readonly string NodeModules = NpmComponentUtilities.NodeModules; diff --git a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs index c4ccac918..4336ea24d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetComponentDetector.cs @@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class NuGetComponentDetector : FileComponentDetector +internal class NuGetComponentDetector : FileComponentDetector { private static readonly IEnumerable LowConfidencePackages = ["Newtonsoft.Json"]; diff --git a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetPackagesConfigDetector.cs b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetPackagesConfigDetector.cs index 8dfc06e5c..a6d8f3d70 100644 --- a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetPackagesConfigDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetPackagesConfigDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet; /// /// Detects NuGet packages in packages.config files. /// -public sealed class NuGetPackagesConfigDetector : FileComponentDetector +internal sealed class NuGetPackagesConfigDetector : FileComponentDetector { /// /// Initializes a new instance of the class. diff --git a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetProjectModelProjectCentricComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetProjectModelProjectCentricComponentDetector.cs index 068283dd4..dc5c3e7db 100644 --- a/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetProjectModelProjectCentricComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/nuget/NuGetProjectModelProjectCentricComponentDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class NuGetProjectModelProjectCentricComponentDetector : FileComponentDetector +internal class NuGetProjectModelProjectCentricComponentDetector : FileComponentDetector { public const string ProjectDependencyType = "project"; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs b/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs index bfff00904..be4fb2404 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/IPyPiClient.cs @@ -27,7 +27,7 @@ public interface IPyPiClient Task GetProjectAsync(PipDependencySpecification spec); } -public sealed class PyPiClient : IPyPiClient, IDisposable +internal sealed class PyPiClient : IPyPiClient, IDisposable { // Values used for cache creation private const long CACHEINTERVALSECONDS = 180; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs index 57f2a0c48..bf1edc7d6 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PipCommandService.cs @@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.ComponentDetection.Contracts; using Microsoft.Extensions.Logging; -public class PipCommandService : IPipCommandService +internal class PipCommandService : IPipCommandService { private const string PipReportDisableFastDepsEnvVar = "PipReportDisableFastDeps"; private const string PipReportIgnoreFileLevelIndexUrlEnvVar = "PipReportIgnoreFileLevelIndexUrl"; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PythonCommandService.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PythonCommandService.cs index 962003f9c..f5bfdc2a6 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PythonCommandService.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PythonCommandService.cs @@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class PythonCommandService : IPythonCommandService +internal class PythonCommandService : IPythonCommandService { private readonly ICommandLineInvocationService commandLineInvocationService; private readonly IPathUtilityService pathUtilityService; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/PythonResolver.cs b/src/Microsoft.ComponentDetection.Detectors/pip/PythonResolver.cs index 98c405c9b..d33493c6c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/PythonResolver.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/PythonResolver.cs @@ -12,7 +12,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.Extensions.Logging; using MoreLinq; -public class PythonResolver : PythonResolverBase, IPythonResolver +internal class PythonResolver : PythonResolverBase, IPythonResolver { private static readonly JsonSerializerOptions JsonSerializerOptions = new() { diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/SimplePypiClient.cs b/src/Microsoft.ComponentDetection.Detectors/pip/SimplePypiClient.cs index 52be242f9..16ea10f0d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/SimplePypiClient.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/SimplePypiClient.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.Extensions.Logging; using Polly; -public sealed class SimplePyPiClient : ISimplePyPiClient, IDisposable +internal sealed class SimplePyPiClient : ISimplePyPiClient, IDisposable { // Values used for cache creation private const long CACHEINTERVALSECONDS = 180; diff --git a/src/Microsoft.ComponentDetection.Detectors/pip/SimplePythonResolver.cs b/src/Microsoft.ComponentDetection.Detectors/pip/SimplePythonResolver.cs index e2bae4984..9bbac3d05 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pip/SimplePythonResolver.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pip/SimplePythonResolver.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.Extensions.Logging; using MoreLinq; -public class SimplePythonResolver : PythonResolverBase, ISimplePythonResolver +internal class SimplePythonResolver : PythonResolverBase, ISimplePythonResolver { private static readonly Regex VersionRegex = new(@"-((\d+)((\.)\w+((\+|\.)\w*)*)*)(.tar|-)", RegexOptions.Compiled); diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesBase.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesBase.cs index c94b88a61..da1770e5f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesBase.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesBase.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using Microsoft.ComponentDetection.Contracts; using YamlDotNet.Serialization; -public abstract class PnpmParsingUtilitiesBase +internal abstract class PnpmParsingUtilitiesBase where T : PnpmYaml { public T DeserializePnpmYamlFile(string fileContent) diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesFactory.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesFactory.cs index f4e4ddd7c..a286c7110 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesFactory.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using System.IO; using YamlDotNet.Serialization; -public static class PnpmParsingUtilitiesFactory +internal static class PnpmParsingUtilitiesFactory { public static PnpmParsingUtilitiesBase Create() where T : PnpmYaml diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV5ParsingUtilities.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV5ParsingUtilities.cs index 87b850e62..e25a42499 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV5ParsingUtilities.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV5ParsingUtilities.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.TypedComponent; -public class PnpmV5ParsingUtilities : PnpmParsingUtilitiesBase +internal class PnpmV5ParsingUtilities : PnpmParsingUtilitiesBase where T : PnpmYaml { public override DetectedComponent CreateDetectedComponentFromPnpmPath(string pnpmPackagePath) diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV6ParsingUtilities.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV6ParsingUtilities.cs index 9e8712944..f68c9a7a6 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV6ParsingUtilities.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV6ParsingUtilities.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.TypedComponent; -public class PnpmV6ParsingUtilities : PnpmParsingUtilitiesBase +internal class PnpmV6ParsingUtilities : PnpmParsingUtilitiesBase where T : PnpmYaml { public override DetectedComponent CreateDetectedComponentFromPnpmPath(string pnpmPackagePath) diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV9ParsingUtilities.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV9ParsingUtilities.cs index f08447c86..501893539 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV9ParsingUtilities.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmV9ParsingUtilities.cs @@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.TypedComponent; -public class PnpmV9ParsingUtilities : PnpmParsingUtilitiesBase +internal class PnpmV9ParsingUtilities : PnpmParsingUtilitiesBase where T : PnpmYaml { public override DetectedComponent CreateDetectedComponentFromPnpmPath(string pnpmPackagePath) diff --git a/src/Microsoft.ComponentDetection.Detectors/pnpm/PnpmComponentDetectorFactory.cs b/src/Microsoft.ComponentDetection.Detectors/pnpm/PnpmComponentDetectorFactory.cs index 8ed3c7f5b..1756be515 100644 --- a/src/Microsoft.ComponentDetection.Detectors/pnpm/PnpmComponentDetectorFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/pnpm/PnpmComponentDetectorFactory.cs @@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm; /// Factory responsible for constructing the proper and recording its dependency /// graph based on the file found during file component detection. /// -public class PnpmComponentDetectorFactory : FileComponentDetector +internal class PnpmComponentDetectorFactory : FileComponentDetector { /// /// The maximum version of the report specification that this detector can handle. diff --git a/src/Microsoft.ComponentDetection.Detectors/poetry/PoetryComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/poetry/PoetryComponentDetector.cs index 1be702461..554ef477c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/poetry/PoetryComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/poetry/PoetryComponentDetector.cs @@ -14,7 +14,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry; using Microsoft.Extensions.Logging; using Tomlyn; -public class PoetryComponentDetector : FileComponentDetector, IExperimentalDetector +internal class PoetryComponentDetector : FileComponentDetector, IExperimentalDetector { public PoetryComponentDetector( IComponentStreamEnumerableFactory componentStreamEnumerableFactory, diff --git a/src/Microsoft.ComponentDetection.Detectors/ruby/RubyComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/ruby/RubyComponentDetector.cs index 93d9b7f82..c03545079 100644 --- a/src/Microsoft.ComponentDetection.Detectors/ruby/RubyComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/ruby/RubyComponentDetector.cs @@ -39,7 +39,7 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class RubyComponentDetector : FileComponentDetector +internal class RubyComponentDetector : FileComponentDetector { private static readonly Regex HeadingRegex = new Regex("^[A-Z ]+$", RegexOptions.Compiled); private static readonly Regex DependencyDefinitionRegex = new Regex("^ {4}[A-Za-z-]+", RegexOptions.Compiled); diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCargoLockParser.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCargoLockParser.cs index a7efc2270..87eb1443d 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCargoLockParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCargoLockParser.cs @@ -18,7 +18,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust; /// /// Detector for Cargo.lock files. /// -public class RustCargoLockParser : IRustCargoLockParser +internal class RustCargoLockParser : IRustCargoLockParser { //// PkgName[ Version][ (Source)] private static readonly Regex DependencyFormatRegex = new Regex( diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCliParser.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCliParser.cs index 18bc0ac5e..11ac3c101 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCliParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustCliParser.cs @@ -18,7 +18,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust; /// Parser for Cargo.toml files using cargo metadata command or cached metadata, /// with optional ownership-aware component registration. /// -public class RustCliParser : IRustCliParser +internal class RustCliParser : IRustCliParser { private readonly ICommandLineInvocationService cliService; private readonly IEnvironmentVariableService envVarService; diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustSbomParser.cs b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustSbomParser.cs index 5763fb462..0fa15001a 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustSbomParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/Parsers/RustSbomParser.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust; /// /// Detector for Cargo SBOM (.cargo-sbom.json) files. /// -public class RustSbomParser : IRustSbomParser +internal class RustSbomParser : IRustSbomParser { private const string CratesIoSource = "registry+https://github.com/rust-lang/crates.io-index"; diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/RustMetadataContextBuilder.cs b/src/Microsoft.ComponentDetection.Detectors/rust/RustMetadataContextBuilder.cs index 9f5fd2e4f..c728e227e 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/RustMetadataContextBuilder.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/RustMetadataContextBuilder.cs @@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust; using Microsoft.Extensions.Logging; using static Microsoft.ComponentDetection.Detectors.Rust.IRustMetadataContextBuilder; -public class RustMetadataContextBuilder : IRustMetadataContextBuilder +internal class RustMetadataContextBuilder : IRustMetadataContextBuilder { private readonly ILogger logger; private readonly ICommandLineInvocationService cliService; diff --git a/src/Microsoft.ComponentDetection.Detectors/rust/RustSbomDetector.cs b/src/Microsoft.ComponentDetection.Detectors/rust/RustSbomDetector.cs index 9212af429..a37f47dd7 100644 --- a/src/Microsoft.ComponentDetection.Detectors/rust/RustSbomDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/rust/RustSbomDetector.cs @@ -21,7 +21,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust; /// /// A unified Rust detector that orchestrates SBOM, CLI, and Crate parsing. /// -public class RustSbomDetector : FileComponentDetector +internal class RustSbomDetector : FileComponentDetector { private const string CargoTomlFileName = "Cargo.toml"; private const string CargoLockFileName = "Cargo.lock"; diff --git a/src/Microsoft.ComponentDetection.Detectors/spdx/Spdx22ComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/spdx/Spdx22ComponentDetector.cs index 5a3b4bb1f..bb3aa36ce 100644 --- a/src/Microsoft.ComponentDetection.Detectors/spdx/Spdx22ComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/spdx/Spdx22ComponentDetector.cs @@ -18,7 +18,7 @@ namespace Microsoft.ComponentDetection.Detectors.Spdx; /// Spdx22ComponentDetector discover SPDX SBOM files in JSON format and create components with the information about /// what SPDX document describes. /// -public class Spdx22ComponentDetector : FileComponentDetector, IDefaultOffComponentDetector +internal class Spdx22ComponentDetector : FileComponentDetector, IDefaultOffComponentDetector { private readonly IEnumerable supportedSPDXVersions = ["SPDX-2.2"]; diff --git a/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs index a5d4e6bc4..64aaa5f09 100644 --- a/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Swift; /// /// Detects Swift Package Manager components. /// -public class SwiftResolvedComponentDetector : FileComponentDetector, IDefaultOffComponentDetector +internal class SwiftResolvedComponentDetector : FileComponentDetector, IDefaultOffComponentDetector { // We are only interested in packages coming from remote sources such as git // The Package Kind is not an enum because the Swift Package Manager contract does not specify the possible values. diff --git a/src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs index 4b1ec4256..7bcc4cef7 100644 --- a/src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs @@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Detectors.Uv; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class UvLockComponentDetector : FileComponentDetector, IExperimentalDetector +internal class UvLockComponentDetector : FileComponentDetector, IExperimentalDetector { public UvLockComponentDetector( IComponentStreamEnumerableFactory componentStreamEnumerableFactory, diff --git a/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs index c2fac266a..49cbd1016 100644 --- a/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/vcpkg/VcpkgComponentDetector.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg; using Microsoft.ComponentDetection.Detectors.Vcpkg.Contracts; using Microsoft.Extensions.Logging; -public class VcpkgComponentDetector : FileComponentDetector +internal class VcpkgComponentDetector : FileComponentDetector { private const string VcpkgInstalledFolder = "vcpkg_installed"; private const string ManifestInfoFile = "manifest-info.json"; diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnBlockFile.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnBlockFile.cs index c7dd0e0b0..d99c38862 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnBlockFile.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnBlockFile.cs @@ -40,7 +40,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers; /// {key}: "{value}" /// ... /// -public class YarnBlockFile : IYarnBlockFile +internal class YarnBlockFile : IYarnBlockFile { private static readonly Regex YarnV1Regex = new Regex("(.*)\\s\"(.*)\"", RegexOptions.Compiled); diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnLockParser.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnLockParser.cs index e1e0cd665..196a299dc 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnLockParser.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnLockParser.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers; using Microsoft.ComponentDetection.Contracts; using Microsoft.Extensions.Logging; -public class YarnLockParser : IYarnLockParser +internal class YarnLockParser : IYarnLockParser { private const string VersionString = "version"; diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.cs index 5f743585c..16fcf431f 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockComponentDetector.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn; using Microsoft.ComponentDetection.Detectors.Npm; using Microsoft.Extensions.Logging; -public class YarnLockComponentDetector : FileComponentDetector +internal class YarnLockComponentDetector : FileComponentDetector { private readonly IYarnLockFileFactory yarnLockFileFactory; diff --git a/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockFileFactory.cs b/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockFileFactory.cs index e764c8fdd..b002c0765 100644 --- a/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockFileFactory.cs +++ b/src/Microsoft.ComponentDetection.Detectors/yarn/YarnLockFileFactory.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn; using Microsoft.ComponentDetection.Detectors.Yarn.Parsers; using Microsoft.Extensions.Logging; -public class YarnLockFileFactory : IYarnLockFileFactory +internal class YarnLockFileFactory : IYarnLockFileFactory { private readonly IEnumerable parsers; diff --git a/test/.editorconfig b/test/.editorconfig index e33d0b57a..c7eee2cc4 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -39,6 +39,11 @@ dotnet_diagnostic.CA1062.severity = none # https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1707 dotnet_diagnostic.CA1707.severity = none +# CA1812: Avoid uninstantiated internal classes +# Justification: Test classes may use internal types via InternalsVisibleTo +# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1812 +dotnet_diagnostic.CA1812.severity = none + # FAA0001: AwesomeAssertions analyzer suggestions # Justification: Suppress style suggestions that would be treated as errors # https://awesomeassertions.org/tips/ diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/ConanLockComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/ConanLockComponentDetectorTests.cs index 09ef06092..57a52f977 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/ConanLockComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/ConanLockComponentDetectorTests.cs @@ -16,8 +16,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class ConanLockComponentDetectorTests : BaseDetectorTest +public class ConanLockComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly string testConanLockString = @"{ ""graph_lock"": { ""nodes"": { @@ -138,7 +140,7 @@ public class ConanLockComponentDetectorTests : BaseDetectorTest +public class CondaLockComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task CondaComponentDetector_TestCondaLockFileAsync() { @@ -83,7 +85,7 @@ public async Task CondaComponentDetector_TestCondaLockFileAsync() optional: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("conda-lock.yml", condaLockContent) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/DotNetComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/DotNetComponentDetectorTests.cs index d4941512a..c1f165771 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/DotNetComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/DotNetComponentDetectorTests.cs @@ -26,10 +26,12 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class DotNetComponentDetectorTests : BaseDetectorTest +public class DotNetComponentDetectorTests { private static readonly string RootDir = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:" : @"/"; + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock> mockLogger = new(); // uses ExecuteCommandAsync @@ -53,7 +55,7 @@ public class DotNetComponentDetectorTests : BaseDetectorTest public DotNetComponentDetectorTests() { - this.DetectorTestUtility.AddServiceMock(this.mockLogger) + this.detectorTestUtility.AddServiceMock(this.mockLogger) .AddServiceMock(this.mockCommandLineInvocationService) .AddServiceMock(this.mockDirectoryUtilityService) .AddServiceMock(this.mockFileUtilityService) @@ -240,7 +242,7 @@ private static Stream StreamFromString(string content) [TestMethod] public async Task TestDotNetDetectorWithNoFiles_ReturnsSuccessfullyAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility.ExecuteDetectorAsync(); + var (scanResult, componentRecorder) = await this.detectorTestUtility.ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); componentRecorder.GetDetectedComponents().Should().BeEmpty(); @@ -256,7 +258,7 @@ public async Task TestDotNetDetectorGlobalJson_ReturnsSDKVersion() this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -290,7 +292,7 @@ public async Task TestDotNetDetectorGlobalJsonWithComments_ReturnsSDKVersion() this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -322,7 +324,7 @@ public async Task TestDotNetDetectorGlobalJsonWithTrailingCommas_ReturnsSDKVersi this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(-1); // force reading from file instead of dotnet --version - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -353,7 +355,7 @@ public async Task TestDotNetDetectorGlobalJsonWithoutVersion() this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -376,7 +378,7 @@ public async Task TestDotNetDetectorGlobalJsonRollForward_ReturnsSDKVersion() this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(0, "8.0.808"); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -400,7 +402,7 @@ public async Task TestDotNetDetectorGlobalJsonDotNetVersionFails_ReturnsSDKVersi this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -424,7 +426,7 @@ public async Task TestDotNetDetectorGlobalJsonDotNetVersionThrows_ReturnsSDKVers this.AddFile(Path.Combine(RootDir, "path", "global.json"), globalJson); this.SetCommandResult((c, d) => throw new InvalidOperationException()); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -446,7 +448,7 @@ public async Task TestDotNetDetectorNoGlobalJson_ReturnsDotNetVersion() this.AddFile(projectPath, null); this.SetCommandResult(0, "86.75.309"); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -467,7 +469,7 @@ public async Task TestDotNetDetectorNoGlobalJsonNoDotnet_ReturnsUnknownVersion() this.AddFile(projectPath, null); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -490,7 +492,7 @@ public async Task TestDotNetDetectorInvalidProjectName_ReturnsUnknownVersion() this.AddDirectory(outputPath); this.SetCommandResult(-1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -511,7 +513,7 @@ public async Task TestDotNetDetectorMultipleTargetFrameworks() this.AddFile(projectPath, null); this.SetCommandResult(0, "1.2.3"); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -563,7 +565,7 @@ public async Task TestDotNetDetectorMultipleProjectsWithDifferentOutputTypeAndSd this.AddFile(Path.Combine(applicationOutputPath, "Release", "net8.0", "application.dll"), applicationAssemblyStream); this.AddFile(Path.Combine(applicationOutputPath, "Release", "net4.8", "application.exe"), applicationAssemblyStream); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(libraryAssetsPath, libraryAssets) .WithFile(applicationAssetsPath, applicationAssets) .ExecuteDetectorAsync(); @@ -602,7 +604,7 @@ public async Task TestDotNetDetectorExe() var applicationAssemblyStream = File.OpenRead(Assembly.GetEntryAssembly().Location); this.AddFile(Path.Combine(applicationOutputPath, "Release", "net4.8", "application.exe"), applicationAssemblyStream); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(applicationAssetsPath, applicationAssets) .ExecuteDetectorAsync(); @@ -639,7 +641,7 @@ public async Task TestDotNetDetectorInvalidOutputAssembly() this.AddFile(Path.Combine(libraryOutputPath, "Release", "net6.0", "library.dll"), libraryAssemblyStream); this.AddFile(Path.Combine(libraryOutputPath, "Release", "netstandard2.0", "library.dll"), libraryAssemblyStream); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(libraryAssetsPath, libraryAssets) .ExecuteDetectorAsync(); @@ -674,7 +676,7 @@ public async Task TestDotNetDetectorNoGlobalJsonSourceRoot() }; }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("project.assets.json", projectAssets) .ExecuteDetectorAsync(); @@ -730,7 +732,7 @@ public async Task TestDotNetDetectorRebasePaths(string additionalPathSegment) this.AddFile(Path.Combine(libraryOutputPath, "Release", "net6.0", "library.dll"), libraryAssemblyStream); this.AddFile(Path.Combine(libraryOutputPath, "Release", "netstandard2.0", "library.dll"), libraryAssemblyStream); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(libraryAssetsPath, libraryAssets) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentDetectorTests.cs index 7f159d323..55388510e 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentDetectorTests.cs @@ -21,8 +21,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class GoComponentDetectorTests : BaseDetectorTest +public class GoComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock commandLineMock; private readonly Mock envVarService; private readonly Mock fileUtilityServiceMock; @@ -42,15 +44,15 @@ public GoComponentDetectorTests() this.commandLineMock.Setup(x => x.CanCommandBeLocatedAsync("go", null, It.IsAny(), It.IsAny())) .ReturnsAsync(false); - this.DetectorTestUtility.AddServiceMock(this.commandLineMock); + this.detectorTestUtility.AddServiceMock(this.commandLineMock); this.envVarService = new Mock(); this.envVarService.Setup(x => x.IsEnvironmentVariableValueTrue("DisableGoCliScan")).Returns(true); - this.DetectorTestUtility.AddServiceMock(this.envVarService); + this.detectorTestUtility.AddServiceMock(this.envVarService); this.fileUtilityServiceMock = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.fileUtilityServiceMock); + this.detectorTestUtility.AddServiceMock(this.fileUtilityServiceMock); this.mockLogger = new Mock>(); - this.DetectorTestUtility.AddServiceMock(this.mockLogger); - this.DetectorTestUtility.AddServiceMock(this.mockParserFactory); + this.detectorTestUtility.AddServiceMock(this.mockLogger); + this.detectorTestUtility.AddServiceMock(this.mockParserFactory); } private void SetupMockGoModParser() @@ -92,7 +94,7 @@ public async Task TestGoModDetectorWithValidFile_ReturnsSuccessfullyAsync() )"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -119,7 +121,7 @@ public async Task TestGoModDetector_CommentsOnFile_CommentsAreIgnoredAsync() github.com/kr/pretty v0.1.0 // indirect )"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -148,7 +150,7 @@ public async Task TestGoSumDetectorWithValidFile_ReturnsSuccessfullyAsync() )"; this.SetupActualGoSumParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.sum", goSum) .ExecuteDetectorAsync(); @@ -185,7 +187,7 @@ public async Task TestGoModDetector_MultipleSpaces_ReturnsSuccessfullyAsync() )"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -223,7 +225,7 @@ public async Task TestGoModDetector_ComponentsWithMultipleLocations_ReturnsSucce github.com/Azure/go-autorest v10.15.2+incompatible )"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod1) .WithFile("go.mod", goMod2, fileLocation: Path.Join(Path.GetTempPath(), "another-location", "go.mod")) .ExecuteDetectorAsync(); @@ -250,7 +252,7 @@ four score and seven bugs ago $#26^#25%4"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", invalidGoMod) .ExecuteDetectorAsync(); @@ -274,7 +276,7 @@ go 1.18 this.SetupActualGoModParser(); this.SetupActualGoSumParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .WithFile("go.mod", goMod, ["go.mod"]) .WithFile("go.sum", goSum) @@ -306,7 +308,7 @@ go 1.18 )"; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -332,7 +334,7 @@ public async Task TestGoSumDetection_TwoEntriesForTheSameComponent_ReturnsSucces )"; this.SetupActualGoSumParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.sum", goSum) .ExecuteDetectorAsync(); @@ -358,7 +360,7 @@ public async Task TestGoModDetector_DetectorOnlyDetectInsideRequireSectionAsync( ) "; this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -464,7 +466,7 @@ a v1.5.0 // indirect this.envVarService.Setup(x => x.IsEnvironmentVariableValueTrue("DisableGoCliScan")).Returns(false); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -516,7 +518,7 @@ a v1.5.0 // indirect this.envVarService.Setup(x => x.IsEnvironmentVariableValueTrue("DisableGoCliScan")).Returns(false); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -569,7 +571,7 @@ go 1.11 this.envVarService.Setup(x => x.IsEnvironmentVariableValueTrue("DisableGoCliScan")).Returns(false); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -631,7 +633,7 @@ a v1.5.0 // indirect this.fileUtilityServiceMock.Setup(fs => fs.Exists(It.IsAny())) .Returns(true); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -690,7 +692,7 @@ github v1.5.0 // indirect .Returns(true); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -744,7 +746,7 @@ github v1.5.0 // indirect this.envVarService.Setup(x => x.IsEnvironmentVariableValueTrue("DisableGoCliScan")).Returns(false); this.SetupActualGoModParser(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -802,7 +804,7 @@ public async Task GoModDetector_GoCliIs1_11OrGreater_GoGraphIsExecutedAsync() }) .Verifiable(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -831,7 +833,7 @@ public async Task GoModDetector_GoCliIs111OrLessThan1_11_GoGraphIsNotExecutedAsy StdOut = "go version go1.10.6 windows/amd64", }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", goMod) .ExecuteDetectorAsync(); @@ -863,7 +865,7 @@ public async Task GoModDetector_GoModFileFound_GoModParserIsExecuted() StdOut = "go version go1.10.6 windows/amd64", }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty) .ExecuteDetectorAsync(); @@ -892,7 +894,7 @@ public async Task GoDetector_GoSum_GoSumParserExecuted(bool goCliSucceeds) // Setup go sum parser to succeed this.mockGoSumParser.Setup(p => p.ParseAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.sum", string.Empty) .ExecuteDetectorAsync(); @@ -916,7 +918,7 @@ public async Task GoDetector_GoSum_GoSumParserExecutedIfCliDisabled() // Setup go sum parser to succeed goSumParserMock.Setup(p => p.ParseAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.sum", string.Empty) .ExecuteDetectorAsync(); @@ -935,7 +937,7 @@ public async Task GoModDetector_ExecutingGoVersionFails_DetectorDoesNotFail() this.commandLineMock.Setup(x => x.ExecuteCommandAsync("go", null, null, default, It.Is(p => p.SequenceEqual(new List { "version" }.ToArray())))) .Throws(new InvalidOperationException("Failed to execute go version")); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty) .ExecuteDetectorAsync(); @@ -1005,7 +1007,7 @@ public async Task GoDetector_GoMod_VerifyNestedRootsUnderGTE117_AreSkipped() }); var root = Path.Combine("C:", "root"); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "b", "go.mod")) @@ -1048,7 +1050,7 @@ public async Task GoDetector_GoMod_VerifyNestedRootsUnderLT117AreNotSkipped() }; }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "b", "go.mod")) @@ -1101,7 +1103,7 @@ public async Task GoDetector_GoMod_VerifyNestedRootsAreNotSkippedIfParentParseFa return true; }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "b", "go.mod")) @@ -1141,7 +1143,7 @@ public async Task GoDetector_GoSum_VerifyNestedRootsUnderGoSum_AreSkipped() processedFiles.Add(file.Location); }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "b", "go.mod")) @@ -1189,7 +1191,7 @@ public async Task GoDetector_GoSum_VerifyNestedRootsAreNotSkippedIfParentParseFa return file.Location != Path.Combine(root, "a", "go.sum"); }); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("go.sum", string.Empty, fileLocation: Path.Combine(root, "a", "go.sum")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "a", "go.mod")) .WithFile("go.mod", string.Empty, fileLocation: Path.Combine(root, "a", "b", "go.mod")) diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/GradleComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/GradleComponentDetectorTests.cs index 0632e801d..8050fac44 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/GradleComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/GradleComponentDetectorTests.cs @@ -18,20 +18,22 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class GradleComponentDetectorTests : BaseDetectorTest +public class GradleComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock envVarService; public GradleComponentDetectorTests() { this.envVarService = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.envVarService); + this.detectorTestUtility.AddServiceMock(this.envVarService); } [TestMethod] public async Task TestGradleDetectorWithNoFiles_ReturnsSuccessfullyAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -46,7 +48,7 @@ public async Task TestGradleDetectorWithValidFile_DetectsComponentsSuccessfullyA org.springframework:spring-core:5.0.5.RELEASE org.springframework:spring-jcl:5.0.5.RELEASE"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", validFileOne) .ExecuteDetectorAsync(); @@ -77,7 +79,7 @@ public async Task TestGradleDetectorWithValidSingleLockfilePerProject_DetectsCom org.springframework:spring-core:5.0.5.RELEASE=debugCompile,releaseCompile org.springframework:spring-jcl:5.0.5.RELEASE=lintClassPath,debugCompile,releaseCompile"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", validFileOne) .ExecuteDetectorAsync(); @@ -116,7 +118,7 @@ public async Task TestGradleDetectorWithValidFiles_ReturnsSuccessfullyAsync() org.msgpack:msgpack-core:0.8.16 org.springframework:spring-jcl:5.0.5.RELEASE"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", validFileOne) .WithFile("gradle2.lockfile", validFileTwo) .ExecuteDetectorAsync(); @@ -161,7 +163,7 @@ public async Task TestGradleDetector_SameComponentDifferentLocations_DifferentLo var validFileTwo = "org.springframework:spring-beans:5.0.5.RELEASE"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", validFileOne) .WithFile("gradle2.lockfile", validFileTwo) .ExecuteDetectorAsync(); @@ -199,7 +201,7 @@ lorem ipsum four score and seven bugs ago $#26^#25%4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", invalidFileOne) .WithFile("gradle2.lockfile", validFileTwo) .ExecuteDetectorAsync(); @@ -241,7 +243,7 @@ public async Task TestGradleDetector_DevDependenciesByLockfileNameAsync() var devLockfile2 = @"org.jacoco:org.jacoco.agent:0.8.8"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("settings-gradle.lockfile", devLockfile1) .WithFile("buildscript-gradle.lockfile", devLockfile2) .WithFile("gradle.lockfile", regularLockfile) @@ -297,7 +299,7 @@ public async Task TestGradleDetector_DevDependenciesByDevLockfileEnvironmentAsyn this.envVarService.Setup(x => x.GetListEnvironmentVariable("CD_GRADLE_DEV_LOCKFILES", ",")).Returns(["dev1\\gradle.lockfile", "dev2\\gradle.lockfile"]); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("dev1\\gradle.lockfile", devLockfile1) .WithFile("dev2\\gradle.lockfile", devLockfile2) .WithFile("prod\\gradle.lockfile", regularLockfile) @@ -350,7 +352,7 @@ public async Task TestGradleDetector_DevDependenciesByDevConfigurationEnvironmen this.envVarService.Setup(x => x.GetListEnvironmentVariable("CD_GRADLE_DEV_CONFIGURATIONS", ",")).Returns(["testDebugUnitTest", "testReleaseUnitTest"]); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("gradle.lockfile", lockfile) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/IvyDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/IvyDetectorTests.cs index 3935424ca..09808ad6f 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/IvyDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/IvyDetectorTests.cs @@ -17,14 +17,16 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class IvyDetectorTests : BaseDetectorTest +public class IvyDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock commandLineMock; public IvyDetectorTests() { this.commandLineMock = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.commandLineMock); + this.detectorTestUtility.AddServiceMock(this.commandLineMock); } [TestMethod] @@ -33,7 +35,7 @@ public async Task IfAntIsNotAvailableThenExitDetectorGracefullyAsync() this.commandLineMock.Setup(x => x.CanCommandBeLocatedAsync(IvyDetector.PrimaryCommand, IvyDetector.AdditionalValidCommands, IvyDetector.AntVersionArgument)) .ReturnsAsync(false); - var (detectorResult, componentRecorder) = await this.DetectorTestUtility.ExecuteDetectorAsync(); + var (detectorResult, componentRecorder) = await this.detectorTestUtility.ExecuteDetectorAsync(); componentRecorder.GetDetectedComponents().Should().BeEmpty(); detectorResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -52,7 +54,7 @@ public async Task AntAvailableHappyPathAsync() this.IvyHappyPath(content: registerUsageContent); - var (detectorResult, componentRecorder) = await this.DetectorTestUtility.ExecuteDetectorAsync(); + var (detectorResult, componentRecorder) = await this.detectorTestUtility.ExecuteDetectorAsync(); var detectedComponents = componentRecorder.GetDetectedComponents(); // IsDevelopmentDependency = true in componentRecorder but null in detectedComponents... why? detectedComponents.Should().HaveCount(3); @@ -80,7 +82,7 @@ public async Task IvyDetector_FileObservableIsNotPresent_DetectionShouldNotFailA this.commandLineMock.Setup(x => x.CanCommandBeLocatedAsync(IvyDetector.PrimaryCommand, IvyDetector.AdditionalValidCommands, IvyDetector.AntVersionArgument)) .ReturnsAsync(true); - Func action = async () => await this.DetectorTestUtility.ExecuteDetectorAsync(); + Func action = async () => await this.detectorTestUtility.ExecuteDetectorAsync(); await action.Should().NotThrowAsync(); } @@ -102,7 +104,7 @@ public async Task IvyDependencyGraphAsync() this.IvyHappyPath(content: registerUsageContent); - var (detectorResult, componentRecorder) = await this.DetectorTestUtility.ExecuteDetectorAsync(); + var (detectorResult, componentRecorder) = await this.detectorTestUtility.ExecuteDetectorAsync(); var detectedComponents = componentRecorder.GetDetectedComponents(); // IsDevelopmentDependency = true in componentRecorder but null in detectedComponents... why? detectedComponents.Should().HaveCount(3); @@ -132,7 +134,7 @@ private void IvyHappyPath(string content) File.WriteAllText(Path.Combine(Path.GetTempPath(), "ivy.xml"), "(dummy content)"); File.WriteAllText(Path.Combine(Path.GetTempPath(), "ivysettings.xml"), "(dummy content)"); - this.DetectorTestUtility + this.detectorTestUtility .WithFile("ivy.xml", "(dummy content)", fileLocation: Path.Combine(Path.GetTempPath(), "ivy.xml")); this.commandLineMock.Setup( diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorTests.cs index 2d575ee04..6081e5e0c 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorTests.cs @@ -15,8 +15,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class NpmDetectorTests : BaseDetectorTest +public class NpmDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly List packageJsonSearchPattern = ["package.json"]; [TestMethod] @@ -27,7 +29,7 @@ public async Task TestNpmDetector_NameAndVersionDetectedAsync() var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForNameAndVersion(componentName, version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -45,7 +47,7 @@ public async Task TestNpmDetector_AuthorNameAndEmailDetected_AuthorInJsonFormatA var authorEmail = GetRandomString(); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailInJsonFormat(authorName, authorEmail); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -63,7 +65,7 @@ public async Task TestNpmDetector_AuthorNameDetectedWhenEmailIsNotPresent_Author var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailInJsonFormat(authorName, null); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -83,7 +85,7 @@ public async Task TestNpmDetector_AuthorNameAndAuthorEmailDetected_WhenAuthorNam var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(authorName, authorEmail, authorUrl); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -102,7 +104,7 @@ public async Task TestNpmDetector_AuthorNameDetected_WhenEmailNotPresentAndUrlIs var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(authorName, null, authorUrl); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -122,7 +124,7 @@ public async Task TestNpmDetector_AuthorNull_WhenAuthorMalformed_AuthorAsSingleS var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesMalformedAuthorAsSingleString(authorName, authorEmail, authorUrl); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -139,7 +141,7 @@ public async Task TestNpmDetector_AuthorNameDetected_WhenEmailNotPresentAndUrlNo var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(authorName); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -158,7 +160,7 @@ public async Task TestNpmDetector_AuthorNameAndAuthorEmailDetected_WhenUrlNotPre var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(authorName, authorEmail); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -178,7 +180,7 @@ public async Task TestNpmDetector_NullAuthor_WhenAuthorNameIsNullOrEmpty_AuthorA var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailInJsonFormat(authorName, authorEmail); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -197,7 +199,7 @@ public async Task TestNpmDetector_NullAuthor_WhenAuthorNameIsNullOrEmpty_AuthorA var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(authorName, authorEmail); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -216,7 +218,7 @@ public async Task TestNpmDetector_NodeEngineDoesNotCauseSkippedPackageAsync() var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForNameAndVersionWithNodeEngine(componentName, version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -232,7 +234,7 @@ public async Task TestNpmDetector_VSCodeEngineCausesSkippedPackageAsync() var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForNameAndVersionWithVSCodeEngine(componentName, version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -249,7 +251,7 @@ public async Task TestNpmDetector_EnginesAsArray_VSCodeEngine() var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForNameAndVersionWithEngiesAsArray(packageName, packageVersion, engineText); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -266,7 +268,7 @@ public async Task TestNpmDetector_EnginesAsArray_NodeEngine() var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonNoDependenciesForNameAndVersionWithEngiesAsArray(packageName, packageVersion, engineText); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorWithRootsTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorWithRootsTests.cs index 14c0bacfd..959d5574a 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorWithRootsTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmDetectorWithRootsTests.cs @@ -19,8 +19,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class NpmDetectorWithRootsTests : BaseDetectorTest +public class NpmDetectorWithRootsTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly string packageLockJsonFileName = "package-lock.json"; private readonly string packageJsonFileName = "package.json"; private readonly List packageJsonSearchPattern = ["package.json"]; @@ -30,7 +32,7 @@ public class NpmDetectorWithRootsTests : BaseDetectorTest(); - this.DetectorTestUtility.AddServiceMock(this.mockPathUtilityService); + this.detectorTestUtility.AddServiceMock(this.mockPathUtilityService); } [TestMethod] @@ -42,7 +44,7 @@ public async Task TestNpmDetector_PackageLockReturnsValidAsync() var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock2(this.packageLockJsonFileName, componentName0, version0); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, version0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -72,7 +74,7 @@ public async Task TestNpmDetector_PackageLockReturnsValidWhenDevAndOptionalDepen var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock2WithOptionalAndDevDependency(this.packageLockJsonFileName, rootName, rootVersion, devDepName, devDepVersion, optDepName, optDepVersion); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRootOneDevDependencyOneOptionalDependency(rootName, rootVersion, devDepName, devDepVersion, optDepName, optDepVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -97,7 +99,7 @@ public async Task TestNpmDetector_MismatchedFilesReturnsEmptyAsync() var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock2(this.packageLockJsonFileName); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, version0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -111,7 +113,7 @@ public async Task TestNpmDetector_MissingPackageJsonReturnsEmptyAsync() { var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock2(this.packageLockJsonFileName); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .ExecuteDetectorAsync(); @@ -142,7 +144,7 @@ public async Task TestNpmDetector_PackageLockMultiRootAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName2, version2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -198,7 +200,7 @@ public async Task TestNpmDetector_VerifyMultiRoot_DependencyGraphAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName2, version2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -262,7 +264,7 @@ public async Task TestNpmDetector_EmptyVersionSkippedAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName2, version2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -315,7 +317,7 @@ public async Task TestNpmDetector_InvalidNameSkippedAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName2, version2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -377,7 +379,7 @@ public async Task TestNpmDetector_LernaDirectoryAsync() this.mockPathUtilityService.Setup(x => x.IsFileBelowAnother(It.IsAny(), It.IsAny())).Returns(true); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("lerna.json", "unused string", this.packageLockJsonSearchPatterns, fileLocation: lernaFileLocation) .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns, fileLocation: lockFileLocation) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern, fileLocation: packageJsonFileLocation) @@ -433,7 +435,7 @@ public async Task TestNpmDetector_CircularRequirementsResolveAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName2, version2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -464,7 +466,7 @@ public async Task TestNpmDetector_ShrinkwrapLockReturnsValidAsync() var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock2(lockFileName, componentName0, version0); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, version0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -509,7 +511,7 @@ public async Task TestNpmDetector_IgnoresPackageLocksInSubFoldersAsync() var packageJsonTemplate2 = string.Format(packagejson, componentName2, version2, "test2"); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility /* Top level */ .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) @@ -588,7 +590,7 @@ public async Task TestNpmDetector_DependencyGraphIsCreatedAsync() var packageJsonTemplate = string.Format(packagejson, componentA.Name, componentA.Version, componentB.Name, componentB.Version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -626,7 +628,7 @@ public async Task TestNpmDetector_PackageLockWithoutDependenciesObject_ShouldHan ""version"": ""1.0.0"" }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -655,7 +657,7 @@ public async Task TestNpmDetector_PackageLockMissingDependenciesButPackageJsonHa } }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -684,7 +686,7 @@ public async Task TestNpmDetector_PackageLockMissingDependenciesProperty_ShouldN // Before the fix, this would throw a NullReferenceException because // packageLockJToken["dependencies"] returns null, and calling .Children() on null throws - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmLockfile3DetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmLockfile3DetectorTests.cs index 45d6c0524..6f2f62921 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/NpmLockfile3DetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/NpmLockfile3DetectorTests.cs @@ -18,8 +18,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class NpmLockfile3DetectorTests : BaseDetectorTest +public class NpmLockfile3DetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly string packageLockJsonFileName = "package-lock.json"; private readonly string packageJsonFileName = "package.json"; private readonly List packageJsonSearchPattern = ["package.json"]; @@ -29,7 +31,7 @@ public class NpmLockfile3DetectorTests : BaseDetectorTest public NpmLockfile3DetectorTests() { this.mockPathUtilityService = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.mockPathUtilityService); + this.detectorTestUtility.AddServiceMock(this.mockPathUtilityService); } [TestMethod] @@ -41,7 +43,7 @@ public async Task TestNpmDetector_PackageLockVersion3ReturnsValidAsync() var (packageLockName, packageLockContents, packageLockPath) = NpmTestUtilities.GetWellFormedPackageLock3(this.packageLockJsonFileName, componentName0, version0); var (packageJsonName, packageJsonContents, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, version0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(packageJsonName, packageJsonContents, this.packageJsonSearchPattern, fileLocation: packageJsonPath) .ExecuteDetectorAsync(); @@ -80,7 +82,7 @@ public async Task TestNpmDetector_PackageLockVersion3NestedReturnsValidAsync() var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName1, version1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -134,7 +136,7 @@ public async Task TestNpmDetector_PackageLockVersion3WithDevDependenciesReturnsV var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName1, version1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -187,7 +189,7 @@ public async Task TestNpmDetector_PackageLockVersion3WithOptionalDependenciesRet var packageJsonTemplate = string.Format(packagejson, componentName0, version0, componentName1, version1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(packageLockName, packageLockContents, this.packageLockJsonSearchPatterns, fileLocation: packageLockPath) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -266,7 +268,7 @@ public async Task TestNpmDetector_NestedNodeModulesV3Async() var packageJsonTemplate = string.Format(packagejson, componentA.Name, componentA.Version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -301,7 +303,7 @@ public async Task TestNpmDetector_PackageLockWithoutPackagesObject_ShouldHandleG ""version"": ""1.0.0"" }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -330,7 +332,7 @@ public async Task TestNpmDetector_PackageLockMissingPackagesButPackageJsonHasDep } }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -359,7 +361,7 @@ public async Task TestNpmDetector_PackageLockMissingPackagesProperty_ShouldNotTh // Before the fix, this would throw a NullReferenceException because // packageLockJToken["packages"] returns null, and calling .Children() on null throws - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockJson, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonContents, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -439,7 +441,7 @@ public async Task TestNpmDetector_SameComponentWithDifferentParents_BothPathsRec componentA.Name, componentA.Version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); @@ -549,7 +551,7 @@ public async Task TestNpmDetector_CircularDependency_HandledGracefullyAsync() componentA.Name, componentA.Version); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.packageLockJsonFileName, packageLockTemplate, this.packageLockJsonSearchPatterns) .WithFile(this.packageJsonFileName, packageJsonTemplate, this.packageJsonSearchPattern) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetComponentDetectorTests.cs index ed6b79fbd..4eea4d4a2 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetComponentDetectorTests.cs @@ -21,23 +21,25 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class NuGetComponentDetectorTests : BaseDetectorTest +public class NuGetComponentDetectorTests { private static readonly IEnumerable DetectorSearchPattern = ["*.nupkg", "*.nuspec", "nuget.config", "paket.lock"]; + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock> mockLogger; public NuGetComponentDetectorTests() { this.mockLogger = new Mock>(); - this.DetectorTestUtility.AddServiceMock(this.mockLogger); + this.detectorTestUtility.AddServiceMock(this.mockLogger); } [TestMethod] public async Task TestNuGetDetectorWithNoFiles_ReturnsSuccessfullyAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility.ExecuteDetectorAsync(); + var (scanResult, componentRecorder) = await this.detectorTestUtility.ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); componentRecorder.GetDetectedComponents().Should().BeEmpty(); @@ -51,7 +53,7 @@ public async Task TestNugetDetector_ReturnsValidNuspecComponentAsync() var testAuthors = new string[] { "author 1", "author 2" }; var nuspec = NugetTestUtilities.GetValidNuspec(testComponentName, testVersion, testAuthors); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("*.nuspec", nuspec) .ExecuteDetectorAsync(); @@ -73,7 +75,7 @@ public async Task TestNugetDetector_ReturnsValidNuspecComponent_SingleAuthorAsyn var testAuthors = new string[] { "author 1" }; var nuspec = NugetTestUtilities.GetValidNuspec(testComponentName, testVersion, testAuthors); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("*.nuspec", nuspec) .ExecuteDetectorAsync(); @@ -92,7 +94,7 @@ public async Task TestNugetDetector_ReturnsValidNupkgComponentAsync() { var nupkg = await NugetTestUtilities.ZipNupkgComponentAsync("test.nupkg", NugetTestUtilities.GetRandomValidNuspec()); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("test.nupkg", nupkg) .ExecuteDetectorAsync(); @@ -106,7 +108,7 @@ public async Task TestNugetDetector_ReturnsValidMixedComponentAsync() var nuspec = NugetTestUtilities.GetRandomValidNuSpecComponent(); var nupkg = await NugetTestUtilities.ZipNupkgComponentAsync("test.nupkg", NugetTestUtilities.GetRandomValidNuspec()); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("test.nuspec", nuspec) .WithFile("test.nupkg", nupkg) .ExecuteDetectorAsync(); @@ -150,7 +152,7 @@ public async Task TestNugetDetector_ReturnsValidPaketComponentAsync() log4net (1.2.10) "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("paket.lock", paketLock) .AddServiceMock(this.mockLogger) .ExecuteDetectorAsync(); @@ -178,7 +180,7 @@ public async Task TestNugetDetector_HandlesMalformedComponentsInComponentListAsy var malformedNupkg = await NugetTestUtilities.ZipNupkgComponentAsync("malformed.nupkg", NugetTestUtilities.GetRandomMalformedNuPkgComponent()); var nuspec = NugetTestUtilities.GetRandomValidNuSpecComponent(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("test.nuspec", nuspec) .WithFile("test.nupkg", validNupkg) .WithFile("malformed.nupkg", malformedNupkg) @@ -277,7 +279,7 @@ public async Task TestNugetDetector_LowConfidencePackagesAsync() { var nupkg = await NugetTestUtilities.ZipNupkgComponentAsync("Newtonsoft.Json.nupkg", NugetTestUtilities.GetValidNuspec("Newtonsoft.Json", "9.0.1", ["JamesNK"])); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Newtonsoft.Json.nupkg", nupkg) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetProjectModelProjectCentricComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetProjectModelProjectCentricComponentDetectorTests.cs index 06c67555b..f7c097ddb 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetProjectModelProjectCentricComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/NuGetProjectModelProjectCentricComponentDetectorTests.cs @@ -18,8 +18,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class NuGetProjectModelProjectCentricComponentDetectorTests : BaseDetectorTest +public class NuGetProjectModelProjectCentricComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly string projectAssetsJsonFileName = "project.assets.json"; private readonly Mock fileUtilityServiceMock; @@ -28,14 +30,14 @@ public NuGetProjectModelProjectCentricComponentDetectorTests() this.fileUtilityServiceMock = new Mock(); this.fileUtilityServiceMock.Setup(x => x.Exists(It.IsAny())) .Returns(true); - this.DetectorTestUtility.AddServiceMock(this.fileUtilityServiceMock); + this.detectorTestUtility.AddServiceMock(this.fileUtilityServiceMock); } [TestMethod] public async Task ScanDirectoryAsync_Base_2_2_VerificationAsync() { var osAgnostic = this.Convert22SampleToOSAgnostic(TestResources.project_assets_2_2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -60,7 +62,7 @@ public async Task ScanDirectoryAsync_Base_2_2_VerificationAsync() public async Task ScanDirectoryAsync_Base_2_2_additional_VerificationAsync() { var osAgnostic = this.Convert22SampleToOSAgnostic(TestResources.project_assets_2_2_additional); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -87,7 +89,7 @@ public async Task ScanDirectoryAsync_Base_2_2_additional_VerificationAsync() public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_2_2_VerificationAsync() { var osAgnostic = this.Convert22SampleToOSAgnostic(TestResources.project_assets_2_2); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -101,7 +103,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_2_2_Verification public async Task ScanDirectoryAsync_DependencyGraph_2_2_additional_VerificationAsync() { var osAgnostic = this.Convert22SampleToOSAgnostic(TestResources.project_assets_2_2_additional); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); var graphsByLocation = componentRecorder.GetDependencyGraphsByLocation(); @@ -183,7 +185,7 @@ public async Task ScanDirectoryAsync_DependencyGraph_2_2_additional_Verification public async Task ScanDirectoryAsync_Base_3_1_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_3_1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -213,7 +215,7 @@ public async Task ScanDirectoryAsync_Base_3_1_VerificationAsync() public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_3_1_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_3_1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -226,7 +228,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_3_1_Verification public async Task ScanDirectoryAsync_DependencyGraph_3_1_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_3_1); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -279,7 +281,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_1x_2x_Verificati foreach (var testResource in testResources) { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, testResource) .ExecuteDetectorAsync(); @@ -292,7 +294,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_1x_2x_Verificati [TestMethod] public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_1_1_web_VerificationAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, TestResources.project_assets_1_1_web) .ExecuteDetectorAsync(); @@ -307,7 +309,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_1_1_web_Verifica public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_8_0_web_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_8_0_web); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -319,7 +321,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_8_0_web_Verifica public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_42_15_web_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_42_15_web); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -332,7 +334,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_42_15_web_Verifi public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_8_0_multi_framework_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_8_0_multi_framework); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -346,7 +348,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_8_0_multi_framew public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_6_0_8_0_multi_framework_VerificationAsync() { var osAgnostic = this.Convert31SampleToOSAgnostic(TestResources.project_assets_6_0_8_0_multi_framework); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); @@ -359,7 +361,7 @@ public async Task ScanDirectoryAsync_ExcludedFrameworkComponent_6_0_8_0_multi_fr [TestMethod] public async Task ScanDirectoryAsync_PackageDownload_VerificationAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, TestResources.project_assets_packageDownload) .ExecuteDetectorAsync(); @@ -381,7 +383,7 @@ public async Task ScanDirectory_NoPackageSpecAsync() }, ""packageFolders"": {} }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(this.projectAssetsJsonFileName, osAgnostic) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/PnpmDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/PnpmDetectorTests.cs index f754d027b..de0f977e2 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/PnpmDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/PnpmDetectorTests.cs @@ -19,12 +19,14 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class PnpmDetectorTests : BaseDetectorTest +public class PnpmDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + public PnpmDetectorTests() { var componentRecorder = new ComponentRecorder(enableManualTrackingOfExplicitReferences: false); - this.DetectorTestUtility.WithScanRequest( + this.detectorTestUtility.WithScanRequest( new ScanRequest( new DirectoryInfo(Path.GetTempPath()), null, @@ -32,7 +34,7 @@ public PnpmDetectorTests() new Dictionary(), null, componentRecorder)); - this.DetectorTestUtility.AddServiceMock(new Mock>()); + this.detectorTestUtility.AddServiceMock(new Mock>()); } [TestMethod] @@ -77,7 +79,7 @@ public async Task TestPnpmDetector_SingleFileLocatesExpectedInputAsync() shrinkwrapMinorVersion: 7 shrinkwrapVersion: 3"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -175,7 +177,7 @@ public async Task TestPnpmDetector_SameComponentMergesRootsAndLocationsAcrossMul shrinkwrapMinorVersion: 7 shrinkwrapVersion: 3"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile1) .WithFile("shrinkwrap2.yaml", yamlFile2) .ExecuteDetectorAsync(); @@ -221,7 +223,7 @@ public async Task TestPnpmDetector_SpecialDependencyVersionStringDoesntBlowUsUpA shrinkwrapMinorVersion: 7 shrinkwrapVersion: 3"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile1) .ExecuteDetectorAsync(); @@ -250,7 +252,7 @@ public async Task TestPnpmDetector_DetectorRecognizeDevDependenciesValuesAsync() /strict-uri-encode/1.1.0: dev: true"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile1) .ExecuteDetectorAsync(); @@ -281,7 +283,7 @@ public async Task TestPnpmDetector_DetectorRecognizeDevDependenciesValues_InWeir shared-non-dev-dep: 0.1.2 dev: true"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile1) .ExecuteDetectorAsync(); @@ -296,7 +298,7 @@ public async Task TestPnpmDetector_HandlesMalformedYamlAsync() // This is a clearly malformed Yaml. We expect parsing it to "succeed" but find no components var yamlFile1 = @"dependencies"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile1) .ExecuteDetectorAsync(); @@ -326,7 +328,7 @@ public async Task TestPnpmDetector_DependencyGraphIsCreatedAsync() /test/1.0.0: dev: true"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -376,7 +378,7 @@ public async Task TestPnpmDetector_DependenciesRefeToLocalPaths_DependenciesAreI /nth-check/2.0.0: resolution: {integrity: sha1-G7T22scAcvwxPoyc0UF7UHTAoSU=} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("shrinkwrap1.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -416,7 +418,7 @@ public async Task TestPnpmDetector_BadLockVersion_EmptyAsync() dev: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -440,7 +442,7 @@ public async Task TestPnpmDetector_V5_GoodLockVersion_ParsedDependenciesAsync() /strict-uri-encode/1.1.0: dev: true"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -472,7 +474,7 @@ public async Task TestPnpmDetector_V6_SuccessAsync() dev: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -514,7 +516,7 @@ public async Task TestPnpmDetector_V6_WorkspaceAsync() dev: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -555,7 +557,7 @@ public async Task TestPnpmDetector_V6_RenamedAsync() dev: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -596,7 +598,7 @@ public async Task TestPnpmDetector_V6_BadLockVersion_EmptyAsync() dev: false "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -642,7 +644,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_ParsesDependencies() sampleIndirectDependency@3.3.3: {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -694,7 +696,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_ParsesAliasedDependency() sampleIndirectDependency@3.3.3: {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -756,7 +758,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_SkipsFileAndLinkDependenci 'file://../sampleFile@link:../': {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -838,7 +840,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_FileAndLinkDependenciesAre sampleIndirectDevDependency@5.5.5: {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -922,7 +924,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_HttpDependenciesAreNotRegi sampleHttpDependency@https://samplePackage/tar.gz/32f550d3b3bdb1b781aabe100683311cd982c98e': {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -993,7 +995,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_HttpsDependenciesAreNotReg sample@https://samplePackage/tar.gz/32f550d3b3bdb1b781aabe100683311cd982c98e': {} "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); @@ -1037,7 +1039,7 @@ public async Task TestPnpmDetector_V9_GoodLockVersion_MissingSnapshotsSuccess() version: link:SampleLinkDependency "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("pnpm-lock.yaml", yamlFile) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs index f23dfdd14..cad34e57e 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/PodDetectorTest.cs @@ -17,8 +17,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class PodDetectorTest : BaseDetectorTest +public class PodDetectorTest { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task TestPodDetector_EmptyPodfileLockAsync() { @@ -26,7 +28,7 @@ public async Task TestPodDetector_EmptyPodfileLockAsync() COCOAPODS: 1.4.0.beta.1"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -62,7 +64,7 @@ public async Task TestPodDetector_DetectorRecognizePodComponentsAsync() COCOAPODS: 0.39.0"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -104,7 +106,7 @@ public async Task TestPodDetector_DetectorRecognizeSubspecsAsSinglePodComponentA COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -148,7 +150,7 @@ public async Task TestPodDetector_DetectorRecognizeGitComponentsAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -191,7 +193,7 @@ public async Task TestPodDetector_DetectorRecognizeGitComponentsWithTagsAsPodCom COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -234,7 +236,7 @@ public async Task TestPodDetector_DetectorRecognizeGitComponentsWithTagsAsPodCom COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -271,7 +273,7 @@ public async Task TestPodDetector_DetectorRecognizePodComponentsFromExternalPods COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -304,7 +306,7 @@ public async Task TestPodDetector_DetectorRecognizePodComponentsFromLocalPathAsy COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .ExecuteDetectorAsync(); @@ -369,7 +371,7 @@ public async Task TestPodDetector_MultiplePodfileLocksAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .WithFile("Podfile.lock", podfileLockContent2) .ExecuteDetectorAsync(); @@ -453,7 +455,7 @@ public async Task TestPodDetector_DetectorSupportsDependencyRootsAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .WithFile("Podfile.lock", podfileLockContent2) .ExecuteDetectorAsync(); @@ -550,7 +552,7 @@ public async Task TestPodDetector_DetectorSupportsDependencyRoots_GitUriAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .WithFile("Podfile.lock", podfileLockContent2) .ExecuteDetectorAsync(); @@ -631,7 +633,7 @@ public async Task TestPodDetector_DetectorHandlesMainSpecRepoDifferencesAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .WithFile("Podfile.lock", podfileLockContent2) .WithFile("Podfile.lock", podfileLockContent3) @@ -678,7 +680,7 @@ public async Task TestPodDetector_DetectorRecognizeComponentsSpecRepoAsync() COCOAPODS: 1.8.4"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Podfile.lock", podfileLockContent) .WithFile("Podfile.lock", podfileLockContent2, fileLocation: Path.Join(Path.GetTempPath(), "sub-folder", "Podfile.lock")) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/PoetryComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/PoetryComponentDetectorTests.cs index 8a75a3acf..7c1ffb5dc 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/PoetryComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/PoetryComponentDetectorTests.cs @@ -15,8 +15,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class PoetryComponentDetectorTests : BaseDetectorTest +public class PoetryComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task TestPoetryDetector_TestCustomSourceAsync() { @@ -33,7 +35,7 @@ public async Task TestPoetryDetector_TestCustomSourceAsync() reference = ""custom"" "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("poetry.lock", poetryLockContent) .ExecuteDetectorAsync(); @@ -81,7 +83,7 @@ public async Task TestPoetryDetector_TestGitDependencyAsync() reference = ""master"" resolved_reference = ""232a5596424c98d11c3cf2e29b2f6a6c591c2ff3"""; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("poetry.lock", poetryLockContent) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/RubyDetectorTest.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/RubyDetectorTest.cs index e5c9918b6..44cb9543c 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/RubyDetectorTest.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/RubyDetectorTest.cs @@ -17,12 +17,14 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class RubyDetectorTest : BaseDetectorTest +public class RubyDetectorTest { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + public RubyDetectorTest() { var componentRecorder = new ComponentRecorder(enableManualTrackingOfExplicitReferences: false); - this.DetectorTestUtility.WithScanRequest( + this.detectorTestUtility.WithScanRequest( new ScanRequest( new DirectoryInfo(Path.GetTempPath()), null, @@ -66,7 +68,7 @@ BUNDLED WITH BUNDLED WITH 1.17.3"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .WithFile("2Gemfile.lock", gemFileLockContent2) .ExecuteDetectorAsync(); @@ -96,7 +98,7 @@ public async Task TestRubyDetector_TestGemsWithUppercase_LockFileAsync() BUNDLED WITH 2.2.28"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -129,7 +131,7 @@ public async Task TestRubyDetector_DetectorParseWithBundlerVersionAsync() BUNDLED WITH 1.17.3"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -163,7 +165,7 @@ public async Task TestRubyDetector_DetectorRecognizeGemComponentsAsync() nokogiri (~> 1.8.2) websocket-driver (0.6.1)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -193,7 +195,7 @@ public async Task TestRubyDetector_ParentWithTildeInVersion_IsExcludedAsync() mini_portile2 (~> 2.3.0) mini_portile2 (2.3.0)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -230,7 +232,7 @@ public async Task TestRubyDetector_DetectorCreatesADependencyGraphAsync() nio4r (5.2.1) websocket-driver (0.6.1)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -282,7 +284,7 @@ public async Task TestRubyDetector_ComponentsRootsAreFilledCorrectlyAsync() nio4r (5.2.1) websocket-driver (0.6.1)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -337,7 +339,7 @@ public async Task TestRubyDetector_DetectorRecognizeGitComponentsAsync() specs: mini_mime (2.0.0)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -366,7 +368,7 @@ public async Task TestRubyDetector_DetectorRecognizeParentChildRelationshipInGit specs: mail (2.7.2.edge)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); @@ -391,7 +393,7 @@ public async Task TestRubyDetector_DetectorRecognizeLocalDependenciesAsync() specs: test2 (1.0.0)"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("1Gemfile.lock", gemFileLockContent) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/RustSbomDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/RustSbomDetectorTests.cs index fbcebadb4..6c02aa17d 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/RustSbomDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/RustSbomDetectorTests.cs @@ -21,8 +21,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class RustSbomDetectorTests : BaseDetectorTest +public class RustSbomDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock mockMetadataContextBuilder; private readonly Mock mockCliParser; private readonly Mock mockCargoLockParser; @@ -238,20 +240,20 @@ public void Initialize() this.pathUtilityService = new PathUtilityService(new Mock>().Object); - this.DetectorTestUtility.AddService(this.pathUtilityService); - this.DetectorTestUtility.AddService(this.mockMetadataContextBuilder.Object); - this.DetectorTestUtility.AddService(this.mockCliParser.Object); - this.DetectorTestUtility.AddService(this.mockCargoLockParser.Object); - this.DetectorTestUtility.AddService(this.mockSbomParser.Object); + this.detectorTestUtility.AddService(this.pathUtilityService); + this.detectorTestUtility.AddService(this.mockMetadataContextBuilder.Object); + this.detectorTestUtility.AddService(this.mockCliParser.Object); + this.detectorTestUtility.AddService(this.mockCargoLockParser.Object); + this.detectorTestUtility.AddService(this.mockSbomParser.Object); } [TestMethod] public async Task TestGraphIsCorrectAsync() { // Use real parser for this test - this.DetectorTestUtility.AddService(new RustSbomParser(new Mock>().Object)); + this.detectorTestUtility.AddService(new RustSbomParser(new Mock>().Object)); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("main.exe.cargo-sbom.json", this.testSbom) .ExecuteDetectorAsync(); @@ -282,9 +284,9 @@ public async Task TestGraphIsCorrectAsync() public async Task TestGraphIsCorrectWithGitDeps() { // Use real parser for this test - this.DetectorTestUtility.AddService(new RustSbomParser(new Mock>().Object)); + this.detectorTestUtility.AddService(new RustSbomParser(new Mock>().Object)); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("main.exe.cargo-sbom.json", this.testSbomWithGitDeps) .ExecuteDetectorAsync(); @@ -356,7 +358,7 @@ public async Task TestSbomOnlyMode_WithOwnershipMap_VerifiesOwnershipUsed() }) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("test.cargo-sbom.json", sbomContent) .WithFile("Cargo.toml", "[package]\nname = \"test\"\nversion = \"1.0.0\"") .ExecuteDetectorAsync(); @@ -408,7 +410,7 @@ public async Task TestMultipleSbomFiles_ProcessedInAlphabeticalOrder_VerifiesOrd }) .ReturnsAsync(1); - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("z.cargo-sbom.json", sbomContent, fileLocation: sbom2) .WithFile("a.cargo-sbom.json", sbomContent, fileLocation: sbom1) .ExecuteDetectorAsync(); @@ -466,7 +468,7 @@ public async Task TestWorkspaceGlobRules_MemberDirectoriesSkipped() (stream, recorder, token) => lockCallCount++) .ReturnsAsync(2); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", cargoLockContent, fileLocation: rootLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: rootToml) @@ -524,7 +526,7 @@ public async Task TestFallbackMode_CargoTomlWithoutMetadataCache_LogsWarning() // Create a new mock logger to capture warnings var mockLoggerForDetector = new Mock>(); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .AddServiceMock(mockLoggerForDetector) .WithFile("Cargo.toml", cargoTomlContent, fileLocation: tomlPath) .ExecuteDetectorAsync(); @@ -615,7 +617,7 @@ public async Task TestFileProcessingOrder_TomlBeforeLock_AndLockSkipped() }) .ReturnsAsync(new IRustCliParser.ParseResult { Success = true }); - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("Cargo.toml", "[package]\nname = \"root\"", fileLocation: rootToml) .WithFile("Cargo.lock", "[[package]]\nname = \"root\"", fileLocation: rootLock) .ExecuteDetectorAsync(); @@ -689,7 +691,7 @@ public async Task TestSkipLogic_SecondFileInSameDirectorySkipped() It.IsAny())) .ReturnsAsync(new IRustCliParser.ParseResult { Success = true }); - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("Cargo.toml", "[package]\nname = \"test\"", fileLocation: toml1) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: lock1) .ExecuteDetectorAsync(); @@ -751,7 +753,7 @@ public async Task TestWorkspaceOnlyToml_NotSkippedEvenWhenDirectoryVisited() "; // Process files in order: lock first (marks directory as visited), then workspace TOML - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: workspaceLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: workspaceToml) .ExecuteDetectorAsync(); @@ -811,7 +813,7 @@ public async Task TestFailedManifests_LoggedAndOthersContinue() It.IsAny())) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("Cargo.toml", "[package]\nname = \"working\"", fileLocation: workingToml) .WithFile("Cargo.toml", "[package]\nname = \"failed\"", fileLocation: failedToml) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: workingLock) @@ -858,7 +860,7 @@ public async Task TestMetadataContextBuilder_FailsGracefully() It.IsAny())) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("Cargo.toml", "[package]\nname = \"test\"") .WithFile("Cargo.lock", "[[package]]\nname = \"test\"") .ExecuteDetectorAsync(); @@ -892,7 +894,7 @@ public async Task TestSbomOnlyMode_ProcessesSbomFilesOnly() It.IsAny())) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("test.cargo-sbom.json", sbomContent) .WithFile("Cargo.toml", "[package]\nname = \"test\"") .WithFile("Cargo.lock", "[[package]]\nname = \"test\"") @@ -929,7 +931,7 @@ public async Task TestCargoLockMode_RecordsLockfileVersion() It.IsAny())) .ReturnsAsync(2); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("Cargo.lock", "[[package]]\nname = \"test\"") .ExecuteDetectorAsync(); @@ -956,7 +958,7 @@ public async Task TestMixedSbomAndLockFiles_SbomTakesPrecedence() It.IsAny())) .ReturnsAsync(1); - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("test.cargo-sbom.json", sbomContent) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"") .WithFile("Cargo.toml", "[package]\nname = \"test\"") @@ -1029,7 +1031,7 @@ public async Task TestShouldSkip_WorkspaceOnlyToml_WithPackageSection_NotSkipped It.IsAny())) .ReturnsAsync(new IRustCliParser.ParseResult { Success = true }); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.toml", tomlContent, fileLocation: workspaceToml) .ExecuteDetectorAsync(); @@ -1063,7 +1065,7 @@ public async Task TestProcessCargoLockAsync_NoCargoToml_DirectoryStillMarkedVisi It.IsAny())) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: lockFile) .ExecuteDetectorAsync(); @@ -1105,7 +1107,7 @@ public async Task TestProcessWorkspaceTables_DefaultMembers_CreatesGlobRule() (stream, recorder, token) => lockCallCount++) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: rootLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: rootToml) @@ -1143,7 +1145,7 @@ public async Task TestProcessWorkspaceTables_InvalidToml_LogsWarningAndContinues It.IsAny())) .ReturnsAsync(2); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: rootLock) .WithFile("Cargo.toml", invalidTomlContent, fileLocation: rootToml) @@ -1207,7 +1209,7 @@ public async Task TestIsWorkspaceOnlyToml_ExceptionThrown_ReturnsFalse() It.IsAny())) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.toml", "[workspace]\nmembers = []", fileLocation: workspaceToml) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: workspaceLock) @@ -1230,7 +1232,7 @@ public async Task TestGetDirectoryDepth_NullOrEmptyPath_ReturnsZero() It.IsAny())) .ReturnsAsync(1); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("test.cargo-sbom.json", sbomContent) .ExecuteDetectorAsync(); @@ -1280,7 +1282,7 @@ public async Task TestCliParser_FailedParsing_DirectoryNotMarkedVisited() It.IsAny())) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .WithFile("Cargo.toml", "[package]\nname = \"test\"", fileLocation: tomlFile) .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: lockFile) .ExecuteDetectorAsync(); @@ -1306,7 +1308,7 @@ public async Task TestCargoLockParser_ReturnsNull_NoTelemetryRecorded() It.IsAny())) .ReturnsAsync((int?)null); - var (result, componentRecorder) = await this.DetectorTestUtility + var (result, componentRecorder) = await this.detectorTestUtility .WithFile("Cargo.lock", "[[package]]\nname = \"test\"", fileLocation: lockFile) .ExecuteDetectorAsync(); @@ -1348,7 +1350,7 @@ public async Task TestGlobRuleMatching_IncludeAndExclude_CorrectlyFilters() (stream, recorder, token) => processedFiles.Add(stream.Location)) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"root\"", fileLocation: rootLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: rootToml) @@ -1401,7 +1403,7 @@ public async Task TestGlobRuleMatching_IncludeAllSubdirectories_SkipsAllMembers( (stream, recorder, token) => processedFiles.Add(stream.Location)) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"root\"", fileLocation: rootLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: rootToml) @@ -1448,7 +1450,7 @@ public async Task TestGlobRuleMatching_MixedExplicitAndGlob_CorrectlyIncludesAnd (stream, recorder, token) => processedFiles.Add(stream.Location)) .ReturnsAsync(2); - await this.DetectorTestUtility + await this.detectorTestUtility .AddService(mockFileUtilityService.Object) .WithFile("Cargo.lock", "[[package]]\nname = \"root\"", fileLocation: rootLock) .WithFile("Cargo.toml", workspaceTomlContent, fileLocation: rootToml) diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/SPDX22ComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/SPDX22ComponentDetectorTests.cs index eb6411ee5..6571f0b0c 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/SPDX22ComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/SPDX22ComponentDetectorTests.cs @@ -19,12 +19,14 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class Spdx22ComponentDetectorTests : BaseDetectorTest +public class Spdx22ComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + public Spdx22ComponentDetectorTests() { var componentRecorder = new ComponentRecorder(enableManualTrackingOfExplicitReferences: false); - this.DetectorTestUtility.WithScanRequest( + this.detectorTestUtility.WithScanRequest( new ScanRequest( new DirectoryInfo(Path.GetTempPath()), null, @@ -102,7 +104,7 @@ public async Task TestSbomDetector_SimpleSbomAsync() }"; var spdxFileName = "manifest.spdx.json"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(spdxFileName, spdxFile) .ExecuteDetectorAsync(); @@ -132,7 +134,7 @@ public async Task TestSbomDetector_BlankJsonAsync() { var spdxFile = "{}"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("manifest.spdx.json", spdxFile) .ExecuteDetectorAsync(); @@ -148,7 +150,7 @@ public async Task TestSbomDetector_InvalidFileAsync() { var spdxFile = "invalidspdxfile"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("manifest.spdx.json", spdxFile) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/SwiftResolvedDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/SwiftResolvedDetectorTests.cs index 0b654e440..e70aaea30 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/SwiftResolvedDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/SwiftResolvedDetectorTests.cs @@ -12,8 +12,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests.Swift; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] -public class SwiftResolvedDetectorTests : BaseDetectorTest +public class SwiftResolvedDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task Test_GivenDetectorWithValidFile_WhenScan_ThenScanIsSuccessfulAndComponentsAreRegistered() { @@ -33,7 +35,7 @@ public async Task Test_GivenDetectorWithValidFile_WhenScan_ThenScanIsSuccessfulA "version" : 2 } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", validResolvedPackageFile) .ExecuteDetectorAsync(); @@ -67,7 +69,7 @@ public async Task Test_GivenDetectorWithValidFileWithMultiplePackages_WhenScan_T { var validLongResolvedPackageFile = this.validLongResolvedPackageFile; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", validLongResolvedPackageFile) .ExecuteDetectorAsync(); @@ -131,7 +133,7 @@ public async Task Test_GivenDetectorWithValidFileWithDuplicatePackages_WhenScan_ } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", duplicatePackages) .ExecuteDetectorAsync(); @@ -168,7 +170,7 @@ public async Task Test_GivenInvalidJSONFile_WhenScan_ThenNoComponentRegisteredAn INVALID JSON } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", invalidJSONResolvedPackageFile) .ExecuteDetectorAsync(); @@ -181,7 +183,7 @@ INVALID JSON public async Task Test_GivenEmptyFile_WhenScan_ThenNoComponentRegisteredAndScanIsSuccessful() { var emptyResolvedPackageFile = string.Empty; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", emptyResolvedPackageFile) .ExecuteDetectorAsync(); @@ -201,7 +203,7 @@ public async Task Test_GivenResvoledPackageWithoutPins_WhenScan_ThenScanIsSucces } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutPins) .ExecuteDetectorAsync(); @@ -238,7 +240,7 @@ public async Task Test_GivenResolvedPackageWithoutIdentity_WhenScan_ThenScanIsSu } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", validResolvedPackageFile) .ExecuteDetectorAsync(); @@ -266,7 +268,7 @@ public async Task Test_GivenResolvedPackageWithoutKind_WhenScan_ThenScanIsSucces } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutKind) .ExecuteDetectorAsync(); @@ -294,7 +296,7 @@ public async Task Test_GivenResolvedPackageWithoutLocation_WhenScan_ThenScanIsSu } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutLocation) .ExecuteDetectorAsync(); @@ -319,7 +321,7 @@ public async Task Test_GivenResolvedPackageWithoutState_WhenScan_ThenScanIsSucce } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutState) .ExecuteDetectorAsync(); @@ -345,7 +347,7 @@ public async Task Test_GivenResolvedPackageWithEmptyState_WhenScan_ThenScanIsSuc } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithEmptyState) .ExecuteDetectorAsync(); @@ -373,7 +375,7 @@ public async Task Test_GivenResolvedPackageWithoutRevision_WhenScan_ThenScanIsSu } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutRevision) .ExecuteDetectorAsync(); @@ -401,7 +403,7 @@ public async Task Test_GivenResolvedPackageWithoutVersion_WhenScan_ThenScanIsSuc } """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility.WithFile( + var (scanResult, componentRecorder) = await this.detectorTestUtility.WithFile( "Package.resolved", resolvedPackageWithoutVersion) .ExecuteDetectorAsync(); @@ -473,7 +475,7 @@ public async Task Test_GivenResolvedPackageWithoutVersion_WhenScan_ThenScanIsSuc [TestMethod] public async Task TestEmptyPackageResolvedAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Package.resolved", string.Empty) .ExecuteDetectorAsync(); @@ -486,7 +488,7 @@ public async Task TestInvalidJsonPackageResolvedAsync() { var invalidJson = "{ invalid json content }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("Package.resolved", invalidJson) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs index 0cb0879a1..ee74049e9 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs @@ -16,12 +16,14 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class UvLockDetectorTests : BaseDetectorTest +public class UvLockDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task TestUvLockDetectorWithNoFiles_ReturnsSuccessfullyAsync() { - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); @@ -32,7 +34,7 @@ public async Task TestUvLockDetectorWithNoFiles_ReturnsSuccessfullyAsync() public async Task TestUvLockDetectorWithEmptyLockFile_FindsNothingAsync() { var emptyUvLock = string.Empty; // Empty TOML - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", emptyUvLock) .ExecuteDetectorAsync(); @@ -44,7 +46,7 @@ public async Task TestUvLockDetectorWithEmptyLockFile_FindsNothingAsync() public async Task TestUvLockDetectorWithNoPackages_FindsNothingAsync() { var uvLock = "# uv.lock file\n[metadata]\nversion = '1'\n"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); @@ -63,7 +65,7 @@ public async Task TestUvLockDetectorWithMultiplePackages_FindsAllComponentsAndGr name = 'bar' version = '4.5.6' "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); @@ -97,7 +99,7 @@ public async Task TestUvLockDetectorWithDependencies_RegistersDependenciesAsync( name = 'bar' version = '4.5.6' "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); @@ -121,7 +123,7 @@ public async Task TestUvLockDetectorWithDependencies_RegistersDependenciesAsync( public async Task TestUvLockDetectorWithMissingDependency_LogsWarningAsync() { var loggerMock = new Mock>(); - this.DetectorTestUtility.AddServiceMock(loggerMock); + this.detectorTestUtility.AddServiceMock(loggerMock); var uvLock = @" [[package]] @@ -132,7 +134,7 @@ public async Task TestUvLockDetectorWithMissingDependency_LogsWarningAsync() name = 'bar' version = '4.5.6' "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .AddServiceMock(loggerMock) .ExecuteDetectorAsync(); @@ -159,7 +161,7 @@ public async Task TestUvLockDetectorWithMalformedPackage_IgnoresInvalidAsync() [[package]] version = '4.5.6' "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); @@ -172,10 +174,10 @@ public async Task TestUvLockDetectorWithMalformedPackage_IgnoresInvalidAsync() public async Task TestUvLockDetectorWithInvalidFile_LogsErrorAsync() { var loggerMock = new Mock>(); - this.DetectorTestUtility.AddServiceMock(loggerMock); + this.detectorTestUtility.AddServiceMock(loggerMock); var invalidUvLock = "not a valid toml file"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", invalidUvLock) .AddServiceMock(loggerMock) .ExecuteDetectorAsync(); @@ -211,7 +213,7 @@ public async Task TestUvLockDetector_ExplicitDependencies_AreMarkedExplicit() name = 'bar' version = '2.0.0' """; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); @@ -250,7 +252,7 @@ public async Task TestUvLockDetector_DevelopmentAndNonDevelopmentDependencies() name = 'devonly' version = '4.0.0' "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("uv.lock", uvLock) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs index f6bdd9469..da64513bd 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs @@ -18,21 +18,23 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class VcpkgComponentDetectorTests : BaseDetectorTest +public class VcpkgComponentDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly Mock mockCommandLineInvocationService; private readonly Mock mockEnvironmentVariableService; public VcpkgComponentDetectorTests() { this.mockCommandLineInvocationService = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.mockCommandLineInvocationService); + this.detectorTestUtility.AddServiceMock(this.mockCommandLineInvocationService); this.mockEnvironmentVariableService = new Mock(); - this.DetectorTestUtility.AddServiceMock(this.mockEnvironmentVariableService); + this.detectorTestUtility.AddServiceMock(this.mockEnvironmentVariableService); var componentRecorder = new ComponentRecorder(enableManualTrackingOfExplicitReferences: false); - this.DetectorTestUtility.WithScanRequest( + this.detectorTestUtility.WithScanRequest( new ScanRequest( new DirectoryInfo(Path.GetTempPath()), null, @@ -65,7 +67,7 @@ public async Task TestNlohmannAsync() } ] }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("vcpkg.spdx.json", spdxFile) .ExecuteDetectorAsync(); @@ -122,7 +124,7 @@ public async Task TestTinyxmlAndResourceAsync() } ] }"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("vcpkg.spdx.json", spdxFile) .ExecuteDetectorAsync(); @@ -153,7 +155,7 @@ public async Task TestBlankJsonAsync() { var spdxFile = "{}"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("vcpkg.spdx.json", spdxFile) .ExecuteDetectorAsync(); @@ -169,7 +171,7 @@ public async Task TestInvalidFileAsync() { var spdxFile = "invalidspdxfile"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("vcpkg.spdx.json", spdxFile) .ExecuteDetectorAsync(); @@ -205,7 +207,7 @@ public async Task TestEmptyManifestInfoAsync() }"; // Empty manifest-info.json should not cause an exception - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(CrossPlatformPath(Path.GetFullPath("vcpkg_installed\\packageLocation\\vcpkg.spdx.json")), spdxFile) .WithFile(CrossPlatformPath(Path.GetFullPath("vcpkg_installed\\vcpkg\\manifest-info.json")), string.Empty) .ExecuteDetectorAsync(); @@ -241,7 +243,7 @@ public async Task TestInvalidManifestInfoAsync() }"; // Invalid JSON in manifest-info.json should not cause an exception - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(CrossPlatformPath(Path.GetFullPath("vcpkg_installed\\packageLocation\\vcpkg.spdx.json")), spdxFile) .WithFile(CrossPlatformPath(Path.GetFullPath("vcpkg_installed\\vcpkg\\manifest-info.json")), "invalid json content") .ExecuteDetectorAsync(); @@ -285,7 +287,7 @@ public async Task TestVcpkgManifestFileAsync(string manifestPath, string pathToV ""manifest-path"": ""{t_pathToVcpkg.Replace("\\", "\\\\")}"" }}"; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile(CrossPlatformPath(Path.GetFullPath("vcpkg_installed\\packageLocation\\vcpkg.spdx.json")), spdxFile) .WithFile(t_manifestPath, manifestFile) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs index 76438c08f..1c7804940 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs @@ -24,8 +24,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; [TestClass] [TestCategory("Governance/All")] [TestCategory("Governance/ComponentDetection")] -public class YarnLockDetectorTests : BaseDetectorTest +public class YarnLockDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + private readonly IYarnLockParser yarnLockParser; private readonly IYarnLockFileFactory yarnLockFileFactory; @@ -42,7 +44,7 @@ public YarnLockDetectorTests() yarnLockFileFactoryMock.Setup(x => x.ParseYarnLockFileAsync(It.IsAny(), It.IsAny(), It.IsAny())) .Returns((ISingleFileComponentRecorder recorder, Stream stream, ILogger logger) => this.yarnLockFileFactory.ParseYarnLockFileAsync(recorder, stream, logger)); - this.DetectorTestUtility.AddServiceMock(yarnLockFileFactoryMock); + this.detectorTestUtility.AddServiceMock(yarnLockFileFactoryMock); } [TestMethod] @@ -51,7 +53,7 @@ public async Task WellFormedYarnLockV1WithZeroComponents_FindsNothingAsync() var yarnLock = YarnTestUtilities.GetWellFormedEmptyYarnV1LockFile(); var packageJson = NpmTestUtilities.GetPackageJsonNoDependencies(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJson, ["package.json"]) .ExecuteDetectorAsync(); @@ -66,7 +68,7 @@ public async Task WellFormedYarnLockV2WithZeroComponents_FindsNothingAsync() var yarnLock = YarnTestUtilities.GetWellFormedEmptyYarnV2LockFile(); var packageJson = NpmTestUtilities.GetPackageJsonNoDependencies(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJson, ["package.json"]) .ExecuteDetectorAsync(); @@ -95,7 +97,7 @@ public async Task MalformedYarnLockV1WithOneComponent_FindsNoComponentAsync() var yarnLock = builder.ToString(); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, providedVersion0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -122,7 +124,7 @@ public async Task MalformedYarnLockV2WithOneComponent_FindsNoComponentAsync() var yarnLock = builder.ToString(); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentName0, providedVersion0); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -146,7 +148,7 @@ public async Task WellFormedYarnLockV1WithOneComponent_FindsComponentAsync() var yarnLock = this.CreateYarnLockV1FileContent([componentA]); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -178,7 +180,7 @@ public async Task WellFormedYarnLockV2WithOneComponent_FindsComponentAsync() var yarnLock = this.CreateYarnLockV2FileContent([componentA]); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -223,7 +225,7 @@ public async Task WellFormedYarnLockV1WithWorkspace_FindsComponentAsync() var packageStream = NpmTestUtilities.GetPackageJsonOneRootComponentStream(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", componentStream.Stream) .WithFile("package.json", packageStream.Stream, ["package.json"]) .WithFile("package.json", workspaceJsonComponentStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "workspace", "package.json")) @@ -269,7 +271,7 @@ public async Task WellFormedYarnLockV1WithWorkspace_CheckFilePathsAsync() var packageStream = NpmTestUtilities.GetPackageJsonOneRootComponentStream(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", componentStream.Stream) .WithFile("package.json", workspaceJsonComponentStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "package.json")) .WithFile("package.json", packageStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "workspace", "package.json")) @@ -315,7 +317,7 @@ public async Task WellFormedYarnLockV2WithWorkspace_FindsComponentAsync() var packageStream = NpmTestUtilities.GetPackageJsonOneRootComponentStream(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", componentStream.Stream) .WithFile("package.json", packageStream.Stream, ["package.json"]) .WithFile("package.json", workspaceJsonComponentStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "workspace", "package.json")) @@ -361,7 +363,7 @@ public async Task WellFormedYarnLockV1WithWorkspaceAltForm_FindsComponentAsync() var packageStream = NpmTestUtilities.GetPackageJsonOneRootComponentStream(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", componentStream.Stream) .WithFile("package.json", packageStream.Stream, ["package.json"]) .WithFile("package.json", workspaceJsonComponentStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "workspace", "package.json")) @@ -407,7 +409,7 @@ public async Task WellFormedYarnLockV2WithWorkspaceAltForm_FindsComponentAsync() var packageStream = NpmTestUtilities.GetPackageJsonOneRootComponentStream(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", componentStream.Stream) .WithFile("package.json", packageStream.Stream, ["package.json"]) .WithFile("package.json", workspaceJsonComponentStream.Stream, ["package.json"], Path.Combine(Path.GetTempPath(), "workspace", "package.json")) @@ -451,7 +453,7 @@ public async Task WellFormedYarnLockV1WithMoreThanOneComponent_FindsComponentsAs var yarnLock = this.CreateYarnLockV1FileContent([componentA, componentB]); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -498,7 +500,7 @@ public async Task WellFormedYarnLockV2WithMoreThanOneComponent_FindsComponentsAs var yarnLock = this.CreateYarnLockV2FileContent([componentA, componentB]); var (packageJsonName, packageJsonContent, packageJsonPath) = NpmTestUtilities.GetPackageJsonOneRoot(componentA.Name, componentA.RequestedVersion); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -571,7 +573,7 @@ public async Task WellFormedYarnLockV1WithMultiRootedComponent_FindsAllRootsAsyn var yarnLock = builder.ToString(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -647,7 +649,7 @@ public async Task WellFormedYarnLockV2WithMultiRootedComponent_FindsAllRootsAsyn var yarnLock = builder.ToString(); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLock) .WithFile("package.json", packageJsonContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -706,7 +708,7 @@ public async Task DependencyGraphV1IsGeneratedCorrectlyAsync() var yarnLockFileContent = this.CreateYarnLockV1FileContent([componentA, componentB, componentC]); var packageJsonFileContent = this.CreatePackageJsonFileContent([componentA, componentB, componentC]); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLockFileContent) .WithFile("package.json", packageJsonFileContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -762,7 +764,7 @@ public async Task DependencyGraphV2IsGeneratedCorrectlyAsync() var yarnLockFileContent = this.CreateYarnLockV2FileContent([componentA, componentB, componentC]); var packageJsonFileContent = this.CreatePackageJsonFileContent([componentA, componentB, componentC]); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLockFileContent) .WithFile("package.json", packageJsonFileContent, ["package.json"]) .ExecuteDetectorAsync(); @@ -804,7 +806,7 @@ public async Task MalformedYarnLockV1_DuplicateAsync() var yarnLockFileContent = builder.ToString(); var packageJsonFileContent = this.CreatePackageJsonFileContent([]); - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("yarn.lock", yarnLockFileContent) .WithFile("package.json", packageJsonFileContent, ["package.json"]) .ExecuteDetectorAsync(); diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/nuget/NuGetPackagesConfigDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/nuget/NuGetPackagesConfigDetectorTests.cs index 7d622471f..b1a9b30f5 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/nuget/NuGetPackagesConfigDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/nuget/NuGetPackagesConfigDetectorTests.cs @@ -10,8 +10,10 @@ namespace Microsoft.ComponentDetection.Detectors.Tests.NuGet; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] -public class NuGetPackagesConfigDetectorTests : BaseDetectorTest +public class NuGetPackagesConfigDetectorTests { + private readonly DetectorTestUtilityBuilder detectorTestUtility = new(); + [TestMethod] public async Task Should_WorkAsync() { @@ -23,7 +25,7 @@ public async Task Should_WorkAsync() "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("packages.config", packagesConfig) .ExecuteDetectorAsync(); @@ -51,7 +53,7 @@ public async Task Should_SkipWithInvalidVersionAsync() "; - var (scanResult, componentRecorder) = await this.DetectorTestUtility + var (scanResult, componentRecorder) = await this.detectorTestUtility .WithFile("packages.config", packagesConfig) .ExecuteDetectorAsync(); From 0bb1f7f4aa75cd8459bbc35607d3f48f25c56cde Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 5 Mar 2026 21:02:31 -0800 Subject: [PATCH 4/6] refactor: make Common implementation details internal Make ~50 classes internal in the Common project: - Telemetry records (~34 concrete classes): NuGetProjectAssetsTelemetryRecord, PyPiCacheTelemetryRecord, LinuxScannerTelemetryRecord, etc. Kept BaseDetectionTelemetryRecord public for external subclassing. - Utility classes: Column, TabularStringFormat, ComponentComparer, DependencyScopeComparer, DirectoryItemFacade(Optimized) - Docker reference exceptions (11 classes) - Concrete service implementations: CommandLineInvocationService, EnvironmentVariableService, PathUtilityService, FileUtilityService, DirectoryUtilityService, DockerService, ConsoleWritingService, SafeFileEnumerableFactory, ComponentStreamEnumerableFactory, FastDirectoryWalkerFactory Kept public: FileWritingService, ComponentStream, LazyComponentStream, ComponentRecorder, CommandLineInvocationResult, CommandLineTelemetryService, BaseDetectionTelemetryRecord, and all interfaces. Part of #455 --- .../Column.cs | 2 +- .../CommandLineInvocationService.cs | 2 +- .../ComponentComparer.cs | 2 +- .../ComponentStreamEnumerableFactory.cs | 2 +- .../ConsoleWritingService.cs | 2 +- .../DependencyScopeComparer.cs | 2 +- .../DirectoryItemFacade.cs | 2 +- .../DirectoryItemFacadeOptimized.cs | 2 +- .../DirectoryUtilityService.cs | 2 +- .../DockerReferenceException.cs | 22 +++++++++--------- .../DockerService.cs | 2 +- .../EnvironmentVariableService.cs | 2 +- .../FastDirectoryWalkerFactory.cs | 2 +- .../FileUtilityService.cs | 2 +- ...Microsoft.ComponentDetection.Common.csproj | 3 +++ .../PathUtilityService.cs | 2 +- .../SafeFileEnumerableFactory.cs | 2 +- .../TabularStringFormat.cs | 2 +- .../Records/BcdeExecutionTelemetryRecord.cs | 2 +- .../CommandLineInvocationTelemetryRecord.cs | 2 +- .../DependencyGraphTranslationRecord.cs | 2 +- .../Records/DetectedComponentScopeRecord.cs | 2 +- .../DetectorExecutionTelemetryRecord.cs | 2 +- ...erviceImageExistsLocallyTelemetryRecord.cs | 2 +- ...ockerServiceInspectImageTelemetryRecord.cs | 2 +- .../DockerServiceSystemInfoTelemetryRecord.cs | 2 +- .../Records/DockerServiceTelemetryRecord.cs | 2 +- ...ockerServiceTryPullImageTelemetryRecord.cs | 2 +- .../Records/FailedParsingFileRecord.cs | 2 +- .../Records/GoReplaceTelemetryRecord.cs | 2 +- .../InvalidParseVersionTelemetryRecord.cs | 2 +- ...uxContainerDetectorImageDetectionFailed.cs | 2 +- .../LinuxContainerDetectorLayerAwareness.cs | 2 +- ...inerDetectorMissingRepoNameAndTagRecord.cs | 2 +- .../LinuxContainerDetectorMissingVersion.cs | 2 +- .../Records/LinuxContainerDetectorTimeout.cs | 2 +- .../LinuxContainerDetectorUnsupportedOs.cs | 2 +- .../LinuxScannerSyftTelemetryRecord.cs | 2 +- .../Records/LinuxScannerTelemetryRecord.cs | 2 +- .../LoadComponentDetectorsTelemetryRecord.cs | 2 +- .../NuGetProjectAssetsTelemetryRecord.cs | 2 +- .../PipReportFailureTelemetryRecord.cs | 2 +- .../Records/PipReportSkipTelemetryRecord.cs | 2 +- .../Records/PipReportTypeTelemetryRecord.cs | 2 +- .../Records/PyPiCacheTelemetryRecord.cs | 2 +- .../Records/PypiFailureTelemetryRecord.cs | 2 +- .../PypiMaxRetriesReachedTelemetryRecord.cs | 2 +- .../Records/PypiRetryTelemetryRecord.cs | 2 +- .../RustCrateDetectorTelemetryRecord.cs | 2 +- .../Records/RustDetectionTelemetryRecord.cs | 2 +- .../Records/RustGraphTelemetryRecord.cs | 2 +- .../Records/SimplePypiCacheTelemetryRecord.cs | 2 +- .../PyPiClientTests.cs | 3 +-- .../SimplePypiClientTests.cs | 23 +++++++++---------- 54 files changed, 76 insertions(+), 75 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/Column.cs b/src/Microsoft.ComponentDetection.Common/Column.cs index d55f00044..aa9fda7a2 100644 --- a/src/Microsoft.ComponentDetection.Common/Column.cs +++ b/src/Microsoft.ComponentDetection.Common/Column.cs @@ -1,7 +1,7 @@ #nullable disable namespace Microsoft.ComponentDetection.Common; -public class Column +internal class Column { public int Width { get; set; } diff --git a/src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs b/src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs index 7dbf630f2..dc66db9ac 100644 --- a/src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs +++ b/src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs @@ -14,7 +14,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; /// -public class CommandLineInvocationService : ICommandLineInvocationService +internal class CommandLineInvocationService : ICommandLineInvocationService { private readonly IDictionary commandLocatableCache = new ConcurrentDictionary(); diff --git a/src/Microsoft.ComponentDetection.Common/ComponentComparer.cs b/src/Microsoft.ComponentDetection.Common/ComponentComparer.cs index f3417a13c..4fe7e8d3b 100644 --- a/src/Microsoft.ComponentDetection.Common/ComponentComparer.cs +++ b/src/Microsoft.ComponentDetection.Common/ComponentComparer.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Common; /// /// Compares two s by their . /// -public class ComponentComparer : EqualityComparer +internal class ComponentComparer : EqualityComparer { /// /// Determines whether the specified objects are equal. diff --git a/src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerableFactory.cs b/src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerableFactory.cs index 318394f23..4f74a9347 100644 --- a/src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerableFactory.cs +++ b/src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerableFactory.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.Extensions.Logging; /// -public class ComponentStreamEnumerableFactory : IComponentStreamEnumerableFactory +internal class ComponentStreamEnumerableFactory : IComponentStreamEnumerableFactory { private readonly IPathUtilityService pathUtilityService; private readonly ILogger logger; diff --git a/src/Microsoft.ComponentDetection.Common/ConsoleWritingService.cs b/src/Microsoft.ComponentDetection.Common/ConsoleWritingService.cs index 1edec9fb4..8235d6148 100644 --- a/src/Microsoft.ComponentDetection.Common/ConsoleWritingService.cs +++ b/src/Microsoft.ComponentDetection.Common/ConsoleWritingService.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common; using System; -public class ConsoleWritingService : IConsoleWritingService +internal class ConsoleWritingService : IConsoleWritingService { public void Write(string content) { diff --git a/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs b/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs index 79a0090a2..1b0ffe4a2 100644 --- a/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs +++ b/src/Microsoft.ComponentDetection.Common/DependencyScopeComparer.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common; /// Merges dependnecy Scope in their order of Priority. /// Higher priority scope, as indicated by its lower enum value is given precendence. /// -public static class DependencyScopeComparer +internal static class DependencyScopeComparer { public static DependencyScope? GetMergedDependencyScope(DependencyScope? scope1, DependencyScope? scope2) { diff --git a/src/Microsoft.ComponentDetection.Common/DirectoryItemFacade.cs b/src/Microsoft.ComponentDetection.Common/DirectoryItemFacade.cs index e06863526..bdec06e23 100644 --- a/src/Microsoft.ComponentDetection.Common/DirectoryItemFacade.cs +++ b/src/Microsoft.ComponentDetection.Common/DirectoryItemFacade.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; [DebuggerDisplay("{Name}")] -public class DirectoryItemFacade +internal class DirectoryItemFacade { public string Name { get; set; } diff --git a/src/Microsoft.ComponentDetection.Common/DirectoryItemFacadeOptimized.cs b/src/Microsoft.ComponentDetection.Common/DirectoryItemFacadeOptimized.cs index 85925b957..562435edf 100644 --- a/src/Microsoft.ComponentDetection.Common/DirectoryItemFacadeOptimized.cs +++ b/src/Microsoft.ComponentDetection.Common/DirectoryItemFacadeOptimized.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Common; using System.Diagnostics; [DebuggerDisplay("{Name}")] -public class DirectoryItemFacadeOptimized +internal class DirectoryItemFacadeOptimized { public string Name { get; set; } diff --git a/src/Microsoft.ComponentDetection.Common/DirectoryUtilityService.cs b/src/Microsoft.ComponentDetection.Common/DirectoryUtilityService.cs index f0ae8f9b9..d9279182b 100644 --- a/src/Microsoft.ComponentDetection.Common/DirectoryUtilityService.cs +++ b/src/Microsoft.ComponentDetection.Common/DirectoryUtilityService.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; /// -public class DirectoryUtilityService : IDirectoryUtilityService +internal class DirectoryUtilityService : IDirectoryUtilityService { /// public void Delete(string path, bool recursive) => Directory.Delete(path, recursive); diff --git a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceException.cs b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceException.cs index 07341d336..1ef1fec97 100644 --- a/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceException.cs +++ b/src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceException.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Common; using System; -public class DockerReferenceException : Exception +internal class DockerReferenceException : Exception { public DockerReferenceException(string reference, string exceptionErrorMessage) : base($"Error while parsing docker reference {reference} : {exceptionErrorMessage}") @@ -26,7 +26,7 @@ public DockerReferenceException(string message, Exception innerException) } // ReferenceInvalidFormat represents an error while trying to parse a string as a reference. -public class ReferenceInvalidFormatException : DockerReferenceException +internal class ReferenceInvalidFormatException : DockerReferenceException { private const string ErrorMessage = "invalid reference format"; @@ -46,7 +46,7 @@ public ReferenceInvalidFormatException(string message, Exception innerException) } // TagInvalidFormat represents an error while trying to parse a string as a tag. -public class ReferenceTagInvalidFormatException : DockerReferenceException +internal class ReferenceTagInvalidFormatException : DockerReferenceException { private const string ErrorMessage = "invalid tag format"; @@ -66,7 +66,7 @@ public ReferenceTagInvalidFormatException(string message, Exception innerExcepti } // DigestInvalidFormat represents an error while trying to parse a string as a tag. -public class ReferenceDigestInvalidFormatException : DockerReferenceException +internal class ReferenceDigestInvalidFormatException : DockerReferenceException { private const string ErrorMessage = "invalid digest format"; @@ -86,7 +86,7 @@ public ReferenceDigestInvalidFormatException(string message, Exception innerExce } // NameContainsUppercase is returned for invalid repository names that contain uppercase characters. -public class ReferenceNameContainsUppercaseException : DockerReferenceException +internal class ReferenceNameContainsUppercaseException : DockerReferenceException { private const string ErrorMessage = "repository name must be lowercase"; @@ -106,7 +106,7 @@ public ReferenceNameContainsUppercaseException(string message, Exception innerEx } // NameEmpty is returned for empty, invalid repository names. -public class ReferenceNameEmptyException : DockerReferenceException +internal class ReferenceNameEmptyException : DockerReferenceException { private const string ErrorMessage = "repository name must have at least one component"; @@ -126,7 +126,7 @@ public ReferenceNameEmptyException(string message, Exception innerException) } // ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax. -public class ReferenceNameTooLongException : DockerReferenceException +internal class ReferenceNameTooLongException : DockerReferenceException { private const string ErrorMessage = "repository name must not be more than 255 characters"; @@ -146,7 +146,7 @@ public ReferenceNameTooLongException(string message, Exception innerException) } // ErrNameNotCanonical is returned when a name is not canonical. -public class ReferenceNameNotCanonicalException : DockerReferenceException +internal class ReferenceNameNotCanonicalException : DockerReferenceException { private const string ErrorMessage = "repository name must be canonical"; @@ -165,7 +165,7 @@ public ReferenceNameNotCanonicalException(string message, Exception innerExcepti } } -public class InvalidDigestFormatError : DockerReferenceException +internal class InvalidDigestFormatError : DockerReferenceException { private const string ErrorMessage = "invalid digest format"; @@ -184,7 +184,7 @@ public InvalidDigestFormatError(string message, Exception innerException) } } -public class UnsupportedAlgorithmError : DockerReferenceException +internal class UnsupportedAlgorithmError : DockerReferenceException { private const string ErrorMessage = "unsupported digest algorithm"; @@ -203,7 +203,7 @@ public UnsupportedAlgorithmError(string message, Exception innerException) } } -public class InvalidDigestLengthError : DockerReferenceException +internal class InvalidDigestLengthError : DockerReferenceException { private const string ErrorMessage = "invalid checksum digest length"; diff --git a/src/Microsoft.ComponentDetection.Common/DockerService.cs b/src/Microsoft.ComponentDetection.Common/DockerService.cs index d9b47e05b..cb0ce2274 100644 --- a/src/Microsoft.ComponentDetection.Common/DockerService.cs +++ b/src/Microsoft.ComponentDetection.Common/DockerService.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts.BcdeModels; using Microsoft.Extensions.Logging; -public class DockerService : IDockerService +internal class DockerService : IDockerService { // Base image annotations from ADO dockerTask private const string BaseImageRefAnnotation = "image.base.ref.name"; diff --git a/src/Microsoft.ComponentDetection.Common/EnvironmentVariableService.cs b/src/Microsoft.ComponentDetection.Common/EnvironmentVariableService.cs index 188efb667..c89e47024 100644 --- a/src/Microsoft.ComponentDetection.Common/EnvironmentVariableService.cs +++ b/src/Microsoft.ComponentDetection.Common/EnvironmentVariableService.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common; using System.Linq; using Microsoft.ComponentDetection.Contracts; -public class EnvironmentVariableService : IEnvironmentVariableService +internal class EnvironmentVariableService : IEnvironmentVariableService { public bool DoesEnvironmentVariableExist(string name) { diff --git a/src/Microsoft.ComponentDetection.Common/FastDirectoryWalkerFactory.cs b/src/Microsoft.ComponentDetection.Common/FastDirectoryWalkerFactory.cs index a6ce9c286..3dd13995f 100644 --- a/src/Microsoft.ComponentDetection.Common/FastDirectoryWalkerFactory.cs +++ b/src/Microsoft.ComponentDetection.Common/FastDirectoryWalkerFactory.cs @@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts.Internal; using Microsoft.Extensions.Logging; -public class FastDirectoryWalkerFactory : IObservableDirectoryWalkerFactory +internal class FastDirectoryWalkerFactory : IObservableDirectoryWalkerFactory { private readonly ConcurrentDictionary>> pendingScans = new ConcurrentDictionary>>(); private readonly IPathUtilityService pathUtilityService; diff --git a/src/Microsoft.ComponentDetection.Common/FileUtilityService.cs b/src/Microsoft.ComponentDetection.Common/FileUtilityService.cs index 6fc7857b5..d7ebbe7b9 100644 --- a/src/Microsoft.ComponentDetection.Common/FileUtilityService.cs +++ b/src/Microsoft.ComponentDetection.Common/FileUtilityService.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; /// -public class FileUtilityService : IFileUtilityService +internal class FileUtilityService : IFileUtilityService { /// public string ReadAllText(string filePath) diff --git a/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj b/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj index efdcd5363..41489c99f 100644 --- a/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj +++ b/src/Microsoft.ComponentDetection.Common/Microsoft.ComponentDetection.Common.csproj @@ -5,6 +5,9 @@ + + + diff --git a/src/Microsoft.ComponentDetection.Common/PathUtilityService.cs b/src/Microsoft.ComponentDetection.Common/PathUtilityService.cs index 27df98217..f55228b40 100644 --- a/src/Microsoft.ComponentDetection.Common/PathUtilityService.cs +++ b/src/Microsoft.ComponentDetection.Common/PathUtilityService.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.Extensions.Logging; // We may want to consider breaking this class into Win/Mac/Linux variants if it gets bigger -public class PathUtilityService : IPathUtilityService +internal class PathUtilityService : IPathUtilityService { public const uint CreationDispositionRead = 0x3; diff --git a/src/Microsoft.ComponentDetection.Common/SafeFileEnumerableFactory.cs b/src/Microsoft.ComponentDetection.Common/SafeFileEnumerableFactory.cs index 64344c123..98ef62eb0 100644 --- a/src/Microsoft.ComponentDetection.Common/SafeFileEnumerableFactory.cs +++ b/src/Microsoft.ComponentDetection.Common/SafeFileEnumerableFactory.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; using Microsoft.Extensions.Logging; -public class SafeFileEnumerableFactory : ISafeFileEnumerableFactory +internal class SafeFileEnumerableFactory : ISafeFileEnumerableFactory { private readonly IPathUtilityService pathUtilityService; private readonly ILogger logger; diff --git a/src/Microsoft.ComponentDetection.Common/TabularStringFormat.cs b/src/Microsoft.ComponentDetection.Common/TabularStringFormat.cs index aa6c314ab..2b2589747 100644 --- a/src/Microsoft.ComponentDetection.Common/TabularStringFormat.cs +++ b/src/Microsoft.ComponentDetection.Common/TabularStringFormat.cs @@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common; using System.Linq; using System.Text; -public class TabularStringFormat +internal class TabularStringFormat { public const char DefaultVerticalLineChar = '|'; public const char DefaultHorizontalLineChar = '_'; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/BcdeExecutionTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/BcdeExecutionTelemetryRecord.cs index b7cab203b..7bf45e883 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/BcdeExecutionTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/BcdeExecutionTelemetryRecord.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System.Threading; using System.Threading.Tasks; -public class BcdeExecutionTelemetryRecord : BaseDetectionTelemetryRecord +internal class BcdeExecutionTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "BcdeExecution"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/CommandLineInvocationTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/CommandLineInvocationTelemetryRecord.cs index dcb111a3e..c5730d20c 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/CommandLineInvocationTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/CommandLineInvocationTelemetryRecord.cs @@ -3,7 +3,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System; using Microsoft.ComponentDetection.Contracts; -public class CommandLineInvocationTelemetryRecord : BaseDetectionTelemetryRecord +internal class CommandLineInvocationTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "CommandLineInvocation"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DependencyGraphTranslationRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DependencyGraphTranslationRecord.cs index bd73c55e3..782dd3022 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DependencyGraphTranslationRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DependencyGraphTranslationRecord.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System; -public class DependencyGraphTranslationRecord : BaseDetectionTelemetryRecord +internal class DependencyGraphTranslationRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DependencyGraphTranslationRecord"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectedComponentScopeRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectedComponentScopeRecord.cs index 94c437277..4ec418c07 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectedComponentScopeRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectedComponentScopeRecord.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System.Runtime.CompilerServices; -public class DetectedComponentScopeRecord : BaseDetectionTelemetryRecord +internal class DetectedComponentScopeRecord : BaseDetectionTelemetryRecord { public override string RecordName => "ComponentScopeRecord"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectorExecutionTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectorExecutionTelemetryRecord.cs index 03abd3daf..d2e1f47b4 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectorExecutionTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DetectorExecutionTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DetectorExecutionTelemetryRecord : BaseDetectionTelemetryRecord +internal class DetectorExecutionTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DetectorExecution"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceImageExistsLocallyTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceImageExistsLocallyTelemetryRecord.cs index 844f773a9..478622949 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceImageExistsLocallyTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceImageExistsLocallyTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DockerServiceImageExistsLocallyTelemetryRecord : BaseDetectionTelemetryRecord +internal class DockerServiceImageExistsLocallyTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DockerServiceImageExistsLocally"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceInspectImageTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceInspectImageTelemetryRecord.cs index c04d287d4..0041e002d 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceInspectImageTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceInspectImageTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DockerServiceInspectImageTelemetryRecord : BaseDetectionTelemetryRecord +internal class DockerServiceInspectImageTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DockerServiceInspectImage"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceSystemInfoTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceSystemInfoTelemetryRecord.cs index 7991cd40c..30f9066de 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceSystemInfoTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceSystemInfoTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DockerServiceSystemInfoTelemetryRecord : BaseDetectionTelemetryRecord +internal class DockerServiceSystemInfoTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DockerServiceSystemInfo"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTelemetryRecord.cs index e93e25681..8357a967f 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DockerServiceTelemetryRecord : BaseDetectionTelemetryRecord +internal class DockerServiceTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DockerService"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTryPullImageTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTryPullImageTelemetryRecord.cs index 79e77779a..211f593eb 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTryPullImageTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/DockerServiceTryPullImageTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class DockerServiceTryPullImageTelemetryRecord : BaseDetectionTelemetryRecord +internal class DockerServiceTryPullImageTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "DockerServiceTryPullImage"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/FailedParsingFileRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/FailedParsingFileRecord.cs index f5e210ff2..e6cfc8576 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/FailedParsingFileRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/FailedParsingFileRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class FailedParsingFileRecord : BaseDetectionTelemetryRecord +internal class FailedParsingFileRecord : BaseDetectionTelemetryRecord { public override string RecordName => "FailedParsingFile"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs index 0403f6c01..41ad6daad 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/GoReplaceTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class GoReplaceTelemetryRecord : BaseDetectionTelemetryRecord +internal class GoReplaceTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "GoReplace"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/InvalidParseVersionTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/InvalidParseVersionTelemetryRecord.cs index 838fa52c8..f3f249d1a 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/InvalidParseVersionTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/InvalidParseVersionTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class InvalidParseVersionTelemetryRecord : BaseDetectionTelemetryRecord +internal class InvalidParseVersionTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "InvalidParseVersion"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorImageDetectionFailed.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorImageDetectionFailed.cs index 46aae7758..4e13c5d03 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorImageDetectionFailed.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorImageDetectionFailed.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorImageDetectionFailed : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorImageDetectionFailed : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxContainerDetectorImageDetectionFailed"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorLayerAwareness.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorLayerAwareness.cs index cf39c768f..e8c63b4fd 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorLayerAwareness.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorLayerAwareness.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorLayerAwareness : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorLayerAwareness : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxContainerDetectorLayerAwareness"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingRepoNameAndTagRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingRepoNameAndTagRecord.cs index 6d64ae1a0..e1269c862 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingRepoNameAndTagRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingRepoNameAndTagRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorMissingRepoNameAndTagRecord : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorMissingRepoNameAndTagRecord : BaseDetectionTelemetryRecord { public override string RecordName => "MissingRepoNameAndTag"; } diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingVersion.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingVersion.cs index a28f2d990..2372bacf9 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingVersion.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorMissingVersion.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorMissingVersion : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorMissingVersion : BaseDetectionTelemetryRecord { public override string RecordName { get; } = "MissingVersion"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorTimeout.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorTimeout.cs index 4e91d6122..83108c0fd 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorTimeout.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorTimeout.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorTimeout : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorTimeout : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxContainerDetectorTimeout"; } diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorUnsupportedOs.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorUnsupportedOs.cs index 415615306..937e5eaac 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorUnsupportedOs.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxContainerDetectorUnsupportedOs.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxContainerDetectorUnsupportedOs : BaseDetectionTelemetryRecord +internal class LinuxContainerDetectorUnsupportedOs : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxContainerDetectorUnsupportedOs"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerSyftTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerSyftTelemetryRecord.cs index e52b0f60f..9aa3de6f0 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerSyftTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerSyftTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxScannerSyftTelemetryRecord : BaseDetectionTelemetryRecord +internal class LinuxScannerSyftTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxScannerSyftTelemetry"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerTelemetryRecord.cs index d3ad07ddd..502e689ba 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LinuxScannerTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LinuxScannerTelemetryRecord : BaseDetectionTelemetryRecord +internal class LinuxScannerTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "LinuxScannerTelemetry"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LoadComponentDetectorsTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LoadComponentDetectorsTelemetryRecord.cs index ce68a8a76..64ce4ff06 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LoadComponentDetectorsTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/LoadComponentDetectorsTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class LoadComponentDetectorsTelemetryRecord : BaseDetectionTelemetryRecord +internal class LoadComponentDetectorsTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "LoadComponentDetectors"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/NuGetProjectAssetsTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/NuGetProjectAssetsTelemetryRecord.cs index 42dd490d6..b28422c0d 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/NuGetProjectAssetsTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/NuGetProjectAssetsTelemetryRecord.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System; -public class NuGetProjectAssetsTelemetryRecord : IDetectionTelemetryRecord, IDisposable +internal class NuGetProjectAssetsTelemetryRecord : IDetectionTelemetryRecord, IDisposable { private bool disposedValue; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportFailureTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportFailureTelemetryRecord.cs index bb68174f1..d8a720721 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportFailureTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportFailureTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class PipReportFailureTelemetryRecord : BaseDetectionTelemetryRecord +internal class PipReportFailureTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PipReportFailure"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportSkipTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportSkipTelemetryRecord.cs index 2032d314b..f3352eaee 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportSkipTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportSkipTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class PipReportSkipTelemetryRecord : BaseDetectionTelemetryRecord +internal class PipReportSkipTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PipReportSkip"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportTypeTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportTypeTelemetryRecord.cs index dd393bed0..e7cee9d66 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportTypeTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportTypeTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class PipReportTypeTelemetryRecord : BaseDetectionTelemetryRecord +internal class PipReportTypeTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PipReportType"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs index ff0a5920e..18b621051 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PyPiCacheTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class PypiCacheTelemetryRecord : BaseDetectionTelemetryRecord +internal class PypiCacheTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PyPiCache"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiFailureTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiFailureTelemetryRecord.cs index bf70d5c7a..369766e04 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiFailureTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiFailureTelemetryRecord.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System.Net; -public class PypiFailureTelemetryRecord : BaseDetectionTelemetryRecord +internal class PypiFailureTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PypiFailure"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiMaxRetriesReachedTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiMaxRetriesReachedTelemetryRecord.cs index 089e2ab17..b7b95a89b 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiMaxRetriesReachedTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiMaxRetriesReachedTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class PypiMaxRetriesReachedTelemetryRecord : BaseDetectionTelemetryRecord +internal class PypiMaxRetriesReachedTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PypiMaxRetriesReached"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiRetryTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiRetryTelemetryRecord.cs index a882f03f7..3de58830d 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiRetryTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/PypiRetryTelemetryRecord.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; using System.Net; -public class PypiRetryTelemetryRecord : BaseDetectionTelemetryRecord +internal class PypiRetryTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "PypiRetry"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustCrateDetectorTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustCrateDetectorTelemetryRecord.cs index 8e795f587..2d919c612 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustCrateDetectorTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustCrateDetectorTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class RustCrateDetectorTelemetryRecord : BaseDetectionTelemetryRecord +internal class RustCrateDetectorTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "RustCrateMalformedDependencies"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustDetectionTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustDetectionTelemetryRecord.cs index 85ffe6b92..ff1561ba3 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustDetectionTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustDetectionTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class RustDetectionTelemetryRecord : BaseDetectionTelemetryRecord +internal class RustDetectionTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "RustDetection"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustGraphTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustGraphTelemetryRecord.cs index 2b2510287..4f3959949 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustGraphTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/RustGraphTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class RustGraphTelemetryRecord : BaseDetectionTelemetryRecord +internal class RustGraphTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "RustGraph"; diff --git a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/SimplePypiCacheTelemetryRecord.cs b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/SimplePypiCacheTelemetryRecord.cs index b615b82d7..9f56fdbcc 100644 --- a/src/Microsoft.ComponentDetection.Common/Telemetry/Records/SimplePypiCacheTelemetryRecord.cs +++ b/src/Microsoft.ComponentDetection.Common/Telemetry/Records/SimplePypiCacheTelemetryRecord.cs @@ -1,6 +1,6 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records; -public class SimplePypiCacheTelemetryRecord : BaseDetectionTelemetryRecord +internal class SimplePypiCacheTelemetryRecord : BaseDetectionTelemetryRecord { public override string RecordName => "SimplePyPiCache"; diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/PyPiClientTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/PyPiClientTests.cs index ca30856a7..fc2b413f7 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/PyPiClientTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/PyPiClientTests.cs @@ -11,7 +11,6 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; using System.Threading; using System.Threading.Tasks; using AwesomeAssertions; -using Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.Extensions.Logging; @@ -25,7 +24,7 @@ public class PyPiClientTests private readonly PyPiClient pypiClient; public PyPiClientTests() => this.pypiClient = new PyPiClient( - new EnvironmentVariableService(), + new Mock().Object, new Mock>().Object); [TestMethod] diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/SimplePypiClientTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/SimplePypiClientTests.cs index 0dc1c6386..1b75fb629 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/SimplePypiClientTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/SimplePypiClientTests.cs @@ -9,7 +9,6 @@ namespace Microsoft.ComponentDetection.Detectors.Tests; using System.Threading; using System.Threading.Tasks; using AwesomeAssertions; -using Microsoft.ComponentDetection.Common; using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Detectors.Pip; using Microsoft.Extensions.Logging; @@ -50,7 +49,7 @@ public async Task GetSimplePypiProject_DuplicateEntries_CallsGetAsync_OnceAsync( var pythonProject = this.SampleValidApiJsonResponse("boto3", "0.0.1"); var mockHandler = this.MockHttpMessageHandler(pythonProject, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); await action.Should().NotThrowAsync(); @@ -74,7 +73,7 @@ public async Task GetSimplePypiProject_DifferentEntries_CallsGetAsync_TwiceAsync }; var mockHandler = this.MockHttpMessageHandler(JsonSerializer.Serialize(pythonProject), HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => { @@ -108,7 +107,7 @@ public async Task GetSimplePypiProject_ReturnsValidSimplePypiProjectAsync() }; var mockHandler = this.MockHttpMessageHandler(sampleApiResponse, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var actualResult = await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); actualResult.Should().BeEquivalentTo(expectedResult); @@ -120,7 +119,7 @@ public async Task GetSimplePypiProject_InvalidSpec_NotThrowAsync() var pythonSpecs = new PipDependencySpecification { DependencySpecifiers = ["==1.0.0"], Name = "randomName" }; var mockHandler = this.MockHttpMessageHandler("404 Not Found", HttpStatusCode.NotFound); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); @@ -134,7 +133,7 @@ public async Task GetSimplePypiProject_UnexpectedContentTypeReturnedByApi_NotThr var content = "\r\n\t

Links for boto3

\r\n\tboto3-0.0.1-py2.py3-none-any.whl
"; var mockHandler = this.MockHttpMessageHandler(content, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); @@ -147,7 +146,7 @@ public async Task GetSimplePypiProject_ShouldRetryAsync() var pythonSpecs = new PipDependencySpecification { DependencySpecifiers = ["==1.0.0"] }; var mockHandler = this.MockHttpMessageHandler(string.Empty, HttpStatusCode.InternalServerError); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); @@ -166,7 +165,7 @@ public async Task GetSimplePypiProject_ShouldNotRetryAsync() { var pythonSpecs = new PipDependencySpecification { DependencySpecifiers = ["==1.0.0"] }; var mockHandler = this.MockHttpMessageHandler("some content", HttpStatusCode.MultipleChoices); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); await action.Should().NotThrowAsync(); @@ -186,7 +185,7 @@ public async Task GetSimplePypiProject_AddsCorrectHeadersAsync() var pythonProject = this.SampleValidApiJsonResponse("boto3", "0.0.1"); var mockHandler = this.MockHttpMessageHandler(pythonProject, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.GetSimplePypiProjectAsync(pythonSpecs); @@ -265,7 +264,7 @@ public async Task FetchPackageFileStream_MaxEntriesVariable_CreatesNewCacheAsync public async Task FetchPackageFileStream_DuplicateEntries_CallsGetAsync_OnceAsync() { var mockHandler = this.MockHttpMessageHandler(string.Empty, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.FetchPackageFileStreamAsync(new Uri($"https://testurl")); @@ -284,7 +283,7 @@ public async Task FetchPackageFileStream_DuplicateEntries_CallsGetAsync_OnceAsyn public async Task FetchPackageFileStream_DifferentEntries_CallsGetAsync_TwiceAsync() { var mockHandler = this.MockHttpMessageHandler(string.Empty, HttpStatusCode.OK); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => await simplePypiClient.FetchPackageFileStreamAsync(new Uri($"https://{Guid.NewGuid()}")); @@ -303,7 +302,7 @@ public async Task FetchPackageFileStream_DifferentEntries_CallsGetAsync_TwiceAsy public async Task FetchPackageFileStream_UnableToRetrievePackageAsync() { var mockHandler = this.MockHttpMessageHandler(string.Empty, HttpStatusCode.InternalServerError); - var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); + var simplePypiClient = this.CreateSimplePypiClient(mockHandler.Object, new Mock().Object, new Mock>().Object); var action = async () => { return await simplePypiClient.FetchPackageFileStreamAsync(new Uri($"https://{Guid.NewGuid()}")); }; From ceb93dacc18dc2c382b3959836acd52ba95fb2ab Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 5 Mar 2026 21:06:41 -0800 Subject: [PATCH 5/6] refactor: make Orchestrator implementation details internal Make 8 classes internal in the Orchestrator project: - Converter classes: CommaDelimitedConverter, KeyValueDelimitedConverter, SemicolonDelimitedConverter - CLI helpers: ArgumentHelper, IArgumentHelper - Concrete service implementations: DetectorProcessingService, DetectorRestrictionService, DefaultGraphTranslationService Kept public: ServiceCollectionExtensions, ScanExecutionService, ScanCommand, ScanSettings, LoggingEnricher, DetectorRestrictions, all experiment types, all service interfaces, DetectorRunResult, DetectorProcessingResult. Part of #455 --- src/Microsoft.ComponentDetection.Orchestrator/ArgumentHelper.cs | 2 +- .../Extensions/CommaDelimitedConverter.cs | 2 +- .../Extensions/KeyValueDelimitedConverter.cs | 2 +- .../Extensions/SemicolonDelimitedConverter.cs | 2 +- .../IArgumentHelper.cs | 2 +- .../Microsoft.ComponentDetection.Orchestrator.csproj | 1 + .../Services/DetectorProcessingService.cs | 2 +- .../Services/DetectorRestrictionService.cs | 2 +- .../Services/GraphTranslation/DefaultGraphTranslationService.cs | 2 +- 9 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/ArgumentHelper.cs b/src/Microsoft.ComponentDetection.Orchestrator/ArgumentHelper.cs index bbf0afe8a..820983517 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/ArgumentHelper.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/ArgumentHelper.cs @@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Orchestrator; using CommandLine; using Microsoft.ComponentDetection.Orchestrator.Commands; -public class ArgumentHelper : IArgumentHelper +internal class ArgumentHelper : IArgumentHelper { private readonly IEnumerable argumentSets; diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/CommaDelimitedConverter.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/CommaDelimitedConverter.cs index c8f0a3770..98a4d9806 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/CommaDelimitedConverter.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/CommaDelimitedConverter.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Extensions; /// /// Converts a comma separated string to an array of strings. /// -public class CommaDelimitedConverter : TypeConverter +internal class CommaDelimitedConverter : TypeConverter { /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/KeyValueDelimitedConverter.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/KeyValueDelimitedConverter.cs index b39585367..ae89bcd69 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/KeyValueDelimitedConverter.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/KeyValueDelimitedConverter.cs @@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Extensions; /// /// Converts a comma separated string of key value pairs to a dictionary. /// -public class KeyValueDelimitedConverter : TypeConverter +internal class KeyValueDelimitedConverter : TypeConverter { /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/SemicolonDelimitedConverter.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/SemicolonDelimitedConverter.cs index d2294c8f3..e1d19567a 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/SemicolonDelimitedConverter.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/SemicolonDelimitedConverter.cs @@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Extensions; /// /// Converts a semicolon separated string to an array of strings. /// -public class SemicolonDelimitedConverter : TypeConverter +internal class SemicolonDelimitedConverter : TypeConverter { /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/IArgumentHelper.cs b/src/Microsoft.ComponentDetection.Orchestrator/IArgumentHelper.cs index 587b8a27c..6f598269a 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/IArgumentHelper.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/IArgumentHelper.cs @@ -2,7 +2,7 @@ namespace Microsoft.ComponentDetection.Orchestrator; using CommandLine; -public interface IArgumentHelper +internal interface IArgumentHelper { ParserResult ParseArguments(string[] args); diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj index 8305338d5..cca6e05b2 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj +++ b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj @@ -4,6 +4,7 @@ + diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs index fb62bb323..d3a7d9fe4 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs @@ -22,7 +22,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services; using Spectre.Console; using static System.Environment; -public class DetectorProcessingService : IDetectorProcessingService +internal class DetectorProcessingService : IDetectorProcessingService { private const int DefaultMaxDetectionThreads = 5; private const int ExperimentalTimeoutSeconds = 240; // 4 minutes diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorRestrictionService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorRestrictionService.cs index 958a5668d..14f4c1ac3 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorRestrictionService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorRestrictionService.cs @@ -7,7 +7,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services; using Microsoft.ComponentDetection.Orchestrator.Exceptions; using Microsoft.Extensions.Logging; -public class DetectorRestrictionService : IDetectorRestrictionService +internal class DetectorRestrictionService : IDetectorRestrictionService { private readonly IList oldDetectorIds = ["MSLicenseDevNpm", "MSLicenseDevNpmList", "MSLicenseNpm", "MSLicenseNpmList"]; private readonly string newDetectorId = "NpmWithRoots"; diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs index 179c9303d..3a27d49c9 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs @@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services.GraphTranslation; using Microsoft.ComponentDetection.Orchestrator.Commands; using Microsoft.Extensions.Logging; -public class DefaultGraphTranslationService : IGraphTranslationService +internal class DefaultGraphTranslationService : IGraphTranslationService { private readonly ILogger logger; From 94e0615627e68e70dd762a9871543ad9d62641be Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Fri, 6 Mar 2026 13:14:02 -0800 Subject: [PATCH 6/6] chore: enable CA1515 to prevent unnecessary public types Enable the CA1515 analyzer rule ("Make class internal") in .editorconfig to prevent new unnecessary public types from accumulating in the future. This rule requires .NET 9+ SDK to enforce. Once the SDK is upgraded, any new public class that could be internal will produce a build warning. Part of #455 --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index 66d093589..85841537e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -706,6 +706,11 @@ dotnet_diagnostic.IDE0240.severity = suggestion # IDE0241: Nullable directive is unnecessary dotnet_diagnostic.IDE0241.severity = suggestion +# CA1515: Make class internal +# Prevents unnecessary public types from accumulating. +# Requires .NET 9+ SDK to enforce. +dotnet_diagnostic.CA1515.severity = warning + # Workaround for https://github.com/dotnet/roslyn-analyzers/issues/5628 [Program.cs] dotnet_diagnostic.ca1812.severity = none