Skip to content

Commit

Permalink
(chocolatey#2893) Update references and syntax to FluentAssertions
Browse files Browse the repository at this point in the history
As per the FluentAssertions api, various calls needed to be adjusted,
mostly in the pattern Shouldxxxx() to Should().xxxx()
  • Loading branch information
TheCakeIsNaOH authored and AdmiringWorm committed Jun 6, 2023
1 parent 643df4f commit 5b2b774
Show file tree
Hide file tree
Showing 59 changed files with 2,041 additions and 2,043 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace chocolatey.tests.integration.infrastructure.app.builders
using chocolatey.infrastructure.registration;
using Microsoft.Win32;
using scenarios;
using Should;
using FluentAssertions;

public class ConfigurationBuilderSpecs
{
Expand Down Expand Up @@ -140,31 +140,31 @@ public void ShouldHaveProxyConfiguration()
if (!SystemSet && !ArgumentSet && !ConfigSet &&
!EnvironmentVariableSet)
{
Configuration.Proxy.Location.ShouldEqual(string.Empty);
Configuration.Proxy.Location.Should().Be(string.Empty);
return;
}

if (ArgumentSet)
{
Configuration.Proxy.Location.ShouldEqual(CommandArgumentProxyValue);
Configuration.Proxy.Location.Should().Be(CommandArgumentProxyValue);
return;
}

if (ConfigSet)
{
Configuration.Proxy.Location.ShouldEqual(ConfigurationFileProxyValue);
Configuration.Proxy.Location.Should().Be(ConfigurationFileProxyValue);
return;
}

if (EnvironmentVariableSet)
{
Configuration.Proxy.Location.ShouldEqual(EnvironmentVariableProxyValue);
Configuration.Proxy.Location.Should().Be(EnvironmentVariableProxyValue);
return;
}

if (SystemSet)
{
Configuration.Proxy.Location.ShouldEqual(SystemLevelProxyValue);
Configuration.Proxy.Location.Should().Be(SystemLevelProxyValue);
return;
}
}
Expand Down Expand Up @@ -211,25 +211,25 @@ public void ShouldBypassProxy()
if (!ArgumentSet && !ConfigSet &&
!EnvironmentVariableSet)
{
Configuration.Proxy.BypassList.ShouldEqual(string.Empty);
Configuration.Proxy.BypassList.Should().Be(string.Empty);
return;
}

if (ArgumentSet)
{
Configuration.Proxy.BypassList.ShouldEqual(CommandArgumentProxyValue);
Configuration.Proxy.BypassList.Should().Be(CommandArgumentProxyValue);
return;
}

if (ConfigSet)
{
Configuration.Proxy.BypassList.ShouldEqual(ConfigurationFileProxyValue);
Configuration.Proxy.BypassList.Should().Be(ConfigurationFileProxyValue);
return;
}

if (EnvironmentVariableSet)
{
Configuration.Proxy.BypassList.ShouldEqual(EnvironmentVariableProxyValue);
Configuration.Proxy.BypassList.Should().Be(EnvironmentVariableProxyValue);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace chocolatey.tests.integration.infrastructure.app.services
using chocolatey.infrastructure.services;
using Moq;
using NUnit.Framework;
using Should;
using FluentAssertions;

public class FilesServiceSpecs
{
Expand Down Expand Up @@ -101,7 +101,7 @@ public void Should_log_a_warning_about_locked_files()
[Fact]
public void Should_return_a_special_code_for_locked_files()
{
_result.Files.FirstOrDefault(x => x.Path == _theLockedFile).Checksum.ShouldEqual(ApplicationParameters.HashProviderFileLocked);
_result.Files.FirstOrDefault(x => x.Path == _theLockedFile).Checksum.Should().Be(ApplicationParameters.HashProviderFileLocked);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace chocolatey.tests.integration.infrastructure.commands
using chocolatey.infrastructure.commands;
using chocolatey.infrastructure.filesystem;
using NUnit.Framework;
using Should;
using FluentAssertions;

public class CommandExecutorSpecs
{
Expand Down Expand Up @@ -64,19 +64,19 @@ public override void Because()
[Fact]
public void Should_not_return_an_exit_code_of_zero()
{
result.ShouldNotEqual(0);
result.Should().NotBe(0);
}

[Fact]
public void Should_contain_error_output()
{
errorOutput.ShouldNotBeNull();
errorOutput.Should().NotBeNull();
}

[Fact]
public void Should_message_the_error()
{
errorOutput.ShouldEqual("'bob123123' is not recognized as an internal or external command,operable program or batch file.");
errorOutput.Should().Be("'bob123123' is not recognized as an internal or external command,operable program or batch file.");
}
}

Expand All @@ -102,7 +102,7 @@ public override void Because()
[Fact]
public void Should_have_an_error_message()
{
result.ShouldNotBeNull();
result.Should().NotBeNull();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace chocolatey.tests.integration.infrastructure.cryptography
using System.Security.Cryptography;
using chocolatey.infrastructure.cryptography;
using chocolatey.infrastructure.filesystem;
using Should;
using FluentAssertions;

public class CryptoHashProviderSpecs
{
Expand Down Expand Up @@ -60,7 +60,7 @@ public void Should_provide_the_correct_hash_based_on_a_checksum()
{
var expected = BitConverter.ToString(SHA256.Create().ComputeHash(File.ReadAllBytes(filePath))).Replace("-", string.Empty);

result.ShouldEqual(expected);
result.Should().Be(expected);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace chocolatey.tests.integration.infrastructure.filesystem
using chocolatey.infrastructure.filesystem;
using chocolatey.infrastructure.platforms;
using NUnit.Framework;
using Should;
using FluentAssertions;

public class DotNetFileSystemSpecs
{
Expand Down Expand Up @@ -59,41 +59,39 @@ public override void Because()
[Fact]
public void GetExecutablePath_should_find_existing_executable()
{
FileSystem.GetExecutablePath("cmd").ShouldEqual(
FileSystem.GetExecutablePath("cmd").Should().BeEquivalentTo(
Platform.GetPlatform() == PlatformType.Windows
? "C:\\Windows\\system32\\cmd.exe"
: "cmd",
StringComparer.OrdinalIgnoreCase
);
: "cmd"
);
}

[Fact]
public void GetExecutablePath_should_find_existing_executable_with_extension()
{
FileSystem.GetExecutablePath("cmd.exe").ShouldEqual(
FileSystem.GetExecutablePath("cmd.exe").Should().BeEquivalentTo(
Platform.GetPlatform() == PlatformType.Windows
? "c:\\windows\\system32\\cmd.exe"
: "cmd.exe",
StringComparer.OrdinalIgnoreCase
: "cmd.exe"
);
}

[Fact]
public void GetExecutablePath_should_return_same_value_when_executable_is_not_found()
{
FileSystem.GetExecutablePath("daslakjsfdasdfwea").ShouldEqual("daslakjsfdasdfwea");
FileSystem.GetExecutablePath("daslakjsfdasdfwea").Should().Be("daslakjsfdasdfwea");
}

[Fact]
public void GetExecutablePath_should_return_empty_string_when_value_is_null()
{
FileSystem.GetExecutablePath(null).ShouldEqual(string.Empty);
FileSystem.GetExecutablePath(null).Should().Be(string.Empty);
}

[Fact]
public void GetExecutablePath_should_return_empty_string_when_value_is_empty_string()
{
FileSystem.GetExecutablePath(string.Empty).ShouldEqual(string.Empty);
FileSystem.GetExecutablePath(string.Empty).Should().Be(string.Empty);
}
}

Expand All @@ -120,7 +118,7 @@ public override void Because()
[Fact]
public void GetFiles_should_return_string_array_of_files()
{
FileSystem.GetFiles(ContextPath, "*lipsum*", SearchOption.AllDirectories).ShouldEqual(FileArray);
FileSystem.GetFiles(ContextPath, "*lipsum*", SearchOption.AllDirectories).Should().BeEquivalentTo(FileArray);
}

[Fact]
Expand All @@ -132,8 +130,8 @@ public void GetFiles_should_return_files_that_meet_the_pattern()
var actual = FileSystem.GetFiles(ContextPath, "chocolateyInstall.ps1", SearchOption.AllDirectories).ToList();
FileSystem.DeleteFile(filePath);

actual.ShouldNotBeEmpty();
actual.Count().ShouldEqual(1);
actual.Should().NotBeEmpty();
actual.Count().Should().Be(1);
}

[Fact]
Expand All @@ -147,44 +145,44 @@ public void GetFiles_should_return_files_that_meet_the_pattern_regardless_of_cas
var actual = FileSystem.GetFiles(ContextPath, "chocolateyinstall.ps1", SearchOption.AllDirectories).ToList();
FileSystem.DeleteFile(filePath);

actual.ShouldNotBeEmpty();
actual.Count().ShouldEqual(1);
actual.Should().NotBeEmpty();
actual.Count().Should().Be(1);
}

[Fact]
public void FileExists_should_return_true_if_file_exists()
{
FileSystem.FileExists(TheTestFile).ShouldBeTrue();
FileSystem.FileExists(TheTestFile).Should().BeTrue();
}

[Fact]
public void FileExists_should_return_false_if_file_does_not_exists()
{
FileSystem.FileExists(Path.Combine(ContextPath, "IDontExist.txt")).ShouldBeFalse();
FileSystem.FileExists(Path.Combine(ContextPath, "IDontExist.txt")).Should().BeFalse();
}

[Fact]
public void DirectoryExists_should_return_true_if_directory_exists()
{
FileSystem.DirectoryExists(ContextPath).ShouldBeTrue();
FileSystem.DirectoryExists(ContextPath).Should().BeTrue();
}

[Fact]
public void DirectoryExists_should_return_false_if_directory_does_not_exist()
{
FileSystem.DirectoryExists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "IDontExist")).ShouldBeFalse();
FileSystem.DirectoryExists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "IDontExist")).Should().BeFalse();
}

[Fact]
public void GetFileSize_should_return_correct_file_size()
{
FileSystem.GetFileSize(TheTestFile).ShouldEqual(5377);
FileSystem.GetFileSize(TheTestFile).Should().Be(5377);
}

[Fact]
public void GetDirectories_should_return_a_string_array_with_directories()
{
FileSystem.GetDirectories(ContextPath).ShouldEqual(DirectoryArray);
FileSystem.GetDirectories(ContextPath).Should().BeEquivalentTo(DirectoryArray);
}
}

Expand All @@ -207,7 +205,7 @@ public override void Because()
[Fact]
public void Visible_file_should_now_be_hidden()
{
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.Hidden).ShouldEqual(FileAttributes.Hidden);
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.Hidden).Should().Be(FileAttributes.Hidden);
}

public override void AfterObservations()
Expand All @@ -234,7 +232,7 @@ public override void Because()
[Fact]
public void Readonly_file_should_no_longer_be_readonly()
{
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.ReadOnly).ShouldNotEqual(FileAttributes.ReadOnly);
((FileAttributes)FileSystem.GetFileInfoFor(SourceFile).Attributes & FileAttributes.ReadOnly).Should().NotBe(FileAttributes.ReadOnly);
}
}

Expand All @@ -258,13 +256,13 @@ public override void Because()
[Fact]
public void Move_me_text_file_should_not_exist_in_the_source_path()
{
FileSystem.FileExists(SourceFile).ShouldBeFalse();
FileSystem.FileExists(SourceFile).Should().BeFalse();
}

[Fact]
public void Move_me_text_file_should_exist_in_destination_path()
{
FileSystem.FileExists(DestFile).ShouldBeTrue();
FileSystem.FileExists(DestFile).Should().BeTrue();
}
}

Expand All @@ -291,13 +289,13 @@ public override void Because()
[Fact]
public void Copy_me_text_file_should_exist_in_context_path()
{
FileSystem.FileExists(SourceFile).ShouldBeTrue();
FileSystem.FileExists(SourceFile).Should().BeTrue();
}

[Fact]
public void Move_me_text_file_should_exist_in_destination_path()
{
FileSystem.FileExists(DestFile).ShouldBeTrue();
FileSystem.FileExists(DestFile).Should().BeTrue();
}
}

Expand All @@ -319,7 +317,7 @@ public override void Because()
[Fact]
public void Delete_me_text_file_should_not_exist()
{
FileSystem.FileExists(DeleteFile).ShouldBeFalse();
FileSystem.FileExists(DeleteFile).Should().BeFalse();
}
}

Expand All @@ -338,7 +336,7 @@ public override void Because()
[Fact]
public void Test_directory_should_exist()
{
FileSystem.DirectoryExists(TestDirectory).ShouldBeTrue();
FileSystem.DirectoryExists(TestDirectory).Should().BeTrue();
}
}

Expand All @@ -353,7 +351,7 @@ public override void Because()
[Fact]
public void Should_have_correct_modified_date()
{
FileSystem.GetFileModifiedDate(TheTestFile).ToShortDateString().ShouldEqual(DateTime.Now.AddDays(-1).ToShortDateString());
FileSystem.GetFileModifiedDate(TheTestFile).ToShortDateString().Should().Be(DateTime.Now.AddDays(-1).ToShortDateString());
}
}
}
Expand Down
Loading

0 comments on commit 5b2b774

Please sign in to comment.