Relocate Logging.Testing to AspNetCore.Testing

This commit is contained in:
John Luo 2020-04-02 00:15:24 -07:00
parent 5f6fbed915
commit fcb23108b6
61 changed files with 21 additions and 113 deletions

View File

@ -152,7 +152,7 @@
$(RepoRoot)src\SiteExtensions\LoggingAggregate\test\**\*.csproj;
$(RepoRoot)src\Shared\**\*.*proj;
$(RepoRoot)src\Tools\**\*.*proj;
$(RepoRoot)src\Logging\**\src\*.csproj;
$(RepoRoot)src\Logging.AzureAppServices\**\src\*.csproj;
$(RepoRoot)src\Middleware\**\*.csproj;
$(RepoRoot)src\Razor\**\*.*proj;
$(RepoRoot)src\Mvc\**\*.*proj;
@ -192,7 +192,7 @@
$(RepoRoot)src\Security\**\src\*.csproj;
$(RepoRoot)src\SiteExtensions\**\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\Razor\**\src\*.csproj;
$(RepoRoot)src\Mvc\**\src\*.csproj;

View File

@ -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.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="Microsoft.Extensions.Logging.AzureAppServices" ProjectPath="$(RepoRoot)src\Logging\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.Extensions.Logging.AzureAppServices" ProjectPath="$(RepoRoot)src\Logging.AzureAppServices\src\Microsoft.Extensions.Logging.AzureAppServices.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.HeaderPropagation" ProjectPath="$(RepoRoot)src\Middleware\HeaderPropagation\src\Microsoft.AspNetCore.HeaderPropagation.csproj" />

View File

@ -14,8 +14,8 @@
<Reference Include="Microsoft.AspNetCore.Mvc" />
<Reference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" />
<Reference Include="Microsoft.AspNetCore.Testing" />
<Reference Include="Microsoft.Extensions.Hosting" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
</ItemGroup>
<ItemGroup>

View File

@ -23,7 +23,6 @@
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Logging.Console" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
<Reference Include="Microsoft.NETCore.Windows.ApiSets" />
<Reference Include="Serilog.Extensions.Logging" />
<Reference Include="Serilog.Sinks.File" />

View 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>

View File

@ -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>

View File

@ -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)]

View File

@ -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));
}
}
}

View File

@ -7,8 +7,8 @@
<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Servers\IIS\IntegrationTesting.IIS\src\Microsoft.AspNetCore.Server.IntegrationTesting.IIS.csproj" />
<Reference Include="Microsoft.AspNetCore.Hosting" />
<Reference Include="Microsoft.AspNetCore.Testing" />
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
<Reference Include="System.Diagnostics.EventLog" />
</ItemGroup>

View File

@ -20,7 +20,5 @@
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<None Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
</ItemGroup>
</Project>

View File

@ -21,7 +21,6 @@
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" Link="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Reference Include="Microsoft.Extensions.Logging.Testing" />
</ItemGroup>
</Project>

View File

@ -21,7 +21,6 @@
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" />
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" />
<Reference Include="Microsoft.AspNetCore.Testing" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
<!-- Avoid CS1705 errors due to mix of assemblies brought in transitively. -->
<Reference Include="Microsoft.AspNetCore.SignalR.Common" />

View File

@ -19,7 +19,9 @@
</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="Serilog.Extensions.Logging" />
<Reference Include="Serilog.Sinks.File" />

View File

@ -4,7 +4,7 @@
using System;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging.Test;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Microsoft.Extensions.Logging.Testing.Tests
@ -16,7 +16,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
{
var testTestOutputHelper = new TestTestOutputHelper();
var loggerFactory = TestLoggerBuilder.Create(builder => builder
var loggerFactory = CreateTestLogger(builder => builder
.SetMinimumLevel(LogLevel.Trace)
.AddXunit(testTestOutputHelper));
@ -35,7 +35,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
public void LoggerProviderDoesNotWriteLogMessagesBelowMinimumLevel()
{
var testTestOutputHelper = new TestTestOutputHelper();
var loggerFactory = TestLoggerBuilder.Create(builder => builder
var loggerFactory = CreateTestLogger(builder => builder
.AddXunit(testTestOutputHelper, LogLevel.Warning));
var logger = loggerFactory.CreateLogger("TestCategory");
@ -49,7 +49,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
public void LoggerProviderPrependsPrefixToEachLine()
{
var testTestOutputHelper = new TestTestOutputHelper();
var loggerFactory = TestLoggerBuilder.Create(builder => builder
var loggerFactory = CreateTestLogger(builder => builder
.AddXunit(testTestOutputHelper));
var logger = loggerFactory.CreateLogger("TestCategory");
@ -68,7 +68,7 @@ namespace Microsoft.Extensions.Logging.Testing.Tests
public void LoggerProviderDoesNotThrowIfOutputHelperThrows()
{
var testTestOutputHelper = new TestTestOutputHelper();
var loggerFactory = TestLoggerBuilder.Create(builder => builder
var loggerFactory = CreateTestLogger(builder => builder
.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 string MakeConsistent(string input) => TimestampRegex.Replace(input, "TIMESTAMP");
private static ILoggerFactory CreateTestLogger(Action<ILoggingBuilder> configure)
{
return new ServiceCollection()
.AddLogging(configure)
.BuildServiceProvider()
.GetRequiredService<ILoggerFactory>();
}
}
}