From fd1cdc846244443836d0cbae0e7ce12fafbfd361 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Thu, 12 Apr 2018 15:33:25 -0700 Subject: [PATCH] added tests --- .../ApplicationInsightsExtensionsTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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() {