Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert "Add logging to tests"
This reverts commit f17ba95.
  • Loading branch information
JamesNK committed Apr 14, 2023
commit a1bf6863f546206e5d494db08e88e832368312ca
21 changes: 8 additions & 13 deletions src/Hosting/Hosting/test/HostingApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Metrics;
using Moq;
using static Microsoft.AspNetCore.Hosting.HostingApplication;

namespace Microsoft.AspNetCore.Hosting.Tests;

public class HostingApplicationTests : LoggedTest
public class HostingApplicationTests
{
[Fact]
public void Metrics()
Expand Down Expand Up @@ -214,11 +213,9 @@ public void CreateContextCreatesNewContextIfNotUsingDefaultHttpContextFactory()
hostingApplication.DisposeContext(context, null);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
[Fact]
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/35142")]
public void IHttpActivityFeatureIsPopulated(bool enableLogging)
public void IHttpActivityFeatureIsPopulated()
{
var testSource = new ActivitySource(Path.GetRandomFileName());
var dummySource = new ActivitySource(Path.GetRandomFileName());
Expand All @@ -230,8 +227,7 @@ public void IHttpActivityFeatureIsPopulated(bool enableLogging)
};
ActivitySource.AddActivityListener(listener);

var loggerFactory = enableLogging ? LoggerFactory : NullLoggerFactory.Instance;
var hostingApplication = CreateApplication(activitySource: testSource, loggerFactory: loggerFactory);
var hostingApplication = CreateApplication(activitySource: testSource);
var httpContext = new DefaultHttpContext();
var context = hostingApplication.CreateContext(httpContext.Features);

Expand Down Expand Up @@ -293,7 +289,7 @@ public void IHttpActivityFeatureNotUsedFromFeatureCollection()
[Fact]
public void IHttpActivityFeatureIsNotPopulatedWithoutAListener()
{
var hostingApplication = CreateApplication(loggerFactory: NullLoggerFactory.Instance);
var hostingApplication = CreateApplication();
var httpContext = new DefaultHttpContext();
httpContext.Features.Set<IHttpActivityFeature>(new TestHttpActivityFeature());
var context = hostingApplication.CreateContext(httpContext.Features);
Expand All @@ -306,8 +302,8 @@ public void IHttpActivityFeatureIsNotPopulatedWithoutAListener()
hostingApplication.DisposeContext(context, null);
}

private HostingApplication CreateApplication(IHttpContextFactory httpContextFactory = null, bool useHttpContextAccessor = false,
ActivitySource activitySource = null, IMeterFactory meterFactory = null, ILoggerFactory loggerFactory = null)
private static HostingApplication CreateApplication(IHttpContextFactory httpContextFactory = null, bool useHttpContextAccessor = false,
ActivitySource activitySource = null, IMeterFactory meterFactory = null)
{
var services = new ServiceCollection();
services.AddOptions();
Expand All @@ -317,11 +313,10 @@ private HostingApplication CreateApplication(IHttpContextFactory httpContextFact
}

httpContextFactory ??= new DefaultHttpContextFactory(services.BuildServiceProvider());
loggerFactory ??= LoggerFactory;

var hostingApplication = new HostingApplication(
ctx => Task.CompletedTask,
loggerFactory.CreateLogger("Microsoft.AspNetCore.Hosting.Diagnostics"),
NullLogger.Instance,
new DiagnosticListener("Microsoft.AspNetCore"),
activitySource ?? new ActivitySource("Microsoft.AspNetCore"),
DistributedContextPropagator.CreateDefaultPropagator(),
Expand Down