Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#2893) Switch from Should to FluentAssertions #2908

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<RootNamespace>chocolatey.tests.integration</RootNamespace>
<AssemblyName>chocolatey.tests.integration</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>7.3</LangVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<OverwriteReadOnlyFiles>true</OverwriteReadOnlyFiles>
Expand Down Expand Up @@ -96,6 +97,9 @@
<Reference Include="Chocolatey.NuGet.Versioning">
<HintPath>..\packages\Chocolatey.NuGet.Versioning.3.2.0\lib\net472\Chocolatey.NuGet.Versioning.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=6.11.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.6.11.0\lib\net47\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
Expand All @@ -111,9 +115,6 @@
<Reference Include="nunit.framework, Version=3.13.3.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.13.3\lib\net40\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Should, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Should.1.1.20\lib\Should.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector, Version=2.8.3.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\packages\SimpleInjector.2.8.3\lib\net45\SimpleInjector.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -207,7 +208,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Analyzer Include="..\packages\FluentAssertions.Analyzers.0.19.1\analyzers\dotnet\cs\FluentAssertions.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
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().BeEmpty();
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().BeEmpty();
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.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 @@ -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,8 @@ namespace chocolatey.tests.integration.infrastructure.filesystem
using chocolatey.infrastructure.filesystem;
using chocolatey.infrastructure.platforms;
using NUnit.Framework;
using Should;
using FluentAssertions;
using FluentAssertions.Extensions;

public class DotNetFileSystemSpecs
{
Expand Down Expand Up @@ -59,41 +60,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().BeEmpty();
}

[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().BeEmpty();
}
}

Expand All @@ -120,7 +119,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 +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.ShouldNotBeEmpty();
actual.Count().ShouldEqual(1);
actual.Should().ContainSingle();
}

[Fact]
Expand All @@ -147,44 +145,43 @@ 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().ContainSingle();
}

[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 +204,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).Should().HaveFlag(FileAttributes.Hidden);
}

public override void AfterObservations()
Expand All @@ -234,7 +231,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).Should().NotHaveFlag(FileAttributes.ReadOnly);
}
}

Expand All @@ -258,13 +255,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 +288,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 +316,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 +335,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 +350,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).Should().BeCloseTo(1.Days().Before(DateTime.Now), 5.Seconds());
}
}
}
Expand Down
Loading