Skip to content

Commit 4cd2109

Browse files
committed
feat: strong name signing of assemblies. closes #316
1 parent 182b325 commit 4cd2109

11 files changed

Lines changed: 190 additions & 10 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<!-- Used by code coverage -->
2323
<DebugType>full</DebugType>
2424
<DebugSymbols>true</DebugSymbols>
25+
<SignAssembly>true</SignAssembly>
26+
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
2527
</PropertyGroup>
2628

2729
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netcoreapp3.1'">

key.snk

596 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Core.Tests")]
1+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Core.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.TestComponents.Tests")]
1+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.TestComponents.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")]

src/bunit.web.testcomponents/bunit.web.testcomponents.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NOTE: This package represents experimental features of bUnit that has been super
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="SourceFileFinder" Version="1.0.1" />
22+
<PackageReference Include="SourceFileFinder" Version="1.1.0" />
2323
<PackageReference Include="System.Reflection.Metadata" Version="$(DotNet5Version)" />
2424
<PackageReference Include="xunit.assert" Version="2.4.1" />
2525
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.Tests")]
1+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bunit.Web.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010001be6b1a2ca57b09b7040e2ab0993e515296ae22aef4031a4fe388a1336fe21f69c7e8610e9935de6ed18d94b5c98429f99ef62ce3d0af28a7088f856239368ea808ad4c448aa2a8075ed581f989f36ed0d0b8b1cfcaf1ff6a4506c8a99b7024b6eb56996d08e3c9c1cf5db59bff96fcc63ccad155ef7fc63aab6a69862437b6")]

src/bunit.web/bunit.web.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="AngleSharp" Version="0.14.0" />
19-
<PackageReference Include="AngleSharp.Css" Version="0.14.2" />
20-
<PackageReference Include="AngleSharp.Diffing" Version="0.14.0" />
21-
<PackageReference Include="AngleSharp.Wrappers" Version="1.2.0" />
18+
<PackageReference Include="AngleSharp" Version="0.15.0" />
19+
<PackageReference Include="AngleSharp.Css" Version="0.15.0" />
20+
<PackageReference Include="AngleSharp.Diffing" Version="0.15.0" />
21+
<PackageReference Include="AngleSharp.Wrappers" Version="1.3.0" />
2222
</ItemGroup>
2323

2424
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LEGAL NOTICE
2+
3+
The files in this folder has been copied from https://github.com/trbenning/serilog-sinks-xunit,
4+
since the project does not use strong name signing.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.IO;
3+
using Serilog.Core;
4+
using Serilog.Events;
5+
using Serilog.Formatting;
6+
using Xunit.Abstractions;
7+
using Xunit.Sdk;
8+
9+
namespace Serilog.Sinks.XUnit
10+
{
11+
internal class TestOutputSink : ILogEventSink
12+
{
13+
private readonly IMessageSink messageSink;
14+
private readonly ITestOutputHelper testOutputHelper;
15+
private readonly ITextFormatter textFormatter;
16+
17+
public TestOutputSink(IMessageSink messageSink, ITextFormatter textFormatter)
18+
{
19+
this.messageSink = messageSink ?? throw new ArgumentNullException(nameof(messageSink));
20+
this.textFormatter = textFormatter ?? throw new ArgumentNullException(nameof(textFormatter));
21+
}
22+
23+
public TestOutputSink(ITestOutputHelper testOutputHelper, ITextFormatter textFormatter)
24+
{
25+
this.testOutputHelper = testOutputHelper ?? throw new ArgumentNullException(nameof(testOutputHelper));
26+
this.textFormatter = textFormatter ?? throw new ArgumentNullException(nameof(textFormatter));
27+
}
28+
29+
public void Emit(LogEvent logEvent)
30+
{
31+
if (logEvent == null)
32+
throw new ArgumentNullException(nameof(logEvent));
33+
34+
using var renderSpace = new StringWriter();
35+
textFormatter.Format(logEvent, renderSpace);
36+
var message = renderSpace.ToString().Trim();
37+
messageSink?.OnMessage(new DiagnosticMessage(message));
38+
testOutputHelper?.WriteLine(message);
39+
}
40+
}
41+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using Serilog.Configuration;
3+
using Serilog.Core;
4+
using Serilog.Events;
5+
using Serilog.Formatting;
6+
using Serilog.Formatting.Display;
7+
using Serilog.Sinks.XUnit;
8+
using Xunit.Abstractions;
9+
10+
namespace Serilog
11+
{
12+
/// <summary>
13+
/// Adds the WriteTo.TestOutput() extension method to <see cref="LoggerConfiguration"/>.
14+
/// </summary>
15+
public static class TestOutputLoggerConfigurationExtensions
16+
{
17+
internal const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}";
18+
19+
/// <summary>
20+
/// Writes log events to <see cref="ITestOutputHelper"/>.
21+
/// </summary>
22+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
23+
/// <param name="messageSink">The <see cref="IMessageSink"/> that will be written to.</param>
24+
/// <param name="restrictedToMinimumLevel">The minimum level for
25+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
26+
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
27+
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
28+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
29+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
30+
/// <returns>Configuration object allowing method chaining.</returns>
31+
public static LoggerConfiguration TestOutput(
32+
this LoggerSinkConfiguration sinkConfiguration,
33+
IMessageSink messageSink,
34+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
35+
string outputTemplate = DefaultConsoleOutputTemplate,
36+
IFormatProvider formatProvider = null,
37+
LoggingLevelSwitch levelSwitch = null)
38+
{
39+
if (sinkConfiguration == null)
40+
throw new ArgumentNullException(nameof(sinkConfiguration));
41+
if (messageSink == null)
42+
throw new ArgumentNullException(nameof(messageSink));
43+
44+
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
45+
46+
return sinkConfiguration.Sink(new TestOutputSink(messageSink, formatter), restrictedToMinimumLevel, levelSwitch);
47+
}
48+
49+
/// <summary>
50+
/// Writes log events to <see cref="ITestOutputHelper"/>.
51+
/// </summary>
52+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
53+
/// <param name="messageSink">The <see cref="IMessageSink"/> that will be written to.</param>
54+
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
55+
/// control plain text formatting, use the overload that accepts an output template.</param>
56+
/// <param name="restrictedToMinimumLevel">The minimum level for
57+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
58+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
59+
/// to be changed at runtime.</param>
60+
/// <returns>Configuration object allowing method chaining.</returns>
61+
public static LoggerConfiguration TestOutput(
62+
this LoggerSinkConfiguration sinkConfiguration,
63+
IMessageSink messageSink,
64+
ITextFormatter formatter,
65+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
66+
LoggingLevelSwitch levelSwitch = null)
67+
{
68+
if (sinkConfiguration == null)
69+
throw new ArgumentNullException(nameof(sinkConfiguration));
70+
if (formatter == null)
71+
throw new ArgumentNullException(nameof(formatter));
72+
73+
return sinkConfiguration.Sink(new TestOutputSink(messageSink, formatter), restrictedToMinimumLevel, levelSwitch);
74+
}
75+
76+
/// <summary>
77+
/// Writes log events to <see cref="ITestOutputHelper"/>.
78+
/// </summary>
79+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
80+
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper"/> that will be written to.</param>
81+
/// <param name="restrictedToMinimumLevel">The minimum level for
82+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
83+
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
84+
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
85+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
86+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
87+
/// <returns>Configuration object allowing method chaining.</returns>
88+
public static LoggerConfiguration TestOutput(
89+
this LoggerSinkConfiguration sinkConfiguration,
90+
ITestOutputHelper testOutputHelper,
91+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
92+
string outputTemplate = DefaultConsoleOutputTemplate,
93+
IFormatProvider formatProvider = null,
94+
LoggingLevelSwitch levelSwitch = null)
95+
{
96+
if (sinkConfiguration == null)
97+
throw new ArgumentNullException(nameof(sinkConfiguration));
98+
if (testOutputHelper == null)
99+
throw new ArgumentNullException(nameof(testOutputHelper));
100+
101+
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
102+
103+
return sinkConfiguration.Sink(new TestOutputSink(testOutputHelper, formatter), restrictedToMinimumLevel, levelSwitch);
104+
}
105+
106+
/// <summary>
107+
/// Writes log events to <see cref="ITestOutputHelper"/>.
108+
/// </summary>
109+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
110+
/// <param name="testOutputHelper">The <see cref="ITestOutputHelper"/> that will be written to.</param>
111+
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
112+
/// control plain text formatting, use the overload that accepts an output template.</param>
113+
/// <param name="restrictedToMinimumLevel">The minimum level for
114+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
115+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
116+
/// to be changed at runtime.</param>
117+
/// <returns>Configuration object allowing method chaining.</returns>
118+
public static LoggerConfiguration TestOutput(
119+
this LoggerSinkConfiguration sinkConfiguration,
120+
ITestOutputHelper testOutputHelper,
121+
ITextFormatter formatter,
122+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
123+
LoggingLevelSwitch levelSwitch = null)
124+
{
125+
if (sinkConfiguration == null)
126+
throw new ArgumentNullException(nameof(sinkConfiguration));
127+
if (formatter == null)
128+
throw new ArgumentNullException(nameof(formatter));
129+
130+
return sinkConfiguration.Sink(new TestOutputSink(testOutputHelper, formatter), restrictedToMinimumLevel, levelSwitch);
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)