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: verify IExperimentConfigurations #812

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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,80 @@
namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
using Microsoft.ComponentDetection.Orchestrator.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

[TestClass]
[TestCategory("Governance/All")]
[TestCategory("Governance/ComponentDetection")]
public class ExperimentConfigTests
{
private List<IExperimentConfiguration> configs;

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

this.configs = serviceProvider.GetServices<IExperimentConfiguration>().ToList();
}

[TestMethod]
public void ExperimentConfig_HaveDistinctNames()
{
var names = this.configs.Select(c => c.Name).ToList();

names.Should().OnlyHaveUniqueItems();
}

[TestMethod]
public async Task ExperimentConfig_InitShouldNotThrowAsync()
{
foreach (var config in this.configs)
{
var init = async () => await config.InitAsync();

await init.Should().NotThrowAsync($"the experiment {config.Name} threw an exception in InitAsync");
}
}

[TestMethod]
public void ExperimentConfig_ShouldRecordShouldNotThrow()
{
foreach (var config in this.configs)
{
var shouldRecord = () => config.ShouldRecord(Mock.Of<IComponentDetector>(), 0);

shouldRecord.Should().NotThrow($"the experiment {config.Name} threw an exception in ShouldRecordAsync");
}
}

[TestMethod]
public void ExperimentConfig_IsInControlGroupShouldNotThrow()
{
foreach (var config in this.configs)
{
var isInControlGroup = () => config.IsInControlGroup(Mock.Of<IComponentDetector>());

isInControlGroup.Should().NotThrow($"the experiment {config.Name} threw an exception in IsInControlGroupAsync");
}
}

[TestMethod]
public void ExperimentConfig_IsInExperimentGroupShouldNotThrow()
{
foreach (var config in this.configs)
{
var isInExperimentGroup = () => config.IsInExperimentGroup(Mock.Of<IComponentDetector>());

isInExperimentGroup.Should().NotThrow($"the experiment {config.Name} threw an exception in IsInExperimentGroupAsync");
}
}
}
Loading