forked from bUnit-dev/bUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: strong name signing of assemblies. closes bUnit-dev#316
- Loading branch information
Showing
11 changed files
with
190 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Core.Tests")] | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Core.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.TestComponents.Tests")] | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.TestComponents.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.Tests")] | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# LEGAL NOTICE | ||
|
||
The files in this folder has been copied from https://github.com/trbenning/serilog-sinks-xunit, | ||
since the project does not use strong name signing. |
41 changes: 41 additions & 0 deletions
41
tests/bunit.testassets/Serilog.Sinks.XUnit/TestOutputSink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.IO; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using Serilog.Formatting; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Serilog.Sinks.XUnit | ||
{ | ||
internal class TestOutputSink : ILogEventSink | ||
{ | ||
private readonly IMessageSink messageSink; | ||
private readonly ITestOutputHelper testOutputHelper; | ||
private readonly ITextFormatter textFormatter; | ||
|
||
public TestOutputSink(IMessageSink messageSink, ITextFormatter textFormatter) | ||
{ | ||
this.messageSink = messageSink ?? throw new ArgumentNullException(nameof(messageSink)); | ||
this.textFormatter = textFormatter ?? throw new ArgumentNullException(nameof(textFormatter)); | ||
} | ||
|
||
public TestOutputSink(ITestOutputHelper testOutputHelper, ITextFormatter textFormatter) | ||
{ | ||
this.testOutputHelper = testOutputHelper ?? throw new ArgumentNullException(nameof(testOutputHelper)); | ||
this.textFormatter = textFormatter ?? throw new ArgumentNullException(nameof(textFormatter)); | ||
} | ||
|
||
public void Emit(LogEvent logEvent) | ||
{ | ||
if (logEvent == null) | ||
throw new ArgumentNullException(nameof(logEvent)); | ||
|
||
using var renderSpace = new StringWriter(); | ||
textFormatter.Format(logEvent, renderSpace); | ||
var message = renderSpace.ToString().Trim(); | ||
messageSink?.OnMessage(new DiagnosticMessage(message)); | ||
testOutputHelper?.WriteLine(message); | ||
} | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
tests/bunit.testassets/Serilog.Sinks.XUnit/XUnitLoggerConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using Serilog.Configuration; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using Serilog.Formatting; | ||
using Serilog.Formatting.Display; | ||
using Serilog.Sinks.XUnit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Serilog | ||
{ | ||
/// <summary> | ||
/// Adds the WriteTo.TestOutput() extension method to <see cref="LoggerConfiguration"/>. | ||
/// </summary> | ||
public static class TestOutputLoggerConfigurationExtensions | ||
{ | ||
internal const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"; | ||
|
||
/// <summary> | ||
/// Writes log events to <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
/// <param name="sinkConfiguration">Logger sink configuration.</param> | ||
/// <param name="messageSink">The <see cref="IMessageSink"/> that will be written to.</param> | ||
/// <param name="restrictedToMinimumLevel">The minimum level for | ||
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> | ||
/// <param name="outputTemplate">A message template describing the format used to write to the sink. | ||
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param> | ||
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> | ||
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param> | ||
/// <returns>Configuration object allowing method chaining.</returns> | ||
public static LoggerConfiguration TestOutput( | ||
this LoggerSinkConfiguration sinkConfiguration, | ||
IMessageSink messageSink, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = DefaultConsoleOutputTemplate, | ||
IFormatProvider formatProvider = null, | ||
LoggingLevelSwitch levelSwitch = null) | ||
{ | ||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException(nameof(sinkConfiguration)); | ||
if (messageSink == null) | ||
throw new ArgumentNullException(nameof(messageSink)); | ||
|
||
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); | ||
|
||
return sinkConfiguration.Sink(new TestOutputSink(messageSink, formatter), restrictedToMinimumLevel, levelSwitch); | ||
} | ||
|
||
/// <summary> | ||
/// Writes log events to <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
/// <param name="sinkConfiguration">Logger sink configuration.</param> | ||
/// <param name="messageSink">The <see cref="IMessageSink"/> that will be written to.</param> | ||
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To | ||
/// control plain text formatting, use the overload that accepts an output template.</param> | ||
/// <param name="restrictedToMinimumLevel">The minimum level for | ||
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> | ||
/// <param name="levelSwitch">A switch allowing the pass-through minimum level | ||
/// to be changed at runtime.</param> | ||
/// <returns>Configuration object allowing method chaining.</returns> | ||
public static LoggerConfiguration TestOutput( | ||
this LoggerSinkConfiguration sinkConfiguration, | ||
IMessageSink messageSink, | ||
ITextFormatter formatter, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
LoggingLevelSwitch levelSwitch = null) | ||
{ | ||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException(nameof(sinkConfiguration)); | ||
if (formatter == null) | ||
throw new ArgumentNullException(nameof(formatter)); | ||
|
||
return sinkConfiguration.Sink(new TestOutputSink(messageSink, formatter), restrictedToMinimumLevel, levelSwitch); | ||
} | ||
|
||
/// <summary> | ||
/// Writes log events to <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
/// <param name="sinkConfiguration">Logger sink configuration.</param> | ||
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper"/> that will be written to.</param> | ||
/// <param name="restrictedToMinimumLevel">The minimum level for | ||
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> | ||
/// <param name="outputTemplate">A message template describing the format used to write to the sink. | ||
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param> | ||
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> | ||
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param> | ||
/// <returns>Configuration object allowing method chaining.</returns> | ||
public static LoggerConfiguration TestOutput( | ||
this LoggerSinkConfiguration sinkConfiguration, | ||
ITestOutputHelper testOutputHelper, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
string outputTemplate = DefaultConsoleOutputTemplate, | ||
IFormatProvider formatProvider = null, | ||
LoggingLevelSwitch levelSwitch = null) | ||
{ | ||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException(nameof(sinkConfiguration)); | ||
if (testOutputHelper == null) | ||
throw new ArgumentNullException(nameof(testOutputHelper)); | ||
|
||
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); | ||
|
||
return sinkConfiguration.Sink(new TestOutputSink(testOutputHelper, formatter), restrictedToMinimumLevel, levelSwitch); | ||
} | ||
|
||
/// <summary> | ||
/// Writes log events to <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
/// <param name="sinkConfiguration">Logger sink configuration.</param> | ||
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper"/> that will be written to.</param> | ||
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To | ||
/// control plain text formatting, use the overload that accepts an output template.</param> | ||
/// <param name="restrictedToMinimumLevel">The minimum level for | ||
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> | ||
/// <param name="levelSwitch">A switch allowing the pass-through minimum level | ||
/// to be changed at runtime.</param> | ||
/// <returns>Configuration object allowing method chaining.</returns> | ||
public static LoggerConfiguration TestOutput( | ||
this LoggerSinkConfiguration sinkConfiguration, | ||
ITestOutputHelper testOutputHelper, | ||
ITextFormatter formatter, | ||
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, | ||
LoggingLevelSwitch levelSwitch = null) | ||
{ | ||
if (sinkConfiguration == null) | ||
throw new ArgumentNullException(nameof(sinkConfiguration)); | ||
if (formatter == null) | ||
throw new ArgumentNullException(nameof(formatter)); | ||
|
||
return sinkConfiguration.Sink(new TestOutputSink(testOutputHelper, formatter), restrictedToMinimumLevel, levelSwitch); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters