Skip to content

Commit a0b8385

Browse files
authored
Replace FluentAssertions with AwesomeAssertions (#596)
1 parent f63bfbe commit a0b8385

File tree

2 files changed

+23
-46
lines changed

2 files changed

+23
-46
lines changed

tests/Install-Scripts.Test/Install-Scripts.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
18+
<PackageReference Include="AwesomeAssertions" Version="8.0.2" />
1919
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
2020
<PackageReference Include="Verify.Xunit" Version="19.10.0" />
2121
<PackageReference Include="xunit" Version="2.4.2" />

tests/Install-Scripts.Test/Utils/CommandResultAssertions.cs

+22-45
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Text.RegularExpressions;
66
using FluentAssertions;
77
using FluentAssertions.Execution;
8-
using static Install_Scripts.Test.Utils.DotNetCommand;
8+
using CommandResult = Install_Scripts.Test.Utils.DotNetCommand.CommandResult;
99

1010
namespace Microsoft.NET.TestFramework.Assertions
1111
{
@@ -20,145 +20,122 @@ internal CommandResultAssertions(CommandResult commandResult)
2020

2121
internal AndConstraint<CommandResultAssertions> ExitWith(int expectedExitCode)
2222
{
23-
Execute.Assertion.ForCondition(_commandResult.ExitCode == expectedExitCode)
24-
.FailWith(AppendDiagnosticsTo($"Expected command to exit with {expectedExitCode} but it did not."));
23+
_commandResult.ExitCode.Should().Be(expectedExitCode, AppendDiagnosticsTo($"Expected command to exit with {expectedExitCode} but it did not."));
2524
return new AndConstraint<CommandResultAssertions>(this);
2625
}
2726

2827
internal AndConstraint<CommandResultAssertions> Pass()
2928
{
30-
Execute.Assertion.ForCondition(_commandResult.ExitCode == 0)
31-
.FailWith(AppendDiagnosticsTo($"Expected command to pass but it did not."));
29+
_commandResult.ExitCode.Should().Be(0, AppendDiagnosticsTo($"Expected command to pass but it did not."));
3230
return new AndConstraint<CommandResultAssertions>(this);
3331
}
3432

3533
internal AndConstraint<CommandResultAssertions> Fail()
3634
{
37-
Execute.Assertion.ForCondition(_commandResult.ExitCode != 0)
38-
.FailWith(AppendDiagnosticsTo($"Expected command to fail but it did not."));
35+
_commandResult.ExitCode.Should().NotBe(0, AppendDiagnosticsTo($"Expected command to fail but it did not."));
3936
return new AndConstraint<CommandResultAssertions>(this);
4037
}
4138

4239
internal AndConstraint<CommandResultAssertions> HaveStdOut()
4340
{
44-
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdOut))
45-
.FailWith(AppendDiagnosticsTo("Command did not output anything to stdout"));
41+
_commandResult.StdOut.Should().NotBeNullOrEmpty(AppendDiagnosticsTo("Command did not output anything to stdout"));
4642
return new AndConstraint<CommandResultAssertions>(this);
4743
}
4844

4945
internal AndConstraint<CommandResultAssertions> HaveStdOut(string expectedOutput)
5046
{
51-
Execute.Assertion.ForCondition(_commandResult.StdOut!.Equals(expectedOutput, StringComparison.Ordinal))
52-
.FailWith(AppendDiagnosticsTo($"Command did not output with Expected Output. Expected: {expectedOutput}"));
47+
_commandResult.StdOut.Should().Be(expectedOutput, AppendDiagnosticsTo($"Command did not output with Expected Output. Expected: {expectedOutput}"));
5348
return new AndConstraint<CommandResultAssertions>(this);
5449
}
5550

5651
internal AndConstraint<CommandResultAssertions> HaveStdOutContaining(string pattern)
5752
{
58-
Execute.Assertion.ForCondition(_commandResult.StdOut!.Contains(pattern))
59-
.FailWith(AppendDiagnosticsTo($"The command output did not contain expected result: {pattern}{Environment.NewLine}"));
53+
_commandResult.StdOut.Should().Contain(pattern, AppendDiagnosticsTo($"The command output did not contain expected result: {pattern}{Environment.NewLine}"));
6054
return new AndConstraint<CommandResultAssertions>(this);
6155
}
6256

6357
internal AndConstraint<CommandResultAssertions> HaveStdOutContaining(Func<string, bool> predicate, string description = "")
6458
{
65-
Execute.Assertion.ForCondition(predicate(_commandResult.StdOut!))
66-
.FailWith(AppendDiagnosticsTo($"The command output did not contain expected result: {description} {Environment.NewLine}"));
59+
predicate(_commandResult.StdOut!).Should().BeTrue(AppendDiagnosticsTo($"The command output did not contain expected result: {description} {Environment.NewLine}"));
6760
return new AndConstraint<CommandResultAssertions>(this);
6861
}
6962

7063
internal AndConstraint<CommandResultAssertions> NotHaveStdOutContaining(string pattern)
7164
{
72-
Execute.Assertion.ForCondition(!_commandResult.StdOut!.Contains(pattern))
73-
.FailWith(AppendDiagnosticsTo($"The command output contained a result it should not have contained: {pattern}{Environment.NewLine}"));
65+
_commandResult.StdOut.Should().NotContain(pattern, AppendDiagnosticsTo($"The command output contained a result it should not have contained: {pattern}{Environment.NewLine}"));
7466
return new AndConstraint<CommandResultAssertions>(this);
7567
}
7668

7769
internal AndConstraint<CommandResultAssertions> NotHaveStdOutContainingIgnoreCase(string pattern)
7870
{
79-
Execute.Assertion.ForCondition(!_commandResult.StdOut!.Contains(pattern, StringComparison.OrdinalIgnoreCase))
80-
.FailWith(AppendDiagnosticsTo($"The command output contained a result it should not have contained (ignoring case): {pattern}{Environment.NewLine}"));
71+
_commandResult.StdOut.Should().NotContainEquivalentOf(pattern, AppendDiagnosticsTo($"The command output contained a result it should not have contained (ignoring case): {pattern}{Environment.NewLine}"));
8172
return new AndConstraint<CommandResultAssertions>(this);
8273
}
8374

8475
internal AndConstraint<CommandResultAssertions> HaveStdOutContainingIgnoreSpaces(string pattern)
8576
{
86-
string commandResultNoSpaces = _commandResult.StdOut!.Replace(" ", "");
87-
88-
Execute.Assertion
89-
.ForCondition(commandResultNoSpaces.Contains(pattern))
90-
.FailWith(AppendDiagnosticsTo($"The command output did not contain expected result: {pattern}{Environment.NewLine}"));
91-
77+
var commandResultNoSpaces = _commandResult.StdOut!.Replace(" ", "");
78+
commandResultNoSpaces.Should().Contain(pattern, AppendDiagnosticsTo($"The command output did not contain expected result: {pattern}{Environment.NewLine}"));
9279
return new AndConstraint<CommandResultAssertions>(this);
9380
}
9481

9582
internal AndConstraint<CommandResultAssertions> HaveStdOutContainingIgnoreCase(string pattern)
9683
{
97-
Execute.Assertion.ForCondition(_commandResult.StdOut!.Contains(pattern, StringComparison.OrdinalIgnoreCase))
98-
.FailWith(AppendDiagnosticsTo($"The command output did not contain expected result (ignoring case): {pattern}{Environment.NewLine}"));
84+
_commandResult.StdOut.Should().ContainEquivalentOf(pattern, AppendDiagnosticsTo($"The command output did not contain expected result (ignoring case): {pattern}{Environment.NewLine}"));
9985
return new AndConstraint<CommandResultAssertions>(this);
10086
}
10187

10288
internal AndConstraint<CommandResultAssertions> HaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
10389
{
104-
Execute.Assertion.ForCondition(Regex.Match(_commandResult.StdOut!, pattern, options).Success)
105-
.FailWith(AppendDiagnosticsTo($"Matching the command output failed. Pattern: {pattern}{Environment.NewLine}"));
90+
_commandResult.StdOut.Should().MatchRegex(pattern, AppendDiagnosticsTo($"Matching the command output failed. Pattern: {pattern}{Environment.NewLine}"));
10691
return new AndConstraint<CommandResultAssertions>(this);
10792
}
10893

10994
internal AndConstraint<CommandResultAssertions> NotHaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
11095
{
111-
Execute.Assertion.ForCondition(!Regex.Match(_commandResult.StdOut!, pattern, options).Success)
112-
.FailWith(AppendDiagnosticsTo($"The command output matched a pattern it should not have. Pattern: {pattern}{Environment.NewLine}"));
96+
_commandResult.StdOut.Should().NotMatchRegex(pattern, AppendDiagnosticsTo($"The command output matched a pattern it should not have contained: {pattern}{Environment.NewLine}"));
11397
return new AndConstraint<CommandResultAssertions>(this);
11498
}
11599

116100
internal AndConstraint<CommandResultAssertions> HaveStdErr()
117101
{
118-
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdErr))
119-
.FailWith(AppendDiagnosticsTo("Command did not output anything to stderr."));
102+
_commandResult.StdErr.Should().NotBeNullOrEmpty(AppendDiagnosticsTo("Command did not output anything to stderr."));
120103
return new AndConstraint<CommandResultAssertions>(this);
121104
}
122105

123106
internal AndConstraint<CommandResultAssertions> HaveStdErrContaining(string pattern)
124107
{
125-
Execute.Assertion.ForCondition(_commandResult.StdErr!.Contains(pattern))
126-
.FailWith(AppendDiagnosticsTo($"The command error output did not contain expected result: {pattern}{Environment.NewLine}"));
108+
_commandResult.StdErr.Should().Contain(pattern, AppendDiagnosticsTo($"The command error output did not contain expected result: {pattern}{Environment.NewLine}"));
127109
return new AndConstraint<CommandResultAssertions>(this);
128110
}
129111

130112
internal AndConstraint<CommandResultAssertions> NotHaveStdErrContaining(string pattern)
131113
{
132-
Execute.Assertion.ForCondition(!_commandResult.StdErr!.Contains(pattern))
133-
.FailWith(AppendDiagnosticsTo($"The command error output contained a result it should not have contained: {pattern}{Environment.NewLine}"));
114+
_commandResult.StdErr.Should().NotContain(pattern, AppendDiagnosticsTo($"The command error output contained a result it should not have contained: {pattern}{Environment.NewLine}"));
134115
return new AndConstraint<CommandResultAssertions>(this);
135116
}
136117

137118
internal AndConstraint<CommandResultAssertions> NotHaveStdErrContainingIgnoreCase(string pattern)
138119
{
139-
Execute.Assertion.ForCondition(!_commandResult.StdErr!.Contains(pattern, StringComparison.OrdinalIgnoreCase))
140-
.FailWith(AppendDiagnosticsTo($"The command error output contained a result it should not have contained (ignoring case): {pattern}{Environment.NewLine}"));
120+
_commandResult.StdErr.Should().NotContainEquivalentOf(pattern, AppendDiagnosticsTo($"The command error output contained a result it should not have contained (ignoring case): {pattern}{Environment.NewLine}"));
141121
return new AndConstraint<CommandResultAssertions>(this);
142122
}
143123

144124
internal AndConstraint<CommandResultAssertions> HaveStdErrMatching(string pattern, RegexOptions options = RegexOptions.None)
145125
{
146-
Execute.Assertion.ForCondition(Regex.Match(_commandResult.StdErr!, pattern, options).Success)
147-
.FailWith(AppendDiagnosticsTo($"Matching the command error output failed. Pattern: {pattern}{Environment.NewLine}"));
126+
_commandResult.StdErr.Should().MatchRegex(pattern, AppendDiagnosticsTo($"Matching the command error output failed. Pattern: {pattern}{Environment.NewLine}"));
148127
return new AndConstraint<CommandResultAssertions>(this);
149128
}
150129

151130
internal AndConstraint<CommandResultAssertions> NotHaveStdOut()
152131
{
153-
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdOut))
154-
.FailWith(AppendDiagnosticsTo($"Expected command to not output to stdout but it did:"));
132+
_commandResult.StdOut.Should().BeNullOrEmpty(AppendDiagnosticsTo($"Expected command to not output to stdout but it did:"));
155133
return new AndConstraint<CommandResultAssertions>(this);
156134
}
157135

158136
internal AndConstraint<CommandResultAssertions> NotHaveStdErr()
159137
{
160-
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdErr))
161-
.FailWith(AppendDiagnosticsTo("Expected command to not output to stderr but it did:"));
138+
_commandResult.StdErr.Should().BeNullOrEmpty(AppendDiagnosticsTo("Expected command to not output to stderr but it did:"));
162139
return new AndConstraint<CommandResultAssertions>(this);
163140
}
164141

0 commit comments

Comments
 (0)