Relocate Logging.Testing to AspNetCore.Testing
This commit is contained in:
parent
5f6fbed915
commit
fcb23108b6
|
|
@ -152,7 +152,7 @@
|
||||||
$(RepoRoot)src\SiteExtensions\LoggingAggregate\test\**\*.csproj;
|
$(RepoRoot)src\SiteExtensions\LoggingAggregate\test\**\*.csproj;
|
||||||
$(RepoRoot)src\Shared\**\*.*proj;
|
$(RepoRoot)src\Shared\**\*.*proj;
|
||||||
$(RepoRoot)src\Tools\**\*.*proj;
|
$(RepoRoot)src\Tools\**\*.*proj;
|
||||||
$(RepoRoot)src\Logging\**\src\*.csproj;
|
$(RepoRoot)src\Logging.AzureAppServices\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Middleware\**\*.csproj;
|
$(RepoRoot)src\Middleware\**\*.csproj;
|
||||||
$(RepoRoot)src\Razor\**\*.*proj;
|
$(RepoRoot)src\Razor\**\*.*proj;
|
||||||
$(RepoRoot)src\Mvc\**\*.*proj;
|
$(RepoRoot)src\Mvc\**\*.*proj;
|
||||||
|
|
@ -192,7 +192,7 @@
|
||||||
$(RepoRoot)src\Security\**\src\*.csproj;
|
$(RepoRoot)src\Security\**\src\*.csproj;
|
||||||
$(RepoRoot)src\SiteExtensions\**\src\*.csproj;
|
$(RepoRoot)src\SiteExtensions\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Tools\**\src\*.csproj;
|
$(RepoRoot)src\Tools\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Logging\**\src\*.csproj;
|
$(RepoRoot)src\Logging.AzureAppServices\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Middleware\**\src\*.csproj;
|
$(RepoRoot)src\Middleware\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Razor\**\src\*.csproj;
|
$(RepoRoot)src\Razor\**\src\*.csproj;
|
||||||
$(RepoRoot)src\Mvc\**\src\*.csproj;
|
$(RepoRoot)src\Mvc\**\src\*.csproj;
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@
|
||||||
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Server" ProjectPath="$(RepoRoot)src\Tools\Extensions.ApiDescription.Server\src\Microsoft.Extensions.ApiDescription.Server.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Server" ProjectPath="$(RepoRoot)src\Tools\Extensions.ApiDescription.Server\src\Microsoft.Extensions.ApiDescription.Server.csproj" />
|
||||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" ProjectPath="$(RepoRoot)src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" ProjectPath="$(RepoRoot)src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj" />
|
||||||
<ProjectReferenceProvider Include="GetDocument.Insider" ProjectPath="$(RepoRoot)src\Tools\GetDocumentInsider\src\GetDocumentInsider.csproj" />
|
<ProjectReferenceProvider Include="GetDocument.Insider" ProjectPath="$(RepoRoot)src\Tools\GetDocumentInsider\src\GetDocumentInsider.csproj" />
|
||||||
<ProjectReferenceProvider Include="Microsoft.Extensions.Logging.AzureAppServices" ProjectPath="$(RepoRoot)src\Logging\Logging.AzureAppServices\src\Microsoft.Extensions.Logging.AzureAppServices.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.Extensions.Logging.AzureAppServices" ProjectPath="$(RepoRoot)src\Logging.AzureAppServices\src\Microsoft.Extensions.Logging.AzureAppServices.csproj" />
|
||||||
<ProjectReferenceProvider Include="Microsoft.Extensions.Logging.Testing" ProjectPath="$(RepoRoot)src\Logging\Logging.Testing\src\Microsoft.Extensions.Logging.Testing.csproj" />
|
|
||||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.ConcurrencyLimiter" ProjectPath="$(RepoRoot)src\Middleware\ConcurrencyLimiter\src\Microsoft.AspNetCore.ConcurrencyLimiter.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.AspNetCore.ConcurrencyLimiter" ProjectPath="$(RepoRoot)src\Middleware\ConcurrencyLimiter\src\Microsoft.AspNetCore.ConcurrencyLimiter.csproj" />
|
||||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" ProjectPath="$(RepoRoot)src\Middleware\Diagnostics.EntityFrameworkCore\src\Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" ProjectPath="$(RepoRoot)src\Middleware\Diagnostics.EntityFrameworkCore\src\Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.csproj" />
|
||||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HeaderPropagation" ProjectPath="$(RepoRoot)src\Middleware\HeaderPropagation\src\Microsoft.AspNetCore.HeaderPropagation.csproj" />
|
<ProjectReferenceProvider Include="Microsoft.AspNetCore.HeaderPropagation" ProjectPath="$(RepoRoot)src\Middleware\HeaderPropagation\src\Microsoft.AspNetCore.HeaderPropagation.csproj" />
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
<Reference Include="Microsoft.AspNetCore.Mvc" />
|
<Reference Include="Microsoft.AspNetCore.Mvc" />
|
||||||
<Reference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
|
<Reference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
|
||||||
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" />
|
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" />
|
||||||
|
<Reference Include="Microsoft.AspNetCore.Testing" />
|
||||||
<Reference Include="Microsoft.Extensions.Hosting" />
|
<Reference Include="Microsoft.Extensions.Hosting" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
|
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
<Reference Include="Microsoft.Extensions.Logging" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Console" />
|
<Reference Include="Microsoft.Extensions.Logging.Console" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
<Reference Include="Microsoft.NETCore.Windows.ApiSets" />
|
<Reference Include="Microsoft.NETCore.Windows.ApiSets" />
|
||||||
<Reference Include="Serilog.Extensions.Logging" />
|
<Reference Include="Serilog.Extensions.Logging" />
|
||||||
<Reference Include="Serilog.Sinks.File" />
|
<Reference Include="Serilog.Sinks.File" />
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<Description>Helpers for writing tests that use Microsoft.Extensions.Logging. Contains null implementations of the abstractions that do nothing, as well as test implementations that are observable.</Description>
|
|
||||||
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
|
|
||||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
|
||||||
<PackageTags>$(PackageTags);testing</PackageTags>
|
|
||||||
<!-- This is actually a library for test projects, not a test project. -->
|
|
||||||
<IsUnitTestProject>false</IsUnitTestProject>
|
|
||||||
<IsShipping>false</IsShipping>
|
|
||||||
<ExcludeFromSourceBuild>true</ExcludeFromSourceBuild>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<InternalsVisibleTo Include="Microsoft.Extensions.Logging.Testing.Tests" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Console" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
This intentionally does not reference 'xunit', 'xunit.core', or any runner packages.
|
|
||||||
XUnit recommends only using xunit.extensibility.*, xunit.assert, and xunit.abstractions for packages which "extend" xunit.
|
|
||||||
This allows consumers to decide which type of xunit runner they want to use to run these tests,
|
|
||||||
and avoids problems with `dotnet pack`.
|
|
||||||
|
|
||||||
See https://xunit.github.io/docs/nuget-packages and the special note in https://xunit.github.io/releases/2.3.
|
|
||||||
-->
|
|
||||||
<Reference Include="xunit.abstractions" />
|
|
||||||
<Reference Include="xunit.assert" />
|
|
||||||
<Reference Include="xunit.extensibility.execution" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFrameworks>$(DefaultNetCoreTargetFramework);net472</TargetFrameworks>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
|
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Primitives" />
|
|
||||||
<ProjectReference Include="../../test/Microsoft.Extensions.Logging.Tests.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
// Licensed to the .NET Foundation under one or more agreements.
|
|
||||||
// The .NET Foundation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Logging.Testing;
|
|
||||||
|
|
||||||
[assembly: LogLevel(LogLevel.Trace)]
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
// Licensed to the .NET Foundation under one or more agreements.
|
|
||||||
// The .NET Foundation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.Logging.Testing.Tests
|
|
||||||
{
|
|
||||||
public class TestTestOutputHelper : ITestOutputHelper
|
|
||||||
{
|
|
||||||
private StringBuilder _output = new StringBuilder();
|
|
||||||
|
|
||||||
public bool Throw { get; set; }
|
|
||||||
|
|
||||||
public string Output => _output.ToString();
|
|
||||||
|
|
||||||
public void WriteLine(string message)
|
|
||||||
{
|
|
||||||
if (Throw)
|
|
||||||
{
|
|
||||||
throw new Exception("Boom!");
|
|
||||||
}
|
|
||||||
_output.AppendLine(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteLine(string format, params object[] args)
|
|
||||||
{
|
|
||||||
if (Throw)
|
|
||||||
{
|
|
||||||
throw new Exception("Boom!");
|
|
||||||
}
|
|
||||||
_output.AppendLine(string.Format(format, args));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="$(RepoRoot)src\Servers\IIS\IntegrationTesting.IIS\src\Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj" />
|
<ProjectReference Include="$(RepoRoot)src\Servers\IIS\IntegrationTesting.IIS\src\Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj" />
|
||||||
<Reference Include="Microsoft.AspNetCore.Hosting" />
|
<Reference Include="Microsoft.AspNetCore.Hosting" />
|
||||||
|
<Reference Include="Microsoft.AspNetCore.Testing" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
<Reference Include="Microsoft.Extensions.Logging" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
<Reference Include="System.Diagnostics.EventLog" />
|
<Reference Include="System.Diagnostics.EventLog" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,5 @@
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
|
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
|
||||||
<None Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
<None Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json">
|
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" />
|
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" />
|
||||||
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" />
|
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" />
|
||||||
<Reference Include="Microsoft.AspNetCore.Testing" />
|
<Reference Include="Microsoft.AspNetCore.Testing" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
|
||||||
<!-- Avoid CS1705 errors due to mix of assemblies brought in transitively. -->
|
<!-- Avoid CS1705 errors due to mix of assemblies brought in transitively. -->
|
||||||
<Reference Include="Microsoft.AspNetCore.SignalR.Common" />
|
<Reference Include="Microsoft.AspNetCore.SignalR.Common" />
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.Extensions.Logging.Testing" />
|
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
|
<Reference Include="Microsoft.Extensions.Logging.Console" />
|
||||||
|
<Reference Include="Microsoft.Extensions.Logging" />
|
||||||
<Reference Include="Microsoft.Win32.Registry" />
|
<Reference Include="Microsoft.Win32.Registry" />
|
||||||
<Reference Include="Serilog.Extensions.Logging" />
|
<Reference Include="Serilog.Extensions.Logging" />
|
||||||
<Reference Include="Serilog.Sinks.File" />
|
<Reference Include="Serilog.Sinks.File" />
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.Extensions.Logging.Test;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.Logging.Testing.Tests
|
namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
{
|
{
|
||||||
var testTestOutputHelper = new TestTestOutputHelper();
|
var testTestOutputHelper = new TestTestOutputHelper();
|
||||||
|
|
||||||
var loggerFactory = TestLoggerBuilder.Create(builder => builder
|
var loggerFactory = CreateTestLogger(builder => builder
|
||||||
.SetMinimumLevel(LogLevel.Trace)
|
.SetMinimumLevel(LogLevel.Trace)
|
||||||
.AddXunit(testTestOutputHelper));
|
.AddXunit(testTestOutputHelper));
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
public void LoggerProviderDoesNotWriteLogMessagesBelowMinimumLevel()
|
public void LoggerProviderDoesNotWriteLogMessagesBelowMinimumLevel()
|
||||||
{
|
{
|
||||||
var testTestOutputHelper = new TestTestOutputHelper();
|
var testTestOutputHelper = new TestTestOutputHelper();
|
||||||
var loggerFactory = TestLoggerBuilder.Create(builder => builder
|
var loggerFactory = CreateTestLogger(builder => builder
|
||||||
.AddXunit(testTestOutputHelper, LogLevel.Warning));
|
.AddXunit(testTestOutputHelper, LogLevel.Warning));
|
||||||
|
|
||||||
var logger = loggerFactory.CreateLogger("TestCategory");
|
var logger = loggerFactory.CreateLogger("TestCategory");
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
public void LoggerProviderPrependsPrefixToEachLine()
|
public void LoggerProviderPrependsPrefixToEachLine()
|
||||||
{
|
{
|
||||||
var testTestOutputHelper = new TestTestOutputHelper();
|
var testTestOutputHelper = new TestTestOutputHelper();
|
||||||
var loggerFactory = TestLoggerBuilder.Create(builder => builder
|
var loggerFactory = CreateTestLogger(builder => builder
|
||||||
.AddXunit(testTestOutputHelper));
|
.AddXunit(testTestOutputHelper));
|
||||||
|
|
||||||
var logger = loggerFactory.CreateLogger("TestCategory");
|
var logger = loggerFactory.CreateLogger("TestCategory");
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
public void LoggerProviderDoesNotThrowIfOutputHelperThrows()
|
public void LoggerProviderDoesNotThrowIfOutputHelperThrows()
|
||||||
{
|
{
|
||||||
var testTestOutputHelper = new TestTestOutputHelper();
|
var testTestOutputHelper = new TestTestOutputHelper();
|
||||||
var loggerFactory = TestLoggerBuilder.Create(builder => builder
|
var loggerFactory = CreateTestLogger(builder => builder
|
||||||
|
|
||||||
.AddXunit(testTestOutputHelper));
|
.AddXunit(testTestOutputHelper));
|
||||||
|
|
||||||
|
|
@ -83,5 +83,13 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
|
||||||
private static readonly Regex TimestampRegex = new Regex(@"\d+-\d+-\d+T\d+:\d+:\d+");
|
private static readonly Regex TimestampRegex = new Regex(@"\d+-\d+-\d+T\d+:\d+:\d+");
|
||||||
|
|
||||||
private string MakeConsistent(string input) => TimestampRegex.Replace(input, "TIMESTAMP");
|
private string MakeConsistent(string input) => TimestampRegex.Replace(input, "TIMESTAMP");
|
||||||
|
|
||||||
|
private static ILoggerFactory CreateTestLogger(Action<ILoggingBuilder> configure)
|
||||||
|
{
|
||||||
|
return new ServiceCollection()
|
||||||
|
.AddLogging(configure)
|
||||||
|
.BuildServiceProvider()
|
||||||
|
.GetRequiredService<ILoggerFactory>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue