-
Notifications
You must be signed in to change notification settings - Fork 244
Implement file logging with default xunit tests #798
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
<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> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to cross-target to enable test discovery on full framework. |
||
<NoWarn>$(NoWarn);CS1591</NoWarn> | ||
<PackageTags>$(PackageTags);testing</PackageTags> | ||
<EnableApiCheck>false</EnableApiCheck> | ||
|
@@ -14,11 +14,16 @@ | |
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(MicrosoftAspNetCoreTestingPackageVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" /> | ||
<PackageReference Include="xunit.abstractions" Version="$(XunitAbstractionsPackageVersion)" /> | ||
<PackageReference Include="xunit.extensibility.execution" Version="$(XunitExtensibilityExecutionPackageVersion)" /> | ||
<PackageReference Include="xunit.assert" Version="$(XunitAssertPackageVersion)" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="$(SerilogExtensionsLoggingPackageVersion)" /> | ||
<PackageReference Include="Serilog.Sinks.File" Version="$(SerilogSinksFilePackageVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="build\**\*.props" PackagePath="%(Identity)" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Microsoft.Extensions.Logging.Testing.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.Extensions.Logging.Testing | ||
{ | ||
public class TestLoggerProvider : ILoggerProvider | ||
{ | ||
private readonly ITestSink _sink; | ||
|
||
public TestLoggerProvider(ITestSink sink) | ||
{ | ||
_sink = sink; | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return new TestLogger(categoryName, _sink, enabled: true); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Extensions.Logging.Testing | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
public class LogLevelAttribute : Attribute | ||
{ | ||
public LogLevelAttribute(LogLevel logLevel) | ||
{ | ||
LogLevel = logLevel; | ||
} | ||
|
||
public LogLevel LogLevel { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Testing.xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.Extensions.Logging.Testing | ||
{ | ||
public class LoggedConditionalFactDiscoverer : LoggedFactDiscoverer | ||
{ | ||
private readonly IMessageSink _diagnosticMessageSink; | ||
|
||
public LoggedConditionalFactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) | ||
{ | ||
_diagnosticMessageSink = diagnosticMessageSink; | ||
} | ||
|
||
protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) | ||
{ | ||
var skipReason = testMethod.EvaluateSkipConditions(); | ||
return skipReason != null | ||
? new SkippedTestCase(skipReason, _diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) | ||
: base.CreateTestCase(discoveryOptions, testMethod, factAttribute); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Testing.xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.Extensions.Logging.Testing | ||
{ | ||
public class LoggedConditionalTheoryDiscoverer : LoggedTheoryDiscoverer | ||
{ | ||
public LoggedConditionalTheoryDiscoverer(IMessageSink diagnosticMessageSink) | ||
: base(diagnosticMessageSink) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory( | ||
ITestFrameworkDiscoveryOptions discoveryOptions, | ||
ITestMethod testMethod, | ||
IAttributeInfo theoryAttribute) | ||
{ | ||
var skipReason = testMethod.EvaluateSkipConditions(); | ||
return skipReason != null | ||
? new[] { new SkippedTestCase(skipReason, DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) } | ||
: base.CreateTestCasesForTheory(discoveryOptions, testMethod, theoryAttribute); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the base class not call EvaluateSkipConditions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not LoggedTheoryDiscoverer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But isn't that what you're replacing? If this didn't need to call EvaluateSkipConditions before, why now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I'm replacing ConditionalTheoryDiscoverer. But this inherits from LoggedTheoryDiscoverer which doesn't call EvaluateSkipConditions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't ConditionalTheoryDiscoverer have it's own LoggedTheoryDiscoverer that does exactly this then? Why not use that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I misunderstood. Could you derive from ConditionalTheoryDiscoverer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I'll still need to override these two methods to create |
||
} | ||
|
||
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow( | ||
ITestFrameworkDiscoveryOptions discoveryOptions, | ||
ITestMethod testMethod, IAttributeInfo theoryAttribute, | ||
object[] dataRow) | ||
{ | ||
var skipReason = testMethod.EvaluateSkipConditions(); | ||
return skipReason != null | ||
? base.CreateTestCasesForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow, skipReason) | ||
: base.CreateTestCasesForDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow); | ||
} | ||
|
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a static blacklist by concatenating https://github.com/dotnet/coreclr/blob/f5ae6d14d9d49dbb9f4e97f605d2a5cceab04879/src/mscorlib/shared/System/IO/Path.Unix.cs#L13-L15 and https://github.com/dotnet/coreclr/blob/9ac41819ab05282798c498b373a5017b1c2c4e64/src/mscorlib/shared/System/IO/Path.Windows.cs#L12-L28
and added space and delete.
cc @halter73