Skip to content

Commit d80be5a

Browse files
committed
Build.ps1 (based on Serilog's), including XUnit testing.
1 parent c72d9e1 commit d80be5a

File tree

4 files changed

+1006
-113
lines changed

4 files changed

+1006
-113
lines changed

Build.ps1

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
function Install-Dnvm
2+
{
3+
& where.exe dnvm 2>&1 | Out-Null
4+
if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true))
5+
{
6+
Write-Host "DNVM not found"
7+
&{$Branch='dev';iex ((New-Object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
8+
9+
# Normally this happens automatically during install but AppVeyor has
10+
# an issue where you may need to manually re-run setup from within this process.
11+
if($env:DNX_HOME -eq $NULL)
12+
{
13+
Write-Host "Initial DNVM environment setup failed; running manual setup"
14+
$tempDnvmPath = Join-Path $env:TEMP "dnvminstall"
15+
$dnvmSetupCmdPath = Join-Path $tempDnvmPath "dnvm.ps1"
16+
& $dnvmSetupCmdPath setup
17+
}
18+
}
19+
}
20+
21+
function Get-DnxVersion
22+
{
23+
$globalJson = Join-Path $PSScriptRoot "global.json"
24+
$jsonData = Get-Content -Path $globalJson -Raw | ConvertFrom-JSON
25+
return $jsonData.sdk.version
26+
}
27+
28+
function Restore-Packages
29+
{
30+
param([string] $DirectoryName)
31+
& dnu restore ("""" + $DirectoryName + """")
32+
}
33+
34+
function Build-Projects
35+
{
36+
param([string] $DirectoryName)
37+
& dnu build ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\testbin; if($LASTEXITCODE -ne 0) { exit 1 }
38+
& dnu pack ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\packages; if($LASTEXITCODE -ne 0) { exit 1 }
39+
}
40+
41+
function Build-TestProjects
42+
{
43+
param([string] $DirectoryName)
44+
& dnu build ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\testbin; if($LASTEXITCODE -ne 0) { exit 1 }
45+
}
46+
47+
function Test-Projects
48+
{
49+
param([string] $DirectoryName)
50+
& dnx -p ("""" + $DirectoryName + """") test; if($LASTEXITCODE -ne 0) { exit 2 }
51+
}
52+
53+
function Remove-PathVariable
54+
{
55+
param([string] $VariableToRemove)
56+
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
57+
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
58+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
59+
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
60+
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
61+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
62+
}
63+
64+
Push-Location $PSScriptRoot
65+
66+
$dnxVersion = Get-DnxVersion
67+
68+
# Clean
69+
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
70+
71+
# Remove the installed DNVM from the path and force use of
72+
# per-user DNVM (which we can upgrade as needed without admin permissions)
73+
Remove-PathVariable "*Program Files\Microsoft DNX\DNVM*"
74+
75+
# Make sure per-user DNVM is installed
76+
Install-Dnvm
77+
78+
# Install DNX
79+
dnvm install $dnxVersion -r CoreCLR -NoNative
80+
dnvm install $dnxVersion -r CLR -NoNative
81+
dnvm use $dnxVersion -r CLR
82+
83+
# Package restore
84+
Get-ChildItem -Path . -Filter *.xproj -Recurse | ForEach-Object { Restore-Packages $_.DirectoryName }
85+
86+
# Set build number
87+
$env:DNX_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
88+
Write-Host "Build number: " $env:DNX_BUILD_VERSION
89+
90+
# Build/package
91+
Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Build-Projects $_.DirectoryName }
92+
Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Build-TestProjects $_.DirectoryName }
93+
94+
# Test
95+
Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName }
96+
97+
# Switch to Core CLR
98+
dnvm use $dnxVersion -r CoreCLR
99+
100+
# Test again
101+
Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName }
102+
103+
Pop-Location

test/Serilog.Framework.Logging.Tests/SerilogLoggerTests.cs

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
using System;
55
using Serilog.Events;
66
using Microsoft.Extensions.Logging;
7-
using NUnit.Framework;
87
using System.Collections.Generic;
98
using System.IO;
109
using Serilog.Debugging;
10+
using Xunit;
1111

1212
namespace Serilog.Framework.Logging.Test
1313
{
14-
[TestFixture]
1514
public class SerilogLoggerTest
1615
{
1716
private const string Name = "test";
@@ -61,7 +60,7 @@ private LogEventLevel MapLevel(LogLevel logLevel)
6160
}
6261
}
6362

64-
[Test]
63+
[Fact]
6564
public void LogsWhenNullFilterGiven()
6665
{
6766
var t = SetUp(LogLevel.Verbose);
@@ -70,10 +69,10 @@ public void LogsWhenNullFilterGiven()
7069

7170
logger.Log(LogLevel.Information, 0, TestMessage, null, null);
7271

73-
Assert.AreEqual(1, sink.Writes.Count);
72+
Assert.Equal(1, sink.Writes.Count);
7473
}
7574

76-
[Test]
75+
[Fact]
7776
public void LogsCorrectLevel()
7877
{
7978
var t = SetUp(LogLevel.Debug);
@@ -87,41 +86,41 @@ public void LogsCorrectLevel()
8786
logger.Log(LogLevel.Error, 0, TestMessage, null, null);
8887
logger.Log(LogLevel.Critical, 0, TestMessage, null, null);
8988

90-
Assert.AreEqual(6, sink.Writes.Count);
91-
Assert.AreEqual(LogEventLevel.Verbose, sink.Writes[0].Level);
92-
Assert.AreEqual(LogEventLevel.Debug, sink.Writes[1].Level);
93-
Assert.AreEqual(LogEventLevel.Information, sink.Writes[2].Level);
94-
Assert.AreEqual(LogEventLevel.Warning, sink.Writes[3].Level);
95-
Assert.AreEqual(LogEventLevel.Error, sink.Writes[4].Level);
96-
Assert.AreEqual(LogEventLevel.Fatal, sink.Writes[5].Level);
89+
Assert.Equal(6, sink.Writes.Count);
90+
Assert.Equal(LogEventLevel.Verbose, sink.Writes[0].Level);
91+
Assert.Equal(LogEventLevel.Debug, sink.Writes[1].Level);
92+
Assert.Equal(LogEventLevel.Information, sink.Writes[2].Level);
93+
Assert.Equal(LogEventLevel.Warning, sink.Writes[3].Level);
94+
Assert.Equal(LogEventLevel.Error, sink.Writes[4].Level);
95+
Assert.Equal(LogEventLevel.Fatal, sink.Writes[5].Level);
9796
}
9897

99-
[Test]
100-
[TestCase(LogLevel.Verbose, LogLevel.Verbose, 1)]
101-
[TestCase(LogLevel.Verbose, LogLevel.Information, 1)]
102-
[TestCase(LogLevel.Verbose, LogLevel.Warning, 1)]
103-
[TestCase(LogLevel.Verbose, LogLevel.Error, 1)]
104-
[TestCase(LogLevel.Verbose, LogLevel.Critical, 1)]
105-
[TestCase(LogLevel.Information, LogLevel.Verbose, 0)]
106-
[TestCase(LogLevel.Information, LogLevel.Information, 1)]
107-
[TestCase(LogLevel.Information, LogLevel.Warning, 1)]
108-
[TestCase(LogLevel.Information, LogLevel.Error, 1)]
109-
[TestCase(LogLevel.Information, LogLevel.Critical, 1)]
110-
[TestCase(LogLevel.Warning, LogLevel.Verbose, 0)]
111-
[TestCase(LogLevel.Warning, LogLevel.Information, 0)]
112-
[TestCase(LogLevel.Warning, LogLevel.Warning, 1)]
113-
[TestCase(LogLevel.Warning, LogLevel.Error, 1)]
114-
[TestCase(LogLevel.Warning, LogLevel.Critical, 1)]
115-
[TestCase(LogLevel.Error, LogLevel.Verbose, 0)]
116-
[TestCase(LogLevel.Error, LogLevel.Information, 0)]
117-
[TestCase(LogLevel.Error, LogLevel.Warning, 0)]
118-
[TestCase(LogLevel.Error, LogLevel.Error, 1)]
119-
[TestCase(LogLevel.Error, LogLevel.Critical, 1)]
120-
[TestCase(LogLevel.Critical, LogLevel.Verbose, 0)]
121-
[TestCase(LogLevel.Critical, LogLevel.Information, 0)]
122-
[TestCase(LogLevel.Critical, LogLevel.Warning, 0)]
123-
[TestCase(LogLevel.Critical, LogLevel.Error, 0)]
124-
[TestCase(LogLevel.Critical, LogLevel.Critical, 1)]
98+
[Theory]
99+
[InlineData(LogLevel.Verbose, LogLevel.Verbose, 1)]
100+
[InlineData(LogLevel.Verbose, LogLevel.Information, 1)]
101+
[InlineData(LogLevel.Verbose, LogLevel.Warning, 1)]
102+
[InlineData(LogLevel.Verbose, LogLevel.Error, 1)]
103+
[InlineData(LogLevel.Verbose, LogLevel.Critical, 1)]
104+
[InlineData(LogLevel.Information, LogLevel.Verbose, 0)]
105+
[InlineData(LogLevel.Information, LogLevel.Information, 1)]
106+
[InlineData(LogLevel.Information, LogLevel.Warning, 1)]
107+
[InlineData(LogLevel.Information, LogLevel.Error, 1)]
108+
[InlineData(LogLevel.Information, LogLevel.Critical, 1)]
109+
[InlineData(LogLevel.Warning, LogLevel.Verbose, 0)]
110+
[InlineData(LogLevel.Warning, LogLevel.Information, 0)]
111+
[InlineData(LogLevel.Warning, LogLevel.Warning, 1)]
112+
[InlineData(LogLevel.Warning, LogLevel.Error, 1)]
113+
[InlineData(LogLevel.Warning, LogLevel.Critical, 1)]
114+
[InlineData(LogLevel.Error, LogLevel.Verbose, 0)]
115+
[InlineData(LogLevel.Error, LogLevel.Information, 0)]
116+
[InlineData(LogLevel.Error, LogLevel.Warning, 0)]
117+
[InlineData(LogLevel.Error, LogLevel.Error, 1)]
118+
[InlineData(LogLevel.Error, LogLevel.Critical, 1)]
119+
[InlineData(LogLevel.Critical, LogLevel.Verbose, 0)]
120+
[InlineData(LogLevel.Critical, LogLevel.Information, 0)]
121+
[InlineData(LogLevel.Critical, LogLevel.Warning, 0)]
122+
[InlineData(LogLevel.Critical, LogLevel.Error, 0)]
123+
[InlineData(LogLevel.Critical, LogLevel.Critical, 1)]
125124
public void LogsWhenEnabled(LogLevel minLevel, LogLevel logLevel, int expected)
126125
{
127126
var t = SetUp(minLevel);
@@ -130,10 +129,10 @@ public void LogsWhenEnabled(LogLevel minLevel, LogLevel logLevel, int expected)
130129

131130
logger.Log(logLevel, 0, TestMessage, null, null);
132131

133-
Assert.AreEqual(expected, sink.Writes.Count);
132+
Assert.Equal(expected, sink.Writes.Count);
134133
}
135134

136-
[Test]
135+
[Fact]
137136
public void LogsCorrectMessage()
138137
{
139138
var t = SetUp(LogLevel.Verbose);
@@ -143,11 +142,11 @@ public void LogsCorrectMessage()
143142
logger.Log(LogLevel.Information, 0, null, null, null);
144143
logger.Log(LogLevel.Information, 0, TestMessage, null, null);
145144

146-
Assert.AreEqual(1, sink.Writes.Count);
147-
Assert.AreEqual(TestMessage, sink.Writes[0].RenderMessage());
145+
Assert.Equal(1, sink.Writes.Count);
146+
Assert.Equal(TestMessage, sink.Writes[0].RenderMessage());
148147
}
149148

150-
[Test]
149+
[Fact]
151150
public void CarriesException()
152151
{
153152
var t = SetUp(LogLevel.Verbose);
@@ -158,11 +157,11 @@ public void CarriesException()
158157

159158
logger.Log(LogLevel.Information, 0, "Test", exception, null);
160159

161-
Assert.AreEqual(1, sink.Writes.Count);
162-
Assert.AreSame(exception, sink.Writes[0].Exception);
160+
Assert.Equal(1, sink.Writes.Count);
161+
Assert.Same(exception, sink.Writes[0].Exception);
163162
}
164163

165-
[Test]
164+
[Fact]
166165
public void SingleScopeProperty()
167166
{
168167
var t = SetUp(LogLevel.Verbose);
@@ -174,12 +173,12 @@ public void SingleScopeProperty()
174173
logger.Log(LogLevel.Information, 0, TestMessage, null, null);
175174
}
176175

177-
Assert.AreEqual(1, sink.Writes.Count);
176+
Assert.Equal(1, sink.Writes.Count);
178177
Assert.True(sink.Writes[0].Properties.ContainsKey("Name"));
179-
Assert.AreEqual("\"pizza\"", sink.Writes[0].Properties["Name"].ToString());
178+
Assert.Equal("\"pizza\"", sink.Writes[0].Properties["Name"].ToString());
180179
}
181180

182-
[Test]
181+
[Fact]
183182
public void NestedScopeSameProperty()
184183
{
185184
var t = SetUp(LogLevel.Verbose);
@@ -195,12 +194,12 @@ public void NestedScopeSameProperty()
195194
}
196195

197196
// Should retain the property of the most specific scope
198-
Assert.AreEqual(1, sink.Writes.Count);
197+
Assert.Equal(1, sink.Writes.Count);
199198
Assert.True(sink.Writes[0].Properties.ContainsKey("Name"));
200-
Assert.AreEqual("\"bacon\"", sink.Writes[0].Properties["Name"].ToString());
199+
Assert.Equal("\"bacon\"", sink.Writes[0].Properties["Name"].ToString());
201200
}
202201

203-
[Test]
202+
[Fact]
204203
public void NestedScopesDifferentProperties()
205204
{
206205
var t = SetUp(LogLevel.Verbose);
@@ -215,14 +214,14 @@ public void NestedScopesDifferentProperties()
215214
}
216215
}
217216

218-
Assert.AreEqual(1, sink.Writes.Count);
217+
Assert.Equal(1, sink.Writes.Count);
219218
Assert.True(sink.Writes[0].Properties.ContainsKey("Name"));
220-
Assert.AreEqual("\"spaghetti\"", sink.Writes[0].Properties["Name"].ToString());
219+
Assert.Equal("\"spaghetti\"", sink.Writes[0].Properties["Name"].ToString());
221220
Assert.True(sink.Writes[0].Properties.ContainsKey("LuckyNumber"));
222-
Assert.AreEqual("7", sink.Writes[0].Properties["LuckyNumber"].ToString());
221+
Assert.Equal("7", sink.Writes[0].Properties["LuckyNumber"].ToString());
223222
}
224223

225-
[Test]
224+
[Fact]
226225
public void CarriesMessageTemplateProperties()
227226
{
228227
var selfLog = new StringWriter();
@@ -235,11 +234,11 @@ public void CarriesMessageTemplateProperties()
235234
logger.LogInformation("Hello, {Recipient}", "World");
236235

237236
Assert.True(sink.Writes[0].Properties.ContainsKey("Recipient"));
238-
Assert.AreEqual("\"World\"", sink.Writes[0].Properties["Recipient"].ToString());
239-
Assert.AreEqual("Hello, {Recipient}", sink.Writes[0].MessageTemplate.Text);
237+
Assert.Equal("\"World\"", sink.Writes[0].Properties["Recipient"].ToString());
238+
Assert.Equal("Hello, {Recipient}", sink.Writes[0].MessageTemplate.Text);
240239

241240
SelfLog.Out = null;
242-
Assert.IsEmpty(selfLog.ToString());
241+
Assert.Empty(selfLog.ToString());
243242
}
244243

245244
private class FoodScope : ILogValues
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
2-
"dependencies": {
3-
"Serilog.Framework.Logging": "1.0.0-*",
4-
"NUnitTestAdapter.WithFramework": "2.0.0"
5-
},
6-
"frameworks": {
7-
"dnx451": {
8-
"dependencies": {
9-
}
10-
}
2+
"commands": {
3+
"test": "xunit.runner.dnx",
4+
"test-dnxcore50": "xunit.runner.dnx"
5+
},
6+
"dependencies": {
7+
"Serilog.Framework.Logging": "1.0.0-*",
8+
"xunit": "2.1.0",
9+
"xunit.runner.visualstudio": "2.1.0",
10+
"xunit.runner.dnx": "2.1.0-rc1-build204"
11+
},
12+
"frameworks": {
13+
"dnx451": {
14+
"dependencies": {
15+
}
1116
}
17+
}
1218
}

0 commit comments

Comments
 (0)