Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Weatherford authored and Stephen Weatherford committed Jun 13, 2024
1 parent 0bf8494 commit 8716dbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Bicep.Cli.IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clie
.AddSingleton(clientFactory)
.AddSingleton(templateSpecRepositoryFactory)
.AddSingleton<IPublicRegistryModuleMetadataProvider, PublicRegistryModuleMetadataProvider>();
//IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, moduleMetadataClient); //asdfg does this work?

IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, moduleMetadataClient);
}
).GetCompiler();

Expand Down Expand Up @@ -61,7 +61,6 @@ public InvocationSettings(
this.TemplateSpecRepositoryFactory = TemplateSpecRepositoryFactory ?? Repository.Create<ITemplateSpecRepositoryFactory>().Object;
this.Environment = Environment;

// This keeps PublicRegistryModuleMetadataProvider from going to the web during CLI integration tests
this.ModuleMetadataClient = ModuleMetadataClient ?? StrictMock.Of<IPublicRegistryModuleMetadataClient>().Object;
}
}
Expand All @@ -77,8 +76,7 @@ protected static Task<CliResult> Bicep(InvocationSettings settings, Action<IServ
services.WithFeatureOverrides(settings.FeatureOverrides);
}

//asdfg does this work?
//IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, settings.ModuleMetadataClient);
IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, settings.ModuleMetadataClient);

services
.AddSingletonIfNotNull(settings.Environment ?? BicepTestConstants.EmptyEnvironment)
Expand Down
25 changes: 25 additions & 0 deletions src/Bicep.Core.UnitTests/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static IServiceCollection AddBicepCore(this IServiceCollection services)
.AddPublicRegistryModuleMetadataProviderServices()
.AddSingleton<BicepCompiler>();

//AddMockHttpClient(services, PublicRegistryModuleMetadataClientMock.Create([]).Object);//asdfg not working?

return services;
}

Expand Down Expand Up @@ -140,4 +142,27 @@ public static IServiceCollection AddSingletonIfNotNull<TService>(this IServiceCo

return services;
}

public static IServiceCollection AddMockHttpClient<TClient>(IServiceCollection services, TClient? httpClient) where TClient : class
{
return AddMockHttpClientIfNotNull(services, httpClient);
}

public static IServiceCollection AddMockHttpClientIfNotNull<TClient>(IServiceCollection services, TClient? httpClient) where TClient : class //asdfg rename
{
if (!typeof(TClient).IsInterface)
{
throw new ArgumentException($"TClient must be an interface type, found: {typeof(TClient).FullName}");
}

if (httpClient is { })
{
services.AddHttpClient(typeof(TClient).FullName!, httpClient =>
{
})
.AddTypedClient(c => httpClient);
}

return services;
}
}

0 comments on commit 8716dbc

Please sign in to comment.