Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Jun 12, 2024
1 parent fcac564 commit a1a1636
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Bicep.Core.UnitTests/BicepTestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public static class BicepTestConstants

public static readonly IServiceProvider EmptyServiceProvider = new Mock<IServiceProvider>(MockBehavior.Loose).Object;

public static readonly IArtifactRegistryProvider RegistryProvider = new DefaultArtifactRegistryProvider(EmptyServiceProvider, FileResolver, FileSystem, ClientFactory, TemplateSpecRepositoryFactory, FeatureProviderFactory, BuiltInOnlyConfigurationManager);
public static IArtifactRegistryProvider CreateRegistryProvider(IServiceProvider services) =>
new DefaultArtifactRegistryProvider(services, FileResolver, FileSystem, ClientFactory, TemplateSpecRepositoryFactory, FeatureProviderFactory, BuiltInOnlyConfigurationManager);

public static readonly IModuleDispatcher ModuleDispatcher = new ModuleDispatcher(RegistryProvider, IConfigurationManager.WithStaticConfiguration(BuiltInConfiguration));
public static IModuleDispatcher CreateModuleDispatcher(IServiceProvider services) =>
new ModuleDispatcher(CreateRegistryProvider(services), IConfigurationManager.WithStaticConfiguration(BuiltInConfiguration));

public static readonly NamespaceResolver DefaultNamespaceResolver = NamespaceResolver.Create([
new("az", AzNamespaceType.Create("az", ResourceScope.ResourceGroup, AzNamespaceType.BuiltInTypeProvider, BicepSourceFileKind.BicepFile), null),
Expand Down
3 changes: 2 additions & 1 deletion src/Bicep.Core.UnitTests/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static IServiceCollection AddBicepCore(this IServiceCollection services)
.AddPublicRegistryModuleMetadataProviderServices()
.AddSingleton<BicepCompiler>();

services.AddPublicRegistryModuleMetadataProviderServices();
AddMockHttpClient(services, PublicRegistryModuleMetadataClientMock.Create([]));

return services;
Expand Down Expand Up @@ -152,7 +153,7 @@ public static IServiceCollection AddMockHttpClientIfNonNull<TClient>(IServiceCol
{
if (httpClient is { })
{
services.AddHttpClient("MockPublicRegistryModuleMetadataClient", httpClient =>
services.AddHttpClient("MockPublicRegistryModuleMetadataClient"/*asdfg?*/, httpClient =>
{
})
.AddTypedClient(c => httpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Bicep.Core.UnitTests.Mock;

public static class PublicRegistryModuleMetadataClientMock
{
// CONSIDER: Mock the HttpClient rather than the typed client
// CONSIDER: Mock HttpClient rather than the typed client

public static Mock<IPublicRegistryModuleMetadataClient> Create(IEnumerable<BicepModuleMetadata> metadata)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System.IO.Abstractions;
using Azure.Deployments.Core.Definitions;
using Azure.Deployments.Extensibility.Messages;
using Bicep.Core.Configuration;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Registry;
using Bicep.Core.UnitTests;
using Bicep.Core.UnitTests.Assertions;
using Bicep.Core.UnitTests.Features;
Expand Down Expand Up @@ -127,7 +131,8 @@ param coords {
return Task.FromResult<ExtensibilityOperationResponse>(new(req.Resource, null, null));
});

await using LocalExtensibilityHandler extensibilityHandler = new(BicepTestConstants.ModuleDispatcher, uri => Task.FromResult(providerMock.Object));
var dispatcher = BicepTestConstants.CreateModuleDispatcher(services.Build().Construct<IServiceProvider>());
await using LocalExtensibilityHandler extensibilityHandler = new(dispatcher, uri => Task.FromResult(providerMock.Object));
await extensibilityHandler.InitializeProviders(result.Compilation);

var localDeployResult = await LocalDeployment.Deploy(extensibilityHandler, templateFile, parametersFile, TestContext.CancellationTokenSource.Token);
Expand Down

0 comments on commit a1a1636

Please sign in to comment.