diff --git a/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests.cs b/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests.cs index 59533fb6..6c712e45 100644 --- a/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests.cs +++ b/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests.cs @@ -10,6 +10,7 @@ namespace Microsoft.Extensions.DependencyInjection.Test using System.Reflection; using Logging; using Microsoft.ApplicationInsights; + using Microsoft.ApplicationInsights.AspNetCore.DiagnosticListeners; using Microsoft.ApplicationInsights.AspNetCore.Extensions; using Microsoft.ApplicationInsights.AspNetCore.Logging; using Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers; @@ -565,6 +566,44 @@ public static void FallbacktoDefaultChannelWhenNoChannelFoundInDI() Assert.Equal(typeof(InMemoryChannel), telemetryConfiguration.TelemetryChannel.GetType()); } + + [Fact] + public static void VerifyTelemetryInitializerNoExceptionWhenAppIdProviderNotFoundFoundInDI() + { + // ARRANGE + var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor(); + var config = new ConfigurationBuilder().AddApplicationInsightsSettings(endpointAddress: "http://localhost:1234/v2/track/").Build(); + services.AddApplicationInsightsTelemetry(config); + + services.AddSingleton(); + + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + var operationCorrelationTelemetryInitializer = serviceProvider.GetService(); + + // SHOULD CALL ONINITIALIZE TELEMETRY + Assert.Equal(typeof(ApplicationInsights.AspNetCore.TelemetryInitializers.OperationCorrelationTelemetryInitializer), operationCorrelationTelemetryInitializer.GetType()); + } + + + [Fact] + public static void VerifyDiagnosticListenerNoExceptionWhenAppIdProviderNotFoundFoundInDI() + { + // ARRANGE + var services = ApplicationInsightsExtensionsTests.GetServiceCollectionWithContextAccessor(); + var config = new ConfigurationBuilder().AddApplicationInsightsSettings(endpointAddress: "http://localhost:1234/v2/track/").Build(); + services.AddApplicationInsightsTelemetry(config); + + services.AddSingleton(); + + + IServiceProvider serviceProvider = services.BuildServiceProvider(); + var hostingDiagnosticListener = serviceProvider.GetService(); + + // SHOULD CALL SetAppIdInResponseHeader + Assert.Equal(typeof(HostingDiagnosticListener), hostingDiagnosticListener.GetType()); + } + [Fact] public static void AddsQuickPulseProcessorToTheConfigurationByDefault() {