Skip to content

Commit

Permalink
tests: detector properties (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
melotic authored Sep 29, 2023
1 parent 58fd79f commit f7879d6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<IComponentDetector> detectors;

[TestInitialize]
public void Initialize()
{
var serviceProvider = new ServiceCollection().AddComponentDetection().BuildServiceProvider();

this.detectors = serviceProvider.GetServices<IComponentDetector>().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");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup Label="Project References">
<ProjectReference Include="..\..\src\Microsoft.ComponentDetection.Orchestrator\Microsoft.ComponentDetection.Orchestrator.csproj" />
<ProjectReference Include="..\Microsoft.ComponentDetection.TestsUtilities\Microsoft.ComponentDetection.TestsUtilities.csproj" />
</ItemGroup>

Expand Down

0 comments on commit f7879d6

Please sign in to comment.