Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym committed May 3, 2017
1 parent 3d3c311 commit 4dc70d9
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Microsoft.Extensions.DependencyInjection.Test
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Logging;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.AspNetCore.Logging;
using Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers;
using Microsoft.ApplicationInsights.AspNetCore.Tests;
using Microsoft.ApplicationInsights.Channel;
Expand Down Expand Up @@ -446,6 +448,38 @@ private static int GetTelemetryProcessorsCountInConfiguration<T>(TelemetryConfig
{
return telemetryConfiguration.TelemetryProcessors.Where(processor => processor.GetType() == typeof(T)).Count();
}

[Fact]
public static void LoggerCallbackIsInvoked()
{
var services = new ServiceCollection();
services.AddSingleton<ApplicationInsightsLoggerEvents>();
var serviceProvider = services.BuildServiceProvider();

var loggerProvider = new MockLoggingFactory();

bool firstLoggerCallback = false;
bool secondLoggerCallback = false;

loggerProvider.AddApplicationInsights(serviceProvider, (s, level) => true, () => firstLoggerCallback = true);
loggerProvider.AddApplicationInsights(serviceProvider, (s, level) => true, () => secondLoggerCallback = true);

Assert.True(firstLoggerCallback);
Assert.False(secondLoggerCallback);
}

[Fact]
public static void NullLoggerCallbackAlowed()
{
var services = new ServiceCollection();
services.AddSingleton<ApplicationInsightsLoggerEvents>();
var serviceProvider = services.BuildServiceProvider();

var loggerProvider = new MockLoggingFactory();

loggerProvider.AddApplicationInsights(serviceProvider, (s, level) => true, null);
loggerProvider.AddApplicationInsights(serviceProvider, (s, level) => true, null);
}
}

public static class AddApplicationInsightsSettings
Expand Down Expand Up @@ -521,5 +555,21 @@ public static ServiceCollection CreateServicesAndAddApplicationinsightsTelemetry
}
return services;
}

private class MockLoggingFactory : ILoggerFactory
{
public void Dispose()
{
}

public ILogger CreateLogger(string categoryName)
{
return null;
}

public void AddProvider(ILoggerProvider provider)
{
}
}
}
}

0 comments on commit 4dc70d9

Please sign in to comment.