Skip to content

Commit 3306f99

Browse files
committed
Assert exceptions with Verify instead of FluentAssertions
Not sure it makes better / more readable tests. Also mutation tests score goes down from 100% to 96.91% (not investigated why)
1 parent a437307 commit 3306f99

18 files changed

+135
-56
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
Type: ArgumentOutOfRangeException,
3+
Message:
4+
The value of argument 'indentation' (-1) is invalid for enum type 'Indentation'. (Parameter 'indentation')
5+
Actual value was -1.,
6+
ActualValue: -1,
7+
ParamName: indentation,
8+
StackTrace:
9+
at Serilog.Formatting.Log4Net.IndentationSettings..ctor(Indentation indentation, Byte size)
10+
at Serilog.Formatting.Log4Net.Tests.IndentationSettingsTest.<>c.<InvalidIndentation>b__1_0()
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
Type: ArgumentOutOfRangeException,
3+
Message:
4+
The value of argument 'size' must be greater than 0. (Parameter 'size')
5+
Actual value was 0.,
6+
ActualValue: 0,
7+
ParamName: size,
8+
StackTrace:
9+
at Serilog.Formatting.Log4Net.IndentationSettings..ctor(Indentation indentation, Byte size)
10+
at Serilog.Formatting.Log4Net.Tests.IndentationSettingsTest.<>c.<InvalidSize>b__2_0()
11+
}

tests/IndentationSettingsTest.cs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System;
2-
using FluentAssertions;
1+
using System.Threading.Tasks;
2+
using VerifyXunit;
33
using Xunit;
44

55
namespace Serilog.Formatting.Log4Net.Tests;
66

77
public class IndentationSettingsTest
88
{
99
[Theory]
10-
[InlineData(Indentation.Space, 2, " ")]
11-
[InlineData(Indentation.Tab, 2, "\t\t")]
12-
[InlineData(Indentation.Space, 4, " ")]
13-
[InlineData(Indentation.Tab, 4, "\t\t\t\t")]
14-
public void IndentationSettingsToString(Indentation indentation, byte size, string expectedString)
10+
[InlineData(Indentation.Space, 2)]
11+
[InlineData(Indentation.Tab, 2)]
12+
[InlineData(Indentation.Space, 4)]
13+
[InlineData(Indentation.Tab, 4)]
14+
public Task IndentationSettingsToString(Indentation indentation, byte size)
1515
{
1616
// Arrange
1717
var indentationSettings = new IndentationSettings(indentation, size);
@@ -20,28 +20,18 @@ public void IndentationSettingsToString(Indentation indentation, byte size, stri
2020
var indentationString = indentationSettings.ToString();
2121

2222
// Assert
23-
indentationString.Should().Be(expectedString);
23+
return Verifier.Verify(indentationString).UseParameters(indentation, size);
2424
}
2525

2626
[Fact]
27-
public void InvalidIndentation()
27+
public Task InvalidIndentation()
2828
{
29-
// Act
30-
var action = () => new IndentationSettings((Indentation)(-1), size: 1);
31-
32-
// Assert
33-
action.Should().ThrowExactly<ArgumentOutOfRangeException>()
34-
.Which.Message.Should().StartWith("The value of argument 'indentation' (-1) is invalid for enum type 'Indentation'.");
29+
return Verifier.Throws(() => new IndentationSettings((Indentation)(-1), size: 1));
3530
}
3631

3732
[Fact]
38-
public void InvalidSize()
33+
public Task InvalidSize()
3934
{
40-
// Act
41-
var action = () => new IndentationSettings(indentation: default, size: 0);
42-
43-
// Assert
44-
action.Should().ThrowExactly<ArgumentOutOfRangeException>()
45-
.Which.Message.Should().StartWith("The value of argument 'size' must be greater than 0.");
35+
return Verifier.Throws(() => new IndentationSettings(indentation: default, size: 0));
4636
}
4737
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
Type: ArgumentOutOfRangeException,
3+
Message:
4+
The value of argument 'lineEnding' (4) is invalid for enum type 'LineEnding'. (Parameter 'lineEnding')
5+
Actual value was 4.,
6+
ActualValue: 4,
7+
ParamName: lineEnding,
8+
StackTrace:
9+
at Serilog.Formatting.Log4Net.LineEndingExtensions.ToCharacters(LineEnding lineEnding)
10+
at Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder.CreateXmlWriterSettings(LineEnding lineEnding, IndentationSettings indentationSettings)
11+
at Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder.Build()
12+
at Serilog.Formatting.Log4Net.Log4NetTextFormatter..ctor(Action`1 configureOptions)
13+
at Serilog.Formatting.Log4Net.Tests.LineEndingTest.<>c.<InvalidLineEnding>b__0_0()
14+
}

tests/LineEndingTest.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
using System;
2-
using FluentAssertions;
1+
using System.Threading.Tasks;
2+
using VerifyXunit;
33
using Xunit;
44

55
namespace Serilog.Formatting.Log4Net.Tests;
66

77
public class LineEndingTest
88
{
99
[Fact]
10-
public void InvalidLineEnding()
10+
public Task InvalidLineEnding()
1111
{
12-
Action action = () => _ = new Log4NetTextFormatter(c => c.UseLineEnding((LineEnding)4));
13-
14-
action.Should().ThrowExactly<ArgumentOutOfRangeException>()
15-
.WithMessage("The value of argument 'lineEnding' (4) is invalid for enum type 'LineEnding'.*");
12+
return Verifier.Throws(() => _ = new Log4NetTextFormatter(c => c.UseLineEnding((LineEnding)4)));
1613
}
1714
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
target: null,
3+
SelfLog:
4+
[Serilog.Formatting.Log4Net.Log4NetTextFormatter] An exception was thrown while formatting an exception. Using the default exception formatter.
5+
System.InvalidOperationException: 💥 Boom 💥
6+
at Serilog.Formatting.Log4Net.Tests.Log4NetTextFormatterTest.<>c.<ExceptionFormatterThrowing>b__29_1(Exception _) in {ProjectDirectory}Log4NetTextFormatterTest.cs:line 466
7+
at Serilog.Formatting.Log4Net.Log4NetTextFormatter.FormatException(Exception exception) in {SolutionDirectory}src/Log4NetTextFormatter.cs:line 424
8+
}

0 commit comments

Comments
 (0)