Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Weatherford authored and Stephen Weatherford committed Dec 16, 2023
1 parent ef02c60 commit 3550ed5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Bicep.Core.UnitTests/BicepTestConstants.cs
Expand Up @@ -134,15 +134,21 @@ public static IFeatureProviderFactory CreateFeatureProviderFactory(FeatureProvid
public static (IModuleDispatcher moduleDispatcher, IModuleRestoreScheduler moduleRestoreScheduler) CreateMockModuleDispatcherAndRestoreScheduler(IArtifactRegistry[]? artifactRegistries = null)
{
var moduleDispatcher = StrictMock.Of<IModuleDispatcher>();
moduleDispatcher.Setup(x => x.RestoreModules(It.IsAny<ImmutableArray<ArtifactReference>>(), It.IsAny<bool>())).
ReturnsAsync(true);
moduleDispatcher.Setup(x => x.PruneRestoreStatuses());
if (artifactRegistries is { })
{
moduleDispatcher.Setup(x => x.RestoreModules(It.IsAny<ImmutableArray<ArtifactReference>>(), It.IsAny<bool>())).
ReturnsAsync(true);
moduleDispatcher.Setup(x => x.PruneRestoreStatuses());
}

MockRepository repository = new(MockBehavior.Strict);
var provider = repository.Create<IArtifactRegistryProvider>();

moduleDispatcher.Setup(m => m.TryGetModuleSources(It.IsAny<ArtifactReference>())).Returns((ArtifactReference reference) =>
(artifactRegistries ?? new IArtifactRegistry[] { }).Select(r => r.TryGetSource(reference)).FirstOrDefault(s => s is not null));
if (artifactRegistries is { })
{
moduleDispatcher.Setup(m => m.TryGetModuleSources(It.IsAny<ArtifactReference>())).Returns((ArtifactReference reference) =>
(artifactRegistries ?? new IArtifactRegistry[] { }).Select(r => r.TryGetSource(reference)).FirstOrDefault(s => s is not null));
}

return (moduleDispatcher.Object, new ModuleRestoreScheduler(moduleDispatcher.Object));
}
Expand Down

0 comments on commit 3550ed5

Please sign in to comment.