Skip to content

Commit a8d6d05

Browse files
committed
Rewrite all tests that were using FluentActions.Invoking
Instead, use Action action = () ⇒ …
1 parent 8dc3b53 commit a8d6d05

5 files changed

+51
-43
lines changed

tests/IndentationSettingsTest.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ public void IndentationSettingsToString(Indentation indentation, byte size, stri
2626
[Fact]
2727
public void InvalidIndentation()
2828
{
29-
FluentActions.Invoking(() => new IndentationSettings((Indentation)(-1), size: 1))
30-
.Should().ThrowExactly<ArgumentOutOfRangeException>()
31-
.And.Message.Should().StartWith("The value of argument 'indentation' (-1) is invalid for enum type 'Indentation'.");
29+
// Act
30+
Func<IndentationSettings> 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'.");
3235
}
3336

3437
[Fact]
3538
public void InvalidSize()
3639
{
37-
FluentActions.Invoking(() => new IndentationSettings(indentation: default, size: 0))
38-
.Should().ThrowExactly<ArgumentOutOfRangeException>()
39-
.And.Message.Should().StartWith("The value of argument 'size' must be greater than 0.");
40+
// Act
41+
Func<IndentationSettings> 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.");
4046
}
4147
}
4248
}

tests/LineEndingExtensionsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void CarriageReturn_LineFeed()
3333
[Fact]
3434
public void InvalidLineEnding()
3535
{
36-
FluentActions.Invoking(() => ((LineEnding)4).ToCharacters())
37-
.Should().ThrowExactly<ArgumentOutOfRangeException>()
38-
.And.Message.Should().StartWith("The value of argument 'lineEnding' (4) is invalid for enum type 'LineEnding'.");
36+
Func<string> action = () => ((LineEnding)4).ToCharacters();
3937

38+
action.Should().ThrowExactly<ArgumentOutOfRangeException>()
39+
.Which.Message.Should().StartWith("The value of argument 'lineEnding' (4) is invalid for enum type 'LineEnding'.");
4040
}
4141
}
4242
}

tests/Log4NetTextFormatterOptionsBuilderTest.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ public void UsePropertyFilter()
9999
[Fact]
100100
public void SettingPropertyFilterToNullThrowsArgumentNullException()
101101
{
102-
// Arrange
103-
static void SetPropertyFilterToNull() => _ = new Log4NetTextFormatterOptionsBuilder().UsePropertyFilter(null!);
102+
// Act
103+
Func<Log4NetTextFormatterOptionsBuilder> action = () => new Log4NetTextFormatterOptionsBuilder().UsePropertyFilter(null!);
104104

105-
// Act + Assert
106-
FluentActions.Invoking(SetPropertyFilterToNull)
107-
.Should().ThrowExactly<ArgumentNullException>()
108-
.And.Message.Should().StartWith("The FilterProperty option can not be null.");
105+
// Assert
106+
action.Should().ThrowExactly<ArgumentNullException>()
107+
.Which.Message.Should().StartWith("The FilterProperty option can not be null.");
109108
}
110109

111110
[Fact]
@@ -124,13 +123,12 @@ public void UseExceptionFormatter()
124123
[Fact]
125124
public void SettingExceptionFormatterToNullThrowsArgumentNullException()
126125
{
127-
// Arrange
128-
static void SetExceptionFormatterToNull() => _ = new Log4NetTextFormatterOptionsBuilder().UseExceptionFormatter(null!);
126+
// Act
127+
Func<Log4NetTextFormatterOptionsBuilder> action = () => new Log4NetTextFormatterOptionsBuilder().UseExceptionFormatter(null!);
129128

130-
// Act + Assert
131-
FluentActions.Invoking(SetExceptionFormatterToNull).Should()
132-
.ThrowExactly<ArgumentNullException>()
133-
.And.Message.Should().StartWith("The FormatException option can not be null.");
129+
// Assert
130+
action.Should().ThrowExactly<ArgumentNullException>()
131+
.Which.Message.Should().StartWith("The FormatException option can not be null.");
134132
}
135133
}
136134
}

tests/Log4NetTextFormatterOptionsTest.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ public void NullXmlWriterSettings_ThrowsArgumentNullException()
2727
XmlWriterSettings xmlWriterSettings = null!;
2828
var parameters = new object?[] {formatProvider, cDataMode, log4NetXmlNamespace, xmlWriterSettings, (PropertyFilter)FilterProperty, (ExceptionFormatter)FormatException};
2929

30-
// Act + Assert
31-
var exception = FluentActions.Invoking(() => Log4NetTextFormatterOptionsConstructor.Invoke(parameters))
32-
.Should()
33-
.ThrowExactly<TargetInvocationException>().Which.InnerException.Should()
34-
.BeOfType<ArgumentNullException>().Subject;
35-
exception.ParamName.Should().Be("xmlWriterSettings");
30+
// Act
31+
Action action = () => Log4NetTextFormatterOptionsConstructor.Invoke(parameters);
32+
33+
// Assert
34+
action.Should().ThrowExactly<TargetInvocationException>()
35+
.Which.InnerException.Should().BeOfType<ArgumentNullException>()
36+
.Which.ParamName.Should().Be("xmlWriterSettings");
3637
}
3738

3839
[Fact]
@@ -46,12 +47,13 @@ public void NullPropertyFilter_ThrowsArgumentNullException()
4647
PropertyFilter filterProperty = null!;
4748
var parameters = new object?[] {formatProvider, cDataMode, log4NetXmlNamespace, xmlWriterSettings, filterProperty, (ExceptionFormatter)FormatException};
4849

49-
// Act + Assert
50-
var exception = FluentActions.Invoking(() => Log4NetTextFormatterOptionsConstructor.Invoke(parameters))
51-
.Should()
52-
.ThrowExactly<TargetInvocationException>().Which.InnerException.Should()
53-
.BeOfType<ArgumentNullException>().Subject;
54-
exception.ParamName.Should().Be("filterProperty");
50+
// Act
51+
Action action = () => Log4NetTextFormatterOptionsConstructor.Invoke(parameters);
52+
53+
// Assert
54+
action.Should().ThrowExactly<TargetInvocationException>()
55+
.Which.InnerException.Should().BeOfType<ArgumentNullException>()
56+
.Which.ParamName.Should().Be("filterProperty");
5557
}
5658

5759
[Fact]
@@ -65,12 +67,13 @@ public void NullExceptionFormatter_ThrowsArgumentNullException()
6567
ExceptionFormatter formatException = null!;
6668
var parameters = new object?[] {formatProvider, cDataMode, log4NetXmlNamespace, xmlWriterSettings, (PropertyFilter)FilterProperty, formatException};
6769

68-
// Act + Assert
69-
var exception = FluentActions.Invoking(() => Log4NetTextFormatterOptionsConstructor.Invoke(parameters))
70-
.Should()
71-
.ThrowExactly<TargetInvocationException>().Which.InnerException.Should()
72-
.BeOfType<ArgumentNullException>().Subject;
73-
exception.ParamName.Should().Be("formatException");
70+
// Act
71+
Action action = () => Log4NetTextFormatterOptionsConstructor.Invoke(parameters);
72+
73+
// Assert
74+
action.Should().ThrowExactly<TargetInvocationException>()
75+
.Which.InnerException.Should().BeOfType<ArgumentNullException>()
76+
.Which.ParamName.Should().Be("formatException");
7477
}
7578
}
7679
}

tests/Log4NetTextFormatterTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ public void LogEventLevel(LogEventLevel level)
106106
public void InvalidLogEventLevelThrowsArgumentOutOfRangeException()
107107
{
108108
// Arrange
109-
using var output = new StringWriter();
110109
var logEvent = CreateLogEvent((LogEventLevel)(-1));
111110
var formatter = new Log4NetTextFormatter();
112111

113-
// Act + Assert
114-
FluentActions.Invoking(() => formatter.Format(logEvent, output))
115-
.Should().ThrowExactly<ArgumentOutOfRangeException>()
112+
// Act
113+
Action action = () => formatter.Format(logEvent, TextWriter.Null);
114+
115+
// Assert
116+
action.Should().ThrowExactly<ArgumentOutOfRangeException>()
116117
.And.Message.Should().StartWith("The value of argument 'level' (-1) is invalid for enum type 'LogEventLevel'.");
117118
}
118119

0 commit comments

Comments
 (0)