Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

tests: detector properties #813

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading