Skip to content

Commit 1a35a27

Browse files
committed
(#2893) Update tests to use to FluentAssertions style
This updates tests to use new ways of writing assertions that are available in FluentAssertions but where not in Should
1 parent 6a02b33 commit 1a35a27

27 files changed

+1124
-2225
lines changed

src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void ShouldHaveProxyConfiguration()
140140
if (!SystemSet && !ArgumentSet && !ConfigSet &&
141141
!EnvironmentVariableSet)
142142
{
143-
Configuration.Proxy.Location.Should().Be(string.Empty);
143+
Configuration.Proxy.Location.Should().BeEmpty();
144144
return;
145145
}
146146

@@ -211,7 +211,7 @@ public void ShouldBypassProxy()
211211
if (!ArgumentSet && !ConfigSet &&
212212
!EnvironmentVariableSet)
213213
{
214-
Configuration.Proxy.BypassList.Should().Be(string.Empty);
214+
Configuration.Proxy.BypassList.Should().BeEmpty();
215215
return;
216216
}
217217

src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void Should_log_a_warning_about_locked_files()
101101
[Fact]
102102
public void Should_return_a_special_code_for_locked_files()
103103
{
104-
_result.Files.FirstOrDefault(x => x.Path == _theLockedFile).Checksum.Should().Be(ApplicationParameters.HashProviderFileLocked);
104+
_result.Files.Should().ContainSingle(x => x.Path == _theLockedFile).Which.Checksum.Should().Be(ApplicationParameters.HashProviderFileLocked);
105105
}
106106
}
107107
}

src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace chocolatey.tests.integration.infrastructure.filesystem
2323
using chocolatey.infrastructure.platforms;
2424
using NUnit.Framework;
2525
using FluentAssertions;
26+
using FluentAssertions.Extensions;
2627

2728
public class DotNetFileSystemSpecs
2829
{
@@ -85,13 +86,13 @@ public void GetExecutablePath_should_return_same_value_when_executable_is_not_fo
8586
[Fact]
8687
public void GetExecutablePath_should_return_empty_string_when_value_is_null()
8788
{
88-
FileSystem.GetExecutablePath(null).Should().Be(string.Empty);
89+
FileSystem.GetExecutablePath(null).Should().BeEmpty();
8990
}
9091

9192
[Fact]
9293
public void GetExecutablePath_should_return_empty_string_when_value_is_empty_string()
9394
{
94-
FileSystem.GetExecutablePath(string.Empty).Should().Be(string.Empty);
95+
FileSystem.GetExecutablePath(string.Empty).Should().BeEmpty();
9596
}
9697
}
9798

@@ -130,8 +131,7 @@ public void GetFiles_should_return_files_that_meet_the_pattern()
130131
var actual = FileSystem.GetFiles(ContextPath, "chocolateyInstall.ps1", SearchOption.AllDirectories).ToList();
131132
FileSystem.DeleteFile(filePath);
132133

133-
actual.Should().NotBeEmpty();
134-
actual.Count().Should().Be(1);
134+
actual.Should().ContainSingle();
135135
}
136136

137137
[Fact]
@@ -145,8 +145,7 @@ public void GetFiles_should_return_files_that_meet_the_pattern_regardless_of_cas
145145
var actual = FileSystem.GetFiles(ContextPath, "chocolateyinstall.ps1", SearchOption.AllDirectories).ToList();
146146
FileSystem.DeleteFile(filePath);
147147

148-
actual.Should().NotBeEmpty();
149-
actual.Count().Should().Be(1);
148+
actual.Should().ContainSingle();
150149
}
151150

152151
[Fact]
@@ -205,7 +204,7 @@ public override void Because()
205204
[Fact]
206205
public void Visible_file_should_now_be_hidden()
207206
{
208-
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.Hidden).Should().Be(FileAttributes.Hidden);
207+
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes).Should().HaveFlag(FileAttributes.Hidden);
209208
}
210209

211210
public override void AfterObservations()
@@ -232,7 +231,7 @@ public override void Because()
232231
[Fact]
233232
public void Readonly_file_should_no_longer_be_readonly()
234233
{
235-
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.ReadOnly).Should().NotBe(FileAttributes.ReadOnly);
234+
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes).Should().NotHaveFlag(FileAttributes.ReadOnly);
236235
}
237236
}
238237

@@ -351,7 +350,7 @@ public override void Because()
351350
[Fact]
352351
public void Should_have_correct_modified_date()
353352
{
354-
FileSystem.GetFileModifiedDate(TheTestFile).ToShortDateString().Should().Be(DateTime.Now.AddDays(-1).ToShortDateString());
353+
FileSystem.GetFileModifiedDate(TheTestFile).Should().BeCloseTo(1.Days().Before(DateTime.Now), 5.Seconds());
355354
}
356355
}
357356
}

0 commit comments

Comments
 (0)