Skip to content

Commit

Permalink
exp
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 3fa36f5 commit 0bf8494
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/Bicep.Cli.IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clie
.AddSingleton(clientFactory)
.AddSingleton(templateSpecRepositoryFactory)
.AddSingleton<IPublicRegistryModuleMetadataProvider, PublicRegistryModuleMetadataProvider>();
IServiceCollectionExtensions.AddMockHttpClientIfNonNull(services, moduleMetadataClient); //asdfg does this work?
//IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, moduleMetadataClient); //asdfg does this work?

}
).GetCompiler();
Expand Down Expand Up @@ -78,12 +78,12 @@ protected static Task<CliResult> Bicep(InvocationSettings settings, Action<IServ
}

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

services
.AddSingletonIfNonNull(settings.Environment ?? BicepTestConstants.EmptyEnvironment)
.AddSingletonIfNonNull(settings.ClientFactory)
.AddSingletonIfNonNull(settings.TemplateSpecRepositoryFactory);
.AddSingletonIfNotNull(settings.Environment ?? BicepTestConstants.EmptyEnvironment)
.AddSingletonIfNotNull(settings.ClientFactory)
.AddSingletonIfNotNull(settings.TemplateSpecRepositoryFactory);

registerAction?.Invoke(services);
}
Expand Down
22 changes: 1 addition & 21 deletions src/Bicep.Core.UnitTests/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public static IServiceCollection AddBicepCore(this IServiceCollection services)
.AddPublicRegistryModuleMetadataProviderServices()
.AddSingleton<BicepCompiler>();

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

return services;
}

Expand Down Expand Up @@ -132,7 +130,7 @@ public static IServiceCollection WithDeploymentHelper(this IServiceCollection se
public static IServiceCollection WithEmptyAzResources(this IServiceCollection services)
=> services.WithAzResources([]);

public static IServiceCollection AddSingletonIfNonNull<TService>(this IServiceCollection services, TService? instance)
public static IServiceCollection AddSingletonIfNotNull<TService>(this IServiceCollection services, TService? instance)
where TService : class
{
if (instance is not null)
Expand All @@ -142,22 +140,4 @@ public static IServiceCollection AddSingletonIfNonNull<TService>(this IServiceCo

return services;
}

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

public static IServiceCollection AddMockHttpClientIfNonNull<TClient>(IServiceCollection services, TClient? httpClient) where TClient : class
{
if (httpClient is { })
{
services.AddHttpClient(typeof(IPublicRegistryModuleMetadataClient).Name /*asdfg?*/, httpClient =>
{
})
.AddTypedClient(c => httpClient);
}

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static ICompilationProvider CreateEmptyCompilationProvider(IConfiguration
{
var helper = ServiceBuilder.Create(services => services
.AddSingleton(TestTypeHelper.CreateEmptyResourceTypeLoader())
.AddSingletonIfNonNull<IConfigurationManager>(configurationManager)
.AddSingletonIfNotNull<IConfigurationManager>(configurationManager)
.AddSingleton<BicepCompilationProvider>());

return helper.Construct<BicepCompilationProvider>();
Expand Down

0 comments on commit 0bf8494

Please sign in to comment.