Skip to content

Commit

Permalink
(chocolatey#2893) Update tests to use to FluentAssertions style
Browse files Browse the repository at this point in the history
This updates tests to use new ways of writing assertions that are available in
FluentAssertions but where not in Should
  • Loading branch information
TheCakeIsNaOH authored and AdmiringWorm committed Jun 6, 2023
1 parent 51efab5 commit c853166
Show file tree
Hide file tree
Showing 27 changed files with 1,124 additions and 2,225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void ShouldHaveProxyConfiguration()
if (!SystemSet && !ArgumentSet && !ConfigSet &&
!EnvironmentVariableSet)
{
Configuration.Proxy.Location.Should().Be(string.Empty);
Configuration.Proxy.Location.Should().BeEmpty();
return;
}

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

Expand Down
Original file line number Diff line number Diff line change
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.Should().Be(ApplicationParameters.HashProviderFileLocked);
_result.Files.Should().ContainSingle(x => x.Path == _theLockedFile).Which.Checksum.Should().Be(ApplicationParameters.HashProviderFileLocked);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace chocolatey.tests.integration.infrastructure.filesystem
using chocolatey.infrastructure.platforms;
using NUnit.Framework;
using FluentAssertions;
using FluentAssertions.Extensions;

public class DotNetFileSystemSpecs
{
Expand Down Expand Up @@ -85,13 +86,13 @@ public void GetExecutablePath_should_return_same_value_when_executable_is_not_fo
[Fact]
public void GetExecutablePath_should_return_empty_string_when_value_is_null()
{
FileSystem.GetExecutablePath(null).Should().Be(string.Empty);
FileSystem.GetExecutablePath(null).Should().BeEmpty();
}

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

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

actual.Should().NotBeEmpty();
actual.Count().Should().Be(1);
actual.Should().ContainSingle();
}

[Fact]
Expand All @@ -145,8 +145,7 @@ 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.Should().NotBeEmpty();
actual.Count().Should().Be(1);
actual.Should().ContainSingle();
}

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

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

Expand Down Expand Up @@ -351,7 +350,7 @@ public override void Because()
[Fact]
public void Should_have_correct_modified_date()
{
FileSystem.GetFileModifiedDate(TheTestFile).ToShortDateString().Should().Be(DateTime.Now.AddDays(-1).ToShortDateString());
FileSystem.GetFileModifiedDate(TheTestFile).Should().BeCloseTo(1.Days().Before(DateTime.Now), 5.Seconds());
}
}
}
Expand Down
Loading

0 comments on commit c853166

Please sign in to comment.