diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs new file mode 100644 index 000000000..7c1e6d1b1 --- /dev/null +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/ComponentDetectorTests.cs @@ -0,0 +1,60 @@ +namespace Microsoft.ComponentDetection.Detectors.Tests; + +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Microsoft.ComponentDetection.Contracts; +using Microsoft.ComponentDetection.Orchestrator.Extensions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[TestClass] +[TestCategory("Governance/All")] +[TestCategory("Governance/ComponentDetection")] +public class ComponentDetectorTests +{ + private List detectors; + + [TestInitialize] + public void Initialize() + { + var serviceProvider = new ServiceCollection().AddComponentDetection().BuildServiceProvider(); + + this.detectors = serviceProvider.GetServices().ToList(); + } + + [TestMethod] + public void AllDetectorsHaveUniqueIds() + { + var ids = this.detectors.Select(detector => detector.Id).ToList(); + + ids.Should().OnlyHaveUniqueItems(); + } + + [TestMethod] + public void AllDetectorsHavePositiveVersion() + { + foreach (var detector in this.detectors) + { + detector.Version.Should().BePositive($"because {detector.Id} should be > 0"); + } + } + + [TestMethod] + public void AllDetectorsHaveUniqueCategories() + { + foreach (var detector in this.detectors) + { + detector.Categories.Should().OnlyHaveUniqueItems($"because {detector.Id} should have unique categories"); + } + } + + [TestMethod] + public void AllDetectorsHaveUniqueSupportedComponentTypes() + { + foreach (var detector in this.detectors) + { + detector.SupportedComponentTypes.Should().OnlyHaveUniqueItems($"because {detector.Id} should have unique supported component types"); + } + } +} diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/Microsoft.ComponentDetection.Detectors.Tests.csproj b/test/Microsoft.ComponentDetection.Detectors.Tests/Microsoft.ComponentDetection.Detectors.Tests.csproj index e47a3886f..7be9fd172 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/Microsoft.ComponentDetection.Detectors.Tests.csproj +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/Microsoft.ComponentDetection.Detectors.Tests.csproj @@ -1,6 +1,7 @@  +