Skip to content

Commit a7cc2ee

Browse files
fredrikhrjonsequitur
authored andcommitted
Use FluentAssertions for Env-Directive unit-tests
1 parent d5d44c5 commit a7cc2ee

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/System.CommandLine.Tests/EnvironmentVariableDirectiveTests.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using FluentAssertions;
2+
33
using System.CommandLine.Builder;
44
using System.CommandLine.Invocation;
55
using System.CommandLine.Parsing;
66
using System.Linq;
7-
using System.Text;
87
using System.Threading.Tasks;
98

109
using Xunit;
@@ -26,7 +25,7 @@ public static async Task Sets_environment_variable_to_value()
2625
Handler = CommandHandler.Create(() =>
2726
{
2827
asserted = true;
29-
Assert.Equal(value, Environment.GetEnvironmentVariable(variable));
28+
Environment.GetEnvironmentVariable(variable).Should().Be(value);
3029
})
3130
};
3231

@@ -36,7 +35,7 @@ public static async Task Sets_environment_variable_to_value()
3635

3736
await parser.InvokeAsync(new[] { $"[env:{variable}={value}]" });
3837

39-
Assert.True(asserted);
38+
asserted.Should().BeTrue();
4039
}
4140

4241
[Fact]
@@ -50,7 +49,7 @@ public static async Task Trims_environment_variable_name()
5049
Handler = CommandHandler.Create(() =>
5150
{
5251
asserted = true;
53-
Assert.Equal(value, Environment.GetEnvironmentVariable(variable));
52+
Environment.GetEnvironmentVariable(variable).Should().Be(value);
5453
})
5554
};
5655

@@ -60,7 +59,7 @@ public static async Task Trims_environment_variable_name()
6059

6160
await parser.InvokeAsync(new[] { $"[env: {variable} ={value}]" });
6261

63-
Assert.True(asserted);
62+
asserted.Should().BeTrue();
6463
}
6564

6665
[Fact]
@@ -74,7 +73,7 @@ public static async Task Trims_environment_variable_value()
7473
Handler = CommandHandler.Create(() =>
7574
{
7675
asserted = true;
77-
Assert.Equal(value, Environment.GetEnvironmentVariable(variable));
76+
Environment.GetEnvironmentVariable(variable).Should().Be(value);
7877
})
7978
};
8079

@@ -84,7 +83,7 @@ public static async Task Trims_environment_variable_value()
8483

8584
await parser.InvokeAsync(new[] { $"[env:{variable}= {value} ]" });
8685

87-
Assert.True(asserted);
86+
asserted.Should().BeTrue();
8887
}
8988

9089
[Fact]
@@ -98,7 +97,7 @@ public static async Task Sets_environment_variable_value_containing_equals_sign(
9897
Handler = CommandHandler.Create(() =>
9998
{
10099
asserted = true;
101-
Assert.Equal(value, Environment.GetEnvironmentVariable(variable));
100+
Environment.GetEnvironmentVariable(variable).Should().Be(value);
102101
})
103102
};
104103

@@ -108,7 +107,7 @@ public static async Task Sets_environment_variable_value_containing_equals_sign(
108107

109108
await parser.InvokeAsync(new[] { $"[env:{variable}={value}]" });
110109

111-
Assert.True(asserted);
110+
asserted.Should().BeTrue();
112111
}
113112

114113
[Fact]
@@ -121,7 +120,7 @@ public static async Task Ignores_environment_directive_without_equals_sign()
121120
Handler = CommandHandler.Create(() =>
122121
{
123122
asserted = true;
124-
Assert.Null(Environment.GetEnvironmentVariable(variable));
123+
Environment.GetEnvironmentVariable(variable).Should().BeNull();
125124
})
126125
};
127126

@@ -131,7 +130,7 @@ public static async Task Ignores_environment_directive_without_equals_sign()
131130

132131
await parser.InvokeAsync(new[] { $"[env:{variable}]" });
133132

134-
Assert.True(asserted);
133+
asserted.Should().BeTrue();
135134
}
136135

137136
[Fact]
@@ -145,7 +144,7 @@ public static async Task Ignores_environment_directive_with_empty_variable_name(
145144
{
146145
asserted = true;
147146
var env = Environment.GetEnvironmentVariables();
148-
Assert.DoesNotContain(value, env.Values.Cast<string>().ToArray());
147+
env.Values.Cast<string>().Should().NotContain(value);
149148
})
150149
};
151150

@@ -155,7 +154,7 @@ public static async Task Ignores_environment_directive_with_empty_variable_name(
155154

156155
await parser.InvokeAsync(new[] { $"[env:={value}]" });
157156

158-
Assert.True(asserted);
157+
asserted.Should().BeTrue();
159158
}
160159

161160
[Fact]
@@ -169,7 +168,7 @@ public static async Task Ignores_environment_directive_with_whitespace_variable_
169168
{
170169
asserted = true;
171170
var env = Environment.GetEnvironmentVariables();
172-
Assert.DoesNotContain(value, env.Values.Cast<string>().ToArray());
171+
env.Values.Cast<string>().Should().NotContain(value);
173172
})
174173
};
175174

@@ -179,7 +178,7 @@ public static async Task Ignores_environment_directive_with_whitespace_variable_
179178

180179
await parser.InvokeAsync(new[] { $"[env: ={value}]" });
181180

182-
Assert.True(asserted);
181+
asserted.Should().BeTrue();
183182
}
184183
}
185184
}

0 commit comments

Comments
 (0)