Skip to content

Commit

Permalink
feat: strong name signing of assemblies. closes bUnit-dev#316
Browse files Browse the repository at this point in the history
  • Loading branch information
egil committed Apr 28, 2021
1 parent 182b325 commit 4cd2109
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<!-- Used by code coverage -->
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netcoreapp3.1'">
Expand Down
Binary file added key.snk
Binary file not shown.
2 changes: 1 addition & 1 deletion src/bunit.core/InternalsVisibleTo.cs
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")]
2 changes: 1 addition & 1 deletion src/bunit.web.testcomponents/InternalsVisibleTo.cs
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")]
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NOTE: This package represents experimental features of bUnit that has been super
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SourceFileFinder" Version="1.0.1" />
<PackageReference Include="SourceFileFinder" Version="1.1.0" />
<PackageReference Include="System.Reflection.Metadata" Version="$(DotNet5Version)" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/bunit.web/InternalsVisibleTo.cs
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")]
8 changes: 4 additions & 4 deletions src/bunit.web/bunit.web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.14.0" />
<PackageReference Include="AngleSharp.Css" Version="0.14.2" />
<PackageReference Include="AngleSharp.Diffing" Version="0.14.0" />
<PackageReference Include="AngleSharp.Wrappers" Version="1.2.0" />
<PackageReference Include="AngleSharp" Version="0.15.0" />
<PackageReference Include="AngleSharp.Css" Version="0.15.0" />
<PackageReference Include="AngleSharp.Diffing" Version="0.15.0" />
<PackageReference Include="AngleSharp.Wrappers" Version="1.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down
4 changes: 4 additions & 0 deletions tests/bunit.testassets/Serilog.Sinks.XUnit/NOTICE.md
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 tests/bunit.testassets/Serilog.Sinks.XUnit/TestOutputSink.cs
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);
}
}
}
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);
}
}
}
4 changes: 2 additions & 2 deletions tests/bunit.testassets/bunit.testassets.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
Expand All @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="2.0.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down

0 comments on commit 4cd2109

Please sign in to comment.