Skip to content

Commit

Permalink
test: add unit test for remove micro app insights extension (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Jul 14, 2022
1 parent 268efd2 commit 2c24ca0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.Logging;

namespace Arcus.Observability.Tests.Unit.Telemetry.AzureFunctions.Fixture
{
/// <summary>
/// Represents a dummy class with the expected name to be removed by the <see cref="ILoggingBuilderExtensions.RemoveMicrosoftApplicationInsightsLoggerProvider"/>.
/// </summary>
public class ApplicationInsightsLoggerProvider
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Arcus.Observability.Tests.Unit.Telemetry.AzureFunctions.Fixture;
using System;
using Arcus.Observability.Tests.Unit.Telemetry.AzureFunctions.Fixture;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Moq;
Expand All @@ -7,6 +8,7 @@

namespace Arcus.Observability.Tests.Unit.Telemetry.AzureFunctions
{
// ReSharper disable once InconsistentNaming
public class ILoggerBuilderExtensionsTests
{
[Fact]
Expand All @@ -28,5 +30,31 @@ public void ClearProvidersExceptFunctions_WithLoggerBuilderContainingProviders_R
Assert.Equal(2, services.Count);
Assert.All(services, desc => Assert.NotEqual(typeof(TestLoggerProvider), desc.ImplementationType));
}

[Fact]
public void RemoveMicrosoftApplicationInsightsLoggerProvider_WithLoggerBuilderContainingProvider_RemovesProvider()
{
// Arrange
var services = new ServiceCollection();
services.AddSingleton<ApplicationInsightsLoggerProvider>();

// Act
services.AddLogging(logging => logging.RemoveMicrosoftApplicationInsightsLoggerProvider());

// Assert
Assert.NotEmpty(services);
Assert.All(services, desc => Assert.NotEqual(typeof(ApplicationInsightsLoggerProvider), desc.ImplementationType));
}

[Fact]
public void RemoveMicrosoftApplicationInsightsLoggerProvider_WithoutExpectedLoggerProvider_Fails()
{
// Arrange
var services = new ServiceCollection();

// Act / Assert
Assert.ThrowsAny<InvalidOperationException>(() =>
services.AddLogging(logging => logging.RemoveMicrosoftApplicationInsightsLoggerProvider()));
}
}
}

0 comments on commit 2c24ca0

Please sign in to comment.