Skip to content

Commit e961b2c

Browse files
committed
(#2893) Start on updating to FluentAssertions style
1 parent d26830d commit e961b2c

File tree

15 files changed

+66
-141
lines changed

15 files changed

+66
-141
lines changed

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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public void GetExecutablePath_should_return_same_value_when_executable_is_not_fo
8585
[Fact]
8686
public void GetExecutablePath_should_return_empty_string_when_value_is_null()
8787
{
88-
FileSystem.get_executable_path(null).Should().Be(string.Empty);
88+
FileSystem.get_executable_path(null).Should().BeEmpty();
8989
}
9090

9191
[Fact]
9292
public void GetExecutablePath_should_return_empty_string_when_value_is_empty_string()
9393
{
94-
FileSystem.get_executable_path(string.Empty).Should().Be(string.Empty);
94+
FileSystem.get_executable_path(string.Empty).Should().BeEmpty();
9595
}
9696
}
9797

@@ -130,8 +130,8 @@ public void GetFiles_should_return_files_that_meet_the_pattern()
130130
var actual = FileSystem.get_files(ContextPath, "chocolateyInstall.ps1", SearchOption.AllDirectories).ToList();
131131
FileSystem.delete_file(filePath);
132132

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

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

148-
actual.Should().NotBeEmpty();
149-
actual.Count().Should().Be(1);
148+
actual.Should().NotBeEmpty()
149+
.And.HaveCount(1);
150150
}
151151

152152
[Fact]
@@ -205,7 +205,7 @@ public override void Because()
205205
[Fact]
206206
public void visible_file_should_now_be_hidden()
207207
{
208-
((FileAttributes)FileSystem.get_file_info_for(SourceFile).Attributes & FileAttributes.Hidden).Should().Be(FileAttributes.Hidden);
208+
((FileAttributes)FileSystem.get_file_info_for(SourceFile).Attributes).Should().HaveFlag(FileAttributes.Hidden);
209209
}
210210

211211
public override void AfterObservations()
@@ -232,7 +232,7 @@ public override void Because()
232232
[Fact]
233233
public void readonly_file_should_no_longer_be_readonly()
234234
{
235-
((FileAttributes)FileSystem.get_file_info_for(SourceFile).Attributes & FileAttributes.ReadOnly).Should().NotBe(FileAttributes.ReadOnly);
235+
((FileAttributes)FileSystem.get_file_info_for(SourceFile).Attributes).Should().HaveFlag(FileAttributes.ReadOnly);
236236
}
237237
}
238238

src/chocolatey.tests.integration/scenarios/InstallScenarios.cs

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,8 @@ public void should_not_install_a_package_in_the_lib_directory()
8181
[Fact]
8282
public void should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_package()
8383
{
84-
bool expectedMessage = false;
85-
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
86-
{
87-
if (message.Contains("would have used NuGet to install packages")) expectedMessage = true;
88-
}
89-
90-
expectedMessage.Should().BeTrue();
84+
MockLogger.Messages.Should().ContainKey(LogLevel.Info.to_string())
85+
.WhoseValue.Should().Contain("would have used NuGet to install packages");
9186
}
9287

9388
[Fact]
@@ -130,25 +125,15 @@ public void should_not_install_a_package_in_the_lib_directory()
130125
[Fact]
131126
public void should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_package()
132127
{
133-
bool expectedMessage = false;
134-
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
135-
{
136-
if (message.Contains("would have used NuGet to install packages")) expectedMessage = true;
137-
}
138-
139-
expectedMessage.Should().BeTrue();
128+
MockLogger.Messages.Should().ContainKey(LogLevel.Info.to_string())
129+
.WhoseValue.Should().Contain("would have used NuGet to install packages");
140130
}
141131

142132
[Fact]
143133
public void should_contain_a_message_that_it_was_unable_to_find_package()
144134
{
145-
bool expectedMessage = false;
146-
foreach (var message in MockLogger.MessagesFor(LogLevel.Error).or_empty_list_if_null())
147-
{
148-
if (message.Contains("somethingnonexisting not installed. The package was not found with the source(s) listed")) expectedMessage = true;
149-
}
150-
151-
expectedMessage.Should().BeTrue();
135+
MockLogger.Messages.Should().ContainKey(LogLevel.Error.to_string())
136+
.WhoseValue.Should().Contain("somethingnonexisting not installed. The package was not found with the source(s) listed");
152137
}
153138
}
154139

@@ -450,13 +435,8 @@ public void should_contain_a_warning_message_that_it_installed_4_out_of_5_packag
450435
[Fact]
451436
public void should_contain_a_message_that_upgradepackage_with_an_expected_specified_version_was_installed()
452437
{
453-
bool expectedMessage = false;
454-
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
455-
{
456-
if (message.Contains("upgradepackage v1.0.0")) expectedMessage = true;
457-
}
458-
459-
expectedMessage.Should().BeTrue();
438+
MockLogger.Messages.Should().ContainKey(LogLevel.Info.to_string())
439+
.WhoseValue.Should().Contain("upgradepackage v1.0.0");
460440
}
461441

462442
[Fact]
@@ -502,25 +482,15 @@ public void should_not_have_warning_package_result()
502482
[Fact]
503483
public void should_specify_config_file_is_being_used_in_message()
504484
{
505-
bool expectedMessage = false;
506-
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
507-
{
508-
if (message.Contains("Installing from config file:")) expectedMessage = true;
509-
}
510-
511-
expectedMessage.Should().BeTrue();
485+
MockLogger.Messages.Should().ContainKey(LogLevel.Info.to_string())
486+
.WhoseValue.Should().Contain("Installing from config file:");
512487
}
513488

514489
[Fact]
515490
public void should_print_out_package_from_config_file_in_message()
516491
{
517-
bool expectedMessage = false;
518-
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
519-
{
520-
if (message.Contains("installpackage")) expectedMessage = true;
521-
}
522-
523-
expectedMessage.Should().BeTrue();
492+
MockLogger.Messages.Should().ContainKey(LogLevel.Info.to_string())
493+
.WhoseValue.Should().Contain("installpackage");
524494
}
525495
}
526496

@@ -849,13 +819,8 @@ public void should_not_be_able_delete_the_rollback()
849819
[Fact]
850820
public void should_contain_a_message_that_it_installed_successfully()
851821
{
852-
bool expectedMessage = false;
853-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
854-
{
855-
if (message.Contains("1/1")) expectedMessage = true;
856-
}
857-
858-
expectedMessage.Should().BeTrue();
822+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
823+
.WhoseValue.Should().Contain("1/1");
859824
}
860825

861826
[Fact]
@@ -947,13 +912,8 @@ public void should_delete_the_rollback()
947912
[Fact]
948913
public void should_contain_a_message_that_it_was_unable_to_reinstall_successfully()
949914
{
950-
bool expectedMessage = false;
951-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
952-
{
953-
if (message.Contains("0/1")) expectedMessage = true;
954-
}
955-
956-
expectedMessage.Should().BeTrue();
915+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
916+
.WhoseValue.Should().Contain("0/1");
957917
}
958918

959919
[Fact]
@@ -1989,13 +1949,8 @@ public void should_install_the_expected_version_of_the_dependency()
19891949
[Fact]
19901950
public void should_contain_a_message_that_everything_installed_successfully()
19911951
{
1992-
bool expectedMessage = false;
1993-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
1994-
{
1995-
if (message.Contains("3/3")) expectedMessage = true;
1996-
}
1997-
1998-
expectedMessage.Should().BeTrue();
1952+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
1953+
.WhoseValue.Should().Contain("3/3");
19991954
}
20001955

20011956
[Fact]
@@ -2103,13 +2058,8 @@ public void should_not_upgrade_the_dependency()
21032058
[Fact]
21042059
public void should_contain_a_message_that_it_installed_successfully()
21052060
{
2106-
bool expectedMessage = false;
2107-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
2108-
{
2109-
if (message.Contains("1/1")) expectedMessage = true;
2110-
}
2111-
2112-
expectedMessage.Should().BeTrue();
2061+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
2062+
.WhoseValue.Should().Contain("1/1");
21132063
}
21142064

21152065
[Fact]

src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,8 @@ public void should_not_uninstall_a_package_from_the_lib_directory()
8383
[Fact]
8484
public void should_contain_a_message_that_it_would_have_uninstalled_a_package()
8585
{
86-
bool expectedMessage = false;
87-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
88-
{
89-
if (message.Contains("Would have uninstalled installpackage v1.0.0")) expectedMessage = true;
90-
}
91-
92-
expectedMessage.Should().BeTrue();
86+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
87+
.WhoseValue.Should().Contain("Would have uninstalled installpackage v1.0.0");
9388
}
9489

9590
[Fact]
@@ -126,13 +121,8 @@ public override void Because()
126121
[Fact]
127122
public void should_contain_a_message_that_it_was_unable_to_find_package()
128123
{
129-
bool expectedMessage = false;
130-
foreach (var message in MockLogger.MessagesFor(LogLevel.Error).or_empty_list_if_null())
131-
{
132-
if (message.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package")) expectedMessage = true;
133-
}
134-
135-
expectedMessage.Should().BeTrue();
124+
MockLogger.Messages.Should().ContainKey(LogLevel.Error.to_string())
125+
.WhoseValue.Should().Contain("somethingnonexisting is not installed. Cannot uninstall a non-existent package");
136126
}
137127
}
138128

@@ -389,13 +379,8 @@ public void should_delete_the_rollback()
389379
[Fact]
390380
public void should_contain_a_message_that_it_uninstalled_successfully()
391381
{
392-
bool expectedMessage = false;
393-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
394-
{
395-
if (message.Contains("uninstalled 1/1")) expectedMessage = true;
396-
}
397-
398-
expectedMessage.Should().BeTrue();
382+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
383+
.WhoseValue.Should().Contain("uninstalled 1/1");
399384
}
400385

401386
[Fact]

src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,15 @@ public void should_contain_older_version_in_directory()
8484
[Fact]
8585
public void should_contain_a_message_that_a_new_version_is_available()
8686
{
87-
bool expectedMessage = false;
88-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
89-
{
90-
if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source(s)")) expectedMessage = true;
91-
}
92-
93-
expectedMessage.Should().BeTrue();
87+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
88+
.WhoseValue.Should().Contain("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source(s)");
9489
}
9590

9691
[Fact]
9792
public void should_contain_a_message_that_a_package_can_be_upgraded()
9893
{
99-
bool expectedMessage = false;
100-
foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
101-
{
102-
if (message.Contains("can upgrade 1/1")) expectedMessage = true;
103-
}
104-
105-
expectedMessage.Should().BeTrue();
94+
MockLogger.Messages.Should().ContainKey(LogLevel.Warn.to_string())
95+
.WhoseValue.Should().Contain("can upgrade 1/1");
10696
}
10797

10898
[Fact]

src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public void should_log_a_message()
161161
public void should_log_the_message_we_expect()
162162
{
163163
var messages = MockLogger.MessagesFor(LogLevel.Info);
164-
messages.Should().NotBeEmpty();
165-
messages.Count.Should().Be(1);
164+
messages.Should().NotBeEmpty()
165+
.And.HaveCount(1);
166166
messages[0].Should().Contain("Export would have been with options");
167167
}
168168
}

0 commit comments

Comments
 (0)