diff --git a/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs index 683ae280ed..f8a5555b27 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs @@ -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; } @@ -211,7 +211,7 @@ public void ShouldBypassProxy() if (!ArgumentSet && !ConfigSet && !EnvironmentVariableSet) { - Configuration.Proxy.BypassList.Should().Be(string.Empty); + Configuration.Proxy.BypassList.Should().BeEmpty(); return; } diff --git a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs index 37c167a4fc..65c37ccd95 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs @@ -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); } } } diff --git a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs index 4495980119..af2d2f778a 100644 --- a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -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 { @@ -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(); } } @@ -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] @@ -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] @@ -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() @@ -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); } } @@ -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()); } } } diff --git a/src/chocolatey.tests.integration/scenarios/InfoScenarios.cs b/src/chocolatey.tests.integration/scenarios/InfoScenarios.cs index 0b0e3a8649..ca6c30e645 100644 --- a/src/chocolatey.tests.integration/scenarios/InfoScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InfoScenarios.cs @@ -83,8 +83,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage 1.0.0"); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0")); } [Fact] @@ -93,15 +93,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.1.0.0" + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -122,8 +122,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage 1.0.0"); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0")); } [Fact] @@ -132,15 +132,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.1.0.0" + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -161,8 +161,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage 1.0.0"); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0")); } [Fact] @@ -171,15 +171,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.1.0.0" + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -202,8 +202,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage {0}".FormatWith(NormalizedVersion)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage {0}".FormatWith(NormalizedVersion))); } [Fact] @@ -212,15 +212,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.{0}".FormatWith(NonNormalizedVersion) + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -245,8 +245,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage {0}".FormatWith(NormalizedVersion)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage {0}".FormatWith(NormalizedVersion))); } [Fact] @@ -255,15 +255,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.{0}".FormatWith(NonNormalizedVersion) + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -288,8 +288,8 @@ public override void Context() [Fact] public void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage {0}".FormatWith(NormalizedVersion)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage {0}".FormatWith(NormalizedVersion))); } [Fact] @@ -298,15 +298,15 @@ public void Should_log_package_information() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.{0}".FormatWith(NonNormalizedVersion) + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -336,8 +336,8 @@ public override void Because() [Fact] public new void Should_log_standalone_header_with_package_name_and_version() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain("installpackage 1.0.0"); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0")); } [Fact] @@ -346,15 +346,15 @@ public override void Because() var lastWriteDate = File.GetLastWriteTimeUtc(Path.Combine("PackageOutput", "installpackage.1.0.0" + NuGetConstants.PackageExtension)) .ToShortDateString(); - MockLogger.Messages.Keys.Should().Contain(LogLevel.Info.ToStringSafe()); - MockLogger.Messages[LogLevel.Info.ToStringSafe()].Should().Contain(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(" Title: installpackage | Published: {0}\r\n Number of Downloads: n/a | Downloads for this version: n/a\r\n Package url\r\n Chocolatey Package Source: n/a\r\n Tags: installpackage admin\r\n Software Site: n/a\r\n Software License: n/a\r\n Summary: __REPLACE__\r\n Description: __REPLACE__\r\n".FormatWith(lastWriteDate))); } [Fact] public new void Should_log_package_count_as_warning() { - MockLogger.Messages.Keys.Should().Contain(LogLevel.Warn.ToStringSafe()); - MockLogger.Messages[LogLevel.Warn.ToStringSafe()].Should().Contain("1 packages found."); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1 packages found.")); } } @@ -372,7 +372,7 @@ public override void Context() [Fact] public void Should_show_only_one_result() { - Results.Count.Should().Be(1, "Expected 1 package to be returned!"); + Results.Should().ContainSingle("Expected 1 package to be returned!"); } [Fact] @@ -422,7 +422,7 @@ public override void Context() [Fact] public void Should_show_only_one_result() { - Results.Count.Should().Be(1, "Expected 1 package to be returned!"); + Results.Should().ContainSingle( "Expected 1 package to be returned!"); } [Fact] @@ -478,7 +478,7 @@ public override void Context() [Fact] public void Should_show_only_one_result() { - Results.Count.Should().Be(1, "Expected 1 package to be returned!"); + Results.Should().ContainSingle( "Expected 1 package to be returned!"); } [Fact] diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index fb2c89fce8..a6b5a36cb3 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -33,6 +33,7 @@ namespace chocolatey.tests.integration.scenarios using NuGet.Packaging; using NUnit.Framework; using FluentAssertions; + using FluentAssertions.Execution; using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; public class InstallScenarios @@ -83,13 +84,8 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("would have used NuGet to install packages")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()) + .WhoseValue.Should().Contain(m => m.Contains("would have used NuGet to install packages")); } [Fact] @@ -97,13 +93,17 @@ public void Should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_ [Platform(Exclude = "Mono")] public void Should_contain_a_message_that_it_would_have_run_a_powershell_script() { - MockLogger.ContainsMessage("chocolateyinstall.ps1", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("chocolateyinstall.ps1")); } [Fact] public void Should_not_contain_a_message_that_it_would_have_run_powershell_modification_script() { - MockLogger.ContainsMessage("chocolateyBeforeModify.ps1", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("chocolateyBeforeModify.ps1")); } } @@ -132,25 +132,16 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("would have used NuGet to install packages")) expectedMessage = true; - } + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()) + .WhoseValue.Should().Contain(m => m.Contains("would have used NuGet to install packages")); - expectedMessage.Should().BeTrue(); } [Fact] public void Should_contain_a_message_that_it_was_unable_to_find_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("somethingnonexisting not installed. The package was not found with the source(s) listed")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToString()) + .WhoseValue.Should().Contain(m => m.Contains("somethingnonexisting not installed. The package was not found with the source(s) listed")); } } @@ -196,7 +187,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be(TestVersion()); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be(TestVersion()); } } @@ -268,15 +259,9 @@ public void Should_have_a_console_shim_that_is_set_for_non_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? False")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI false message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? False"), "GUI false message not found"); } [Fact] @@ -295,27 +280,17 @@ public void Should_have_a_graphical_shim_that_is_set_for_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? True")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI true message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? True"), "GUI true message not found"); } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Warn.ToString()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -355,7 +330,9 @@ public void Should_have_executed_chocolateyInstall_script() { var message = "installpackage v{0} has been installed".FormatWith(TestVersion()); - MockLogger.ContainsMessage(message, LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Info.ToString()) + .WhoseValue.Should().Contain(m => m.Contains(message)); } protected string TestVersion() @@ -440,89 +417,55 @@ public void Should_install_the_dependency_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_installed_4_out_of_5_packages_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("5/6")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("5/6")); } [Fact] public void Should_contain_a_message_that_upgradepackage_with_an_expected_specified_version_was_installed() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("upgradepackage v1.0.0")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage v1.0.0")); } [Fact] public void Should_have_a_successful_package_result_for_all_but_expected_missing_package() { - foreach (var packageResult in Results) - { - if (packageResult.Value.Name.IsEqualTo("missingpackage")) continue; - - packageResult.Value.Success.Should().BeTrue(); - } + Results.Where(r => !r.Value.Name.IsEqualTo("missingpackage")) + .Should().AllSatisfy(p => p.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_a_successful_package_result_for_missing_package() { - foreach (var packageResult in Results) - { - if (!packageResult.Value.Name.IsEqualTo("missingpackage")) continue; - - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().Contain(r => r.Value.Name.IsEqualTo("missingpackage")) + .Which.Value.Success.Should().BeFalse(); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_specify_config_file_is_being_used_in_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("Installing from config file:")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Installing from config file:")); } [Fact] public void Should_print_out_package_from_config_file_in_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("installpackage")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage")); } } @@ -556,35 +499,23 @@ public void Should_still_have_the_expected_version_of_the_package_installed() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_any_packages() { - bool installWarning = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installWarning = true; - } - - installWarning.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] public void Should_contain_a_message_about_force_to_reinstall() { - bool installWarning = false; - foreach (var messageType in MockLogger.Messages.OrEmpty()) - { - foreach (var message in messageType.Value) - { - if (message.Contains("Use --force to reinstall")) installWarning = true; - } - } - - installWarning.Should().BeTrue(); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Use --force to reinstall")); } [Fact] @@ -641,7 +572,7 @@ public void Should_install_the_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -663,13 +594,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -757,13 +683,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_message_that_it_was_unsuccessful() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -834,7 +755,7 @@ public void Should_reinstall_the_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -851,13 +772,8 @@ public void Should_not_be_able_delete_the_rollback() [Fact] public void Should_contain_a_message_that_it_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -934,7 +850,7 @@ public void Should_still_have_the_package_installed_with_the_expected_version_of var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -949,13 +865,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_message_that_it_was_unable_to_reinstall_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1004,13 +915,8 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_did_not_install_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1034,31 +940,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("The package was not found")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("The package was not found"))); } [Fact] @@ -1095,13 +986,8 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_a_package() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1125,31 +1011,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("The package was not found")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("The package was not found"))); } } @@ -1190,13 +1061,8 @@ public void Should_put_a_package_in_the_lib_bad_directory() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_a_package() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1220,31 +1086,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("chocolateyInstall.ps1")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("chocolateyInstall.ps1"))); } } @@ -1294,13 +1145,8 @@ public void Should_install_the_expected_version_of_the_package() [Fact] public void Should_contain_a_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -1374,13 +1220,8 @@ public void Should_put_a_package_in_the_lib_bad_directory() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_a_package() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1404,31 +1245,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("chocolateyInstall.ps1")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("chocolateyInstall.ps1"))); } } @@ -1479,56 +1305,39 @@ public void Should_install_the_expected_version_of_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("3/3")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_a_version_of_one_dot_zero_dot_zero() { - foreach (var packageResult in Results) - { - packageResult.Value.Version.Should().Be("1.0.0"); - } + Results.Should().AllSatisfy(r => r.Value.Version.Should().Be("1.0.0")); } } @@ -1575,7 +1384,7 @@ public void Should_reinstall_the_exact_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1593,56 +1402,39 @@ public void Should_not_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_it_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_a_version_of_one_dot_zero_dot_zero() { - foreach (var packageResult in Results) - { - packageResult.Value.Version.Should().Be("1.0.0"); - } + Results.Should().AllSatisfy(r => r.Value.Version.Should().Be("1.0.0")); } } @@ -1696,7 +1488,7 @@ public void Should_reinstall_the_exact_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1723,7 +1515,7 @@ public void Should_reinstall_the_floating_dependency_with_the_latest_version_tha var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1733,47 +1525,33 @@ public void Should_reinstall_the_exact_same_version_of_the_exact_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("3/3")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -1821,7 +1599,7 @@ public void Should_reinstall_the_exact_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1839,7 +1617,7 @@ public void Should_not_touch_the_floating_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1849,47 +1627,33 @@ public void Should_not_touch_the_exact_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -1938,7 +1702,7 @@ public void Should_reinstall_the_exact_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1959,40 +1723,26 @@ public void Should_remove_the_exact_dependency() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2029,78 +1779,42 @@ public void Should_not_install_the_dependency_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_any_packages() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => m.MessageType == ResultType.Error)); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("Unable to resolve dependency 'isdependency")) errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("Unable to resolve dependency 'isdependency"))); } } @@ -2142,7 +1856,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -2157,13 +1871,8 @@ public void Should_not_install_the_dependency_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -2232,7 +1941,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.6.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.6.0"); } } @@ -2250,47 +1959,33 @@ public void Should_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("3/3")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2322,40 +2017,26 @@ public void Should_not_install_the_package_in_the_lib_directory() [Fact] public void Should_contain_a_message_that_is_was_unable_to_install_any_packages() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2400,47 +2081,33 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.6.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.6.0"); } } [Fact] public void Should_contain_a_message_that_it_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2477,85 +2144,49 @@ public void Should_not_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_any_packages() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => m.MessageType == ResultType.Error)); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("Unable to resolve dependency 'isdependency")) errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("Unable to resolve dependency 'isdependency"))); } } @@ -2601,47 +2232,33 @@ public void Should_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.1"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.1"); } } [Fact] public void Should_contain_a_message_that_it_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("installed 2/2")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installed 2/2")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2687,7 +2304,7 @@ public void Should_not_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2697,66 +2314,40 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_it_was_unable_to_install_any_packages() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("installed 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installed 0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => m.MessageType == ResultType.Error)); } } @@ -2799,66 +2390,40 @@ public void Should_not_downgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_it_was_unable_to_install_any_packages() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("installed 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installed 0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => m.MessageType == ResultType.Error)); } } @@ -2916,7 +2481,7 @@ public void Should_install_the_expected_version_of_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "childdependencywithlooserversiondependency", "childdependencywithlooserversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2926,47 +2491,33 @@ public void Should_install_the_expected_version_of_the_constrained_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_installed_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("3/3")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -3323,20 +2874,15 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -3398,13 +2944,14 @@ public override void Because() [Fact] public void Should_have_no_sources_enabled_result() { - MockLogger.ContainsMessage("Installation was NOT successful. There are no sources enabled for", LogLevel.Error).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Installation was NOT successful. There are no sources enabled for")); } [Fact] public void Should_not_install_any_packages() { - Results.Count().Should().Be(0); + Results.Should().BeEmpty(); } } @@ -3439,7 +2986,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3473,13 +3020,8 @@ public void Should_install_hook_scripts_to_folder() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -3552,7 +3094,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3624,15 +3166,9 @@ public void Should_have_a_console_shim_that_is_set_for_non_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? False")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI false message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? False"), "GUI false message not found"); } [Fact] @@ -3651,27 +3187,16 @@ public void Should_have_a_graphical_shim_that_is_set_for_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? True")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI true message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? True"), "GUI true message not found"); } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -3709,7 +3234,8 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script() { - MockLogger.ContainsMessage("installpackage v1.0.0 has been installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage v1.0.0 has been installed")); } [Fact] @@ -3717,7 +3243,8 @@ public void Should_have_executed_chocolateyInstall_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_all_hook_script() { - MockLogger.ContainsMessage("pre-install-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3725,7 +3252,8 @@ public void Should_have_executed_pre_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_all_hook_script() { - MockLogger.ContainsMessage("post-install-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3733,7 +3261,8 @@ public void Should_have_executed_post_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_installpackage_hook_script() { - MockLogger.ContainsMessage("pre-install-installpackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-installpackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3741,7 +3270,8 @@ public void Should_have_executed_pre_installpackage_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_installpackage_hook_script() { - MockLogger.ContainsMessage("post-install-installpackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-installpackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3749,7 +3279,8 @@ public void Should_have_executed_post_installpackage_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_uninstall_hook_script() { - MockLogger.ContainsMessage("post-uninstall-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("post-uninstall-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3757,7 +3288,8 @@ public void Should_not_have_executed_uninstall_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_upgradepackage_hook_script() { - MockLogger.ContainsMessage("pre-install-upgradepackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-install-upgradepackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -3765,7 +3297,8 @@ public void Should_not_have_executed_upgradepackage_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_beforemodify_hook_script() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for installpackage 1.0.0")); } } @@ -3808,7 +3341,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3880,15 +3413,9 @@ public void Should_have_a_console_shim_that_is_set_for_non_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? False")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI false message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? False"), "GUI false message not found"); } [Fact] @@ -3907,27 +3434,16 @@ public void Should_have_a_graphical_shim_that_is_set_for_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? True")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI true message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? True"), "GUI true message not found"); } [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -3965,7 +3481,8 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero() [Platform(Exclude = "Mono")] public void Should_not_have_executed_chocolateyInstall_script() { - MockLogger.ContainsMessage("portablepackage v1.0.0 has been installed", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("portablepackage v1.0.0 has been installed")); } [Fact] @@ -3973,7 +3490,8 @@ public void Should_not_have_executed_chocolateyInstall_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_all_hook_script() { - MockLogger.ContainsMessage("pre-install-all.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-all.ps1 hook ran for portablepackage 1.0.0")); } [Fact] @@ -3981,7 +3499,8 @@ public void Should_have_executed_pre_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_all_hook_script() { - MockLogger.ContainsMessage("post-install-all.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-all.ps1 hook ran for portablepackage 1.0.0")); } [Fact] @@ -3989,7 +3508,8 @@ public void Should_have_executed_post_all_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_uninstall_hook_script() { - MockLogger.ContainsMessage("post-uninstall-all.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("post-uninstall-all.ps1 hook ran for portablepackage 1.0.0")); } [Fact] @@ -3997,7 +3517,8 @@ public void Should_not_have_executed_uninstall_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_upgradepackage_hook_script() { - MockLogger.ContainsMessage("pre-install-upgradepackage.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-install-upgradepackage.ps1 hook ran for portablepackage 1.0.0")); } [Fact] @@ -4005,7 +3526,8 @@ public void Should_not_have_executed_upgradepackage_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_beforemodify_hook_script() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for portablepackage 1.0.0")); } } @@ -4074,13 +3596,8 @@ public void Should_not_create_an_hooks_folder_for_the_package() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -4118,7 +3635,8 @@ public void Should_have_a_version_of_two_dot_zero_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_reported_package_installed() { - MockLogger.ContainsMessage("isdependency 2.0.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("isdependency 2.0.0 Installed")); } } @@ -4142,10 +3660,7 @@ public override void Because() [Fact] public void Should_not_report_success() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] @@ -4159,30 +3674,22 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_report_package_not_found() { - foreach (var packageResult in Results) - { - var message = packageResult.Value.Messages.First(); - message.MessageType.Should().Be(ResultType.Error); - message.Message.Should().StartWith("non-existing not installed. The package was not found with the source(s) listed."); - } + Results.Should().AllSatisfy(r => r.Value.Messages.First().MessageType.Should().Be(ResultType.Error)) + .And.AllSatisfy(p => + p.Value.Messages.First().Message.Should() + .StartWith("non-existing not installed. The package was not found with the source(s) listed.")); } } @@ -4229,10 +3736,7 @@ public void Should_install_a_package_in_the_lib_directory() [Fact] public void Should_install_lower_version_of_package() { - foreach (var packageResult in Results) - { - packageResult.Value.Version.Should().Be("1.0.0"); - } + Results.Should().AllSatisfy(r => r.Value.Version.Should().Be("1.0.0")); } [Fact] @@ -4251,28 +3755,19 @@ public void Should_have_installed_expected_version_in_lib_directory() [Fact] public void Should_not_have_inconclusive_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_success_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } } @@ -4327,37 +3822,25 @@ public void Should_have_installed_expected_version_in_lib_directory() [Fact] public void Should_install_lower_version_of_package() { - foreach (var packageResult in Results) - { - packageResult.Value.Version.Should().Be("1.0.0"); - } + Results.Should().AllSatisfy(r => r.Value.Version.Should().Be("1.0.0")); } [Fact] public void Should_not_have_inconclusive_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_success_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } } @@ -4441,28 +3924,19 @@ public void Should_report_installed_version_of_package(string name, string versi [Fact] public void Should_not_have_inconclusive_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_success_package_results() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } } @@ -4510,7 +3984,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -4533,13 +4007,8 @@ public void Should_not_create_an_hooks_folder_for_the_package() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -4577,7 +4046,8 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script() { - MockLogger.ContainsMessage("UpperCase 1.0.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("UpperCase 1.0.0 Installed")); } } @@ -4618,7 +4088,7 @@ public void Should_install_the_expected_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -4641,24 +4111,15 @@ public void Should_not_create_an_hooks_folder_for_the_package() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] public void Should_contain_a_warning_message_about_unsupported_elements() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("Issues found with nuspec elements")) upgradeMessage = true; - } - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Issues found with nuspec elements")); } [Fact] @@ -4696,7 +4157,8 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script() { - MockLogger.ContainsMessage("unsupportedelements 1.0.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("unsupportedelements 1.0.0 Installed")); } } @@ -4763,13 +4225,8 @@ public void Should_not_create_an_hooks_folder_for_the_package() [Fact] public void Should_contain_a_warning_message_that_it_installed_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -4799,7 +4256,7 @@ public void Config_should_match_package_result_name() [Fact] public void Result_should_have_the_correct_version() { - _packageResult.Version.Should().Be(NonNormalizedVersion); + _packageResult.Version.Should().Be(NormalizedVersion); } [Fact] @@ -4807,9 +4264,10 @@ public void Result_should_have_the_correct_version() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script() { - var message = "installpackage v{0} has been installed".FormatWith(NonNormalizedVersion); + var message = "installpackage v{0} has been installed".FormatWith(NormalizedVersion); - MockLogger.ContainsMessage(message, LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(message)); } [Fact] @@ -4864,15 +4322,9 @@ public void Should_have_a_console_shim_that_is_set_for_non_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? False")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI false message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? False"), "GUI false message not found"); } [Fact] @@ -4891,15 +4343,9 @@ public void Should_have_a_graphical_shim_that_is_set_for_gui_access() stdErrAction: (s, e) => messages.Add(e.Data) ); - var messageFound = false; - - foreach (var message in messages.OrEmpty()) - { - if (string.IsNullOrWhiteSpace(message)) continue; - if (message.Contains("is gui? True")) messageFound = true; - } - - messageFound.Should().BeTrue("GUI true message not found"); + messages.Should() + .NotBeNullOrEmpty() + .And.Contain(m => m.Contains("is gui? True"), "GUI true message not found"); } } @@ -4984,7 +4430,7 @@ public void Should_install_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".FormatWith(TargetPackageName)); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } @@ -4994,14 +4440,15 @@ public void Should_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".FormatWith(DependencyName)); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_installed_successfully() { - MockLogger.ContainsMessage("installed 2/2", LogLevel.Warn).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installed 2/2")); } [Fact] @@ -5009,7 +4456,8 @@ public void Should_contain_a_message_that_everything_installed_successfully() [Platform(Exclude = "Mono")] public void Should_not_run_target_package_beforeModify_for_upgraded_version() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "2.0.0"))); } [Fact] @@ -5017,7 +4465,8 @@ public void Should_not_run_target_package_beforeModify_for_upgraded_version() [Platform(Exclude = "Mono")] public void Should_run_already_installed_dependency_package_beforeModify() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"))); } [Fact] @@ -5025,34 +4474,26 @@ public void Should_run_already_installed_dependency_package_beforeModify() [Platform(Exclude = "Mono")] public void Should_not_run_dependency_package_beforeModify_for_upgraded_version() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "2.0.0"))); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } } diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index d0a838c3e8..4398502acb 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -22,6 +22,7 @@ namespace chocolatey.tests.integration.scenarios using chocolatey.infrastructure.results; using NuGet.Configuration; using FluentAssertions; + using FluentAssertions.Execution; public class ListScenarios { @@ -80,10 +81,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -138,8 +143,9 @@ public void Should_contain_packages_and_versions_with_a_pipe_between_them() [Fact] public void Should_only_have_messages_related_to_package_information() { - var count = MockLogger.MessagesFor(LogLevel.Info).OrEmpty().Count(); - count.Should().Be(2); + MockLogger.Messages.Should() + .ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().HaveCount(2); } [Fact] @@ -157,10 +163,7 @@ public void Should_not_contain_a_summary() [Fact] public void Should_not_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeFalse(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeFalse(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeFalse(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeFalse(); + MockLogger.Messages.Should().NotContainKey(LogLevel.Debug.ToStringSafe()); } } @@ -241,10 +244,17 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + using (new AssertionScope()) + { + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); + } } } } diff --git a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs index 0eb37f7c9a..c79b3b7204 100644 --- a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs @@ -29,6 +29,7 @@ namespace chocolatey.tests.integration.scenarios using NUnit.Framework; using FluentAssertions; + using FluentAssertions.Execution; public class PackScenarios { @@ -154,9 +155,13 @@ public override void AfterObservations() public void Generated_package_should_be_in_current_directory() { var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(2); - infos[0].Should().Be("Attempting to build package from 'myPackage.nuspec'."); - infos[1].Should().Be(string.Concat("Successfully created package '", PackagePath, "'")); + + using (new AssertionScope()) + { + infos.Should().HaveCount(2); + infos.Should().HaveElementAt(0, "Attempting to build package from 'myPackage.nuspec'."); + infos.Should().HaveElementAt(1, string.Concat("Successfully created package '", PackagePath, "'")); + } FileAssert.Exists(PackagePath); } @@ -426,9 +431,13 @@ public override void Because() public void Property_settings_should_be_logged_as_debug_messages() { var messages = MockLogger.MessagesFor(LogLevel.Debug); - messages.Count.Should().Be(2); - messages.Should().ContainEquivalentOf("Setting property 'commitId': 1234abcd"); - messages.Should().ContainEquivalentOf("Setting property 'version': 0.1.0"); + + using (new AssertionScope()) + { + messages.Should().HaveCount(2); + messages.Should().ContainEquivalentOf("Setting property 'commitId': 1234abcd"); + messages.Should().ContainEquivalentOf("Setting property 'version': 0.1.0"); + } } } diff --git a/src/chocolatey.tests.integration/scenarios/PinScenarios.cs b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs index d7d910d12e..51ac7baa05 100644 --- a/src/chocolatey.tests.integration/scenarios/PinScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs @@ -31,6 +31,7 @@ namespace chocolatey.tests.integration.scenarios using NuGet.Configuration; using FluentAssertions; + using Moq; public class PinScenarios { @@ -83,9 +84,9 @@ public override void Because() [Fact] public void Should_not_contain_list_results() { - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Info).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Warn).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Error).Should().BeFalse(); + MockLogger.Messages.Should() + .NotContainKeys(new string[] + { LogLevel.Info.ToStringSafe(), LogLevel.Warn.ToStringSafe(), LogLevel.Error.ToStringSafe() }); } [Fact] @@ -115,9 +116,11 @@ public override void Because() [Fact] public void Should_not_contain_list_results() { - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Info).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Warn).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Error).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0")); + MockLogger.Messages.Should() + .NotContainKeys(new string[] + { LogLevel.Warn.ToStringSafe(), LogLevel.Error.ToStringSafe() }); } [Fact] @@ -149,9 +152,11 @@ public override void Because() [Fact] public void Should_not_contain_list_results() { - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Info).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Warn).Should().BeFalse(); - MockLogger.ContainsMessage("upgradepackage 1.0.0", LogLevel.Error).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0")); + MockLogger.Messages.Should() + .NotContainKeys(new string[] + { LogLevel.Warn.ToStringSafe(), LogLevel.Error.ToStringSafe() }); } [Fact] diff --git a/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs b/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs index 8f435677e8..4ca26e3f2f 100644 --- a/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/SearchScenarios.cs @@ -74,7 +74,7 @@ public override void Because() [Fact] public void Should_only_pick_up_package_from_highest_priority() { - Results.Count.Should().Be(1); + Results.Should().ContainSingle(); Results[0].Name.Should().Be("upgradepackage"); Results[0].Version.Should().Be("1.0.0"); } @@ -111,7 +111,7 @@ public override void Because() [Fact] public void Should_only_pick_up_package_from_highest_priority() { - Results.Count.Should().Be(2); + Results.Should().HaveCount(2); Results[0].Name.Should().Be("upgradepackage"); Results[0].Version.Should().Be("1.1.1-beta"); Results[1].Name.Should().Be("upgradepackage"); @@ -151,7 +151,7 @@ public override void Because() [Fact] public void Should_pick_up_packages_from_all_feeds_except_those_with_same_name() { - Results.Count.Should().Be(4); + Results.Should().HaveCount(4); Results[0].Name.Should().Be("conflictingdependency"); Results[0].Version.Should().Be("2.0.0"); Results[1].Name.Should().Be("hasdependency"); @@ -200,10 +200,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -242,10 +246,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -291,10 +299,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -351,10 +363,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -375,13 +391,14 @@ public override void Because() [Fact] public void Should_have_no_sources_enabled_result() { - MockLogger.ContainsMessage("Unable to search for packages when there are no sources enabled for", LogLevel.Error).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Unable to search for packages when there are no sources enabled for")); } [Fact] public void Should_not_list_any_packages() { - Results.Count().Should().Be(0); + Results.Should().BeEmpty(); } } @@ -413,7 +430,7 @@ public void Should_not_error() [Fact] public void Should_find_exactly_one_result() { - Results.Count.Should().Be(1); + Results.Should().ContainSingle(); } [Fact] @@ -437,10 +454,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -474,7 +495,7 @@ public void Should_not_error() [Fact] public void Should_not_have_any_results() { - Results.Count.Should().Be(0); + Results.Should().BeEmpty(); } [Fact] @@ -492,10 +513,14 @@ public void Should_contain_a_summary() [Fact] public void Should_contain_debugging_messages() { - MockLogger.ContainsMessage("Searching for package information", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Running list with the following filter", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("Start of List", LogLevel.Debug).Should().BeTrue(); - MockLogger.ContainsMessage("End of List", LogLevel.Debug).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Searching for package information")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Running list with the following filter")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Start of List")); + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("End of List")); } } @@ -528,7 +553,7 @@ public void Should_not_error() [Fact] public void Should_find_two_results() { - Results.Count.Should().Be(2); + Results.Should().HaveCount(2); } [Fact] @@ -576,7 +601,7 @@ public void Should_not_error() [Fact] public void Should_find_three_results() { - Results.Count.Should().Be(3); + Results.Should().HaveCount(3); } [Fact] diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index 3a36ba084f..b010756ee9 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -83,13 +83,8 @@ public void Should_not_uninstall_a_package_from_the_lib_directory() [Fact] public void Should_contain_a_message_that_it_would_have_uninstalled_a_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("Would have uninstalled installpackage v1.0.0")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Would have uninstalled installpackage v1.0.0")); } [Fact] @@ -126,13 +121,8 @@ public override void Because() [Fact] public void Should_contain_a_message_that_it_was_unable_to_find_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package")); } } @@ -193,13 +183,8 @@ public void Should_delete_any_files_created_during_the_install() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -231,7 +216,8 @@ public void Config_should_match_package_result_name() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script() { - MockLogger.ContainsMessage("installpackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0 Before Modification")); } [Fact] @@ -239,7 +225,8 @@ public void Should_have_executed_chocolateyBeforeModify_script() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyUninstall_script() { - MockLogger.ContainsMessage("installpackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0 Uninstalled")); } } @@ -294,13 +281,8 @@ public void Should_delete_a_shim_for_graphical_in_the_bin_directory() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -389,13 +371,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_message_that_it_uninstalled_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("uninstalled 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("uninstalled 1/1")); } [Fact] @@ -476,13 +453,8 @@ public void Should_not_have_deleted_the_rollback_on_server() [Fact] public void Should_contain_a_message_that_it_uninstalled_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("uninstalled 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("uninstalled 1/1")); } [Fact] @@ -567,29 +539,15 @@ public void Should_keep_locked_file_in_directory() [Fact] public void Should_contain_a_message_about_not_all_files_are_removed() { - bool expectedMessage = false; - - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("Unable to delete all existing package files. There will be leftover files requiring manual cleanup")) - { - expectedMessage = true; - } - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Unable to delete all existing package files. There will be leftover files requiring manual cleanup")); } [Fact] public void Should_contain_a_message_that_it_was_not_able_to_uninstall() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("uninstalled 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("uninstalled 0/1")); } [Fact] @@ -678,13 +636,8 @@ public void Should_delete_a_shim_for_graphical_in_the_bin_directory() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -779,13 +732,8 @@ public void Should_delete_a_shim_for_graphical_in_the_bin_directory() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -888,13 +836,8 @@ public void Should_delete_a_shim_for_graphical_in_the_bin_directory() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -941,25 +884,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_it_was_unable_to_find_package() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("somethingnonexisting is not installed. Cannot uninstall a non-existent package")); } [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -983,16 +916,7 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } } @@ -1048,13 +972,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_install_a_package() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -1078,31 +997,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("chocolateyUninstall.ps1")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("chocolateyUninstall.ps1"))); } } @@ -1144,13 +1048,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -1250,13 +1149,8 @@ public void Should_delete_any_files_created_during_the_install() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -1288,7 +1182,8 @@ public void Config_should_match_package_result_name() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script() { - MockLogger.ContainsMessage("installpackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0 Before Modification")); } [Fact] @@ -1296,7 +1191,8 @@ public void Should_have_executed_chocolateyBeforeModify_script() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyUninstall_script() { - MockLogger.ContainsMessage("installpackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage 1.0.0 Uninstalled")); } [Fact] @@ -1304,7 +1200,8 @@ public void Should_have_executed_chocolateyUninstall_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_all_hook_script() { - MockLogger.ContainsMessage("pre-uninstall-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-uninstall-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1312,7 +1209,8 @@ public void Should_have_executed_pre_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_all_hook_script() { - MockLogger.ContainsMessage("post-uninstall-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-uninstall-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1320,7 +1218,8 @@ public void Should_have_executed_post_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_installpackage_hook_script() { - MockLogger.ContainsMessage("pre-uninstall-installpackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-uninstall-installpackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1328,7 +1227,8 @@ public void Should_have_executed_pre_installpackage_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_installpackage_hook_script() { - MockLogger.ContainsMessage("post-uninstall-installpackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-uninstall-installpackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1336,7 +1236,8 @@ public void Should_have_executed_post_installpackage_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_upgradepackage_hook_script() { - MockLogger.ContainsMessage("pre-uninstall-upgradepackage.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-uninstall-upgradepackage.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1344,7 +1245,8 @@ public void Should_not_have_executed_upgradepackage_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_beforemodify_hook_script() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for installpackage 1.0.0")); } [Fact] @@ -1352,7 +1254,8 @@ public void Should_have_executed_pre_beforemodify_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_beforemodify_hook_script() { - MockLogger.ContainsMessage("post-beforemodify-all.ps1 hook ran for installpackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-beforemodify-all.ps1 hook ran for installpackage 1.0.0")); } } @@ -1394,13 +1297,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -1432,7 +1330,8 @@ public void Config_should_match_package_result_name() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script() { - MockLogger.ContainsMessage("UpperCase 1.1.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("UpperCase 1.1.0 Before Modification")); } [Fact] @@ -1440,7 +1339,8 @@ public void Should_have_executed_chocolateyBeforeModify_script() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyUninstall_script() { - MockLogger.ContainsMessage("UpperCase 1.1.0 Uninstalled", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("UpperCase 1.1.0 Uninstalled")); } } @@ -1449,6 +1349,7 @@ public class When_uninstalling_a_package_with_non_normalized_version : Scenarios private PackageResult packageResult; private string NonNormalizedVersion = "0004.0004.00005.00"; + private string NormalizedVersion = "4.4.5"; public override void Context() { @@ -1512,13 +1413,8 @@ public void Should_delete_any_files_created_during_the_install() [Fact] public void Should_contain_a_warning_message_that_it_uninstalled_successfully() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("1/1")); } [Fact] @@ -1550,7 +1446,8 @@ public void Config_should_match_package_result_name() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script() { - MockLogger.ContainsMessage("upgradepackage {0} Before Modification".FormatWith(NonNormalizedVersion), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage {0} Before Modification".FormatWith(NormalizedVersion))); } [Fact] @@ -1558,7 +1455,8 @@ public void Should_have_executed_chocolateyBeforeModify_script() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyUninstall_script() { - MockLogger.ContainsMessage("upgradepackage {0} Uninstalled".FormatWith(NonNormalizedVersion), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage {0} Uninstalled".FormatWith(NormalizedVersion))); } } @@ -1589,20 +1487,21 @@ public override void Because() public void Should_uninstall_the_package() { var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".FormatWith(TargetPackageName)); - File.Exists(packageFile).Should().BeFalse(); + FileAssert.DoesNotExist(packageFile); } [Fact] public void Should_uninstall_the_dependency() { var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".FormatWith(DependencyName)); - File.Exists(packageFile).Should().BeFalse(); + FileAssert.DoesNotExist(packageFile); } [Fact] public void Should_contain_a_message_that_everything_uninstalled_successfully() { - MockLogger.ContainsMessage("uninstalled 2/2", LogLevel.Warn).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("uninstalled 2/2")); } [Fact] @@ -1610,7 +1509,8 @@ public void Should_contain_a_message_that_everything_uninstalled_successfully() [Platform(Exclude = "Mono")] public void Should_run_target_package_beforeModify() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "1.0.0"))); } [Fact] @@ -1618,34 +1518,26 @@ public void Should_run_target_package_beforeModify() [Platform(Exclude = "Mono")] public void Should_run_dependency_package_beforeModify() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"))); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index e4591a0f31..ead522283f 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -86,25 +86,15 @@ public void Should_contain_older_version_in_directory() [Fact] public void Should_contain_a_message_that_a_new_version_is_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_a_package_can_be_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("can upgrade 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("can upgrade 1/1")); } [Fact] @@ -133,25 +123,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_no_packages_can_be_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("can upgrade 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("can upgrade 0/1")); } [Fact] @@ -180,25 +160,15 @@ public override void Because() [Fact] public void Should_contain_a_message_the_package_was_not_found() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("nonexistentpackage not installed. The package was not found with the source(s) listed")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("nonexistentpackage not installed. The package was not found with the source(s) listed")); } [Fact] public void Should_contain_a_message_that_no_packages_can_be_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("can upgrade 0/0")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("can upgrade 0/0")); } } @@ -248,32 +218,22 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -314,7 +274,8 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -324,20 +285,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.0 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.0 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.0 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.0 Before Modification")); } [Fact] @@ -345,7 +307,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.0 Installed")); } } @@ -372,25 +335,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("upgradepackage v1.0.0 is the latest version available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage v1.0.0 is the latest version available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1 ")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1 ")); } [Fact] @@ -464,25 +417,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("upgradepackage v1.1.0 is the latest version available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage v1.1.0 is the latest version available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1 ")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1 ")); } [Fact] @@ -507,7 +450,7 @@ public void Should_be_the_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -598,25 +541,15 @@ public void Should_upgrade_the_package() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta2 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta2 is available based on your source")); } [Fact] @@ -657,7 +590,8 @@ public void Should_match_the_upgrade_version_of_the_new_beta() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -667,20 +601,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta2 Before Modification")); } [Fact] @@ -688,7 +623,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta2 Installed")); } } @@ -756,25 +692,15 @@ public void Should_upgrade_the_package() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta.1 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta.1 is available based on your source")); } [Fact] @@ -815,7 +741,8 @@ public void Should_match_the_upgrade_version_of_the_new_beta() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -825,20 +752,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta.1 Before Modification")); } [Fact] @@ -846,7 +774,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta.1 Installed")); } } @@ -908,32 +837,22 @@ public void Should_upgrade_the_package() version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.ToStringSafe().Should().Be("1.1.1-beta2"); - version.ToStringSafe().Should().Be("1.1.1-beta2"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta2"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.1.1-beta installed. Version 1.1.1-beta2 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.1.1-beta installed. Version 1.1.1-beta2 is available based on your source")); } [Fact] @@ -971,7 +890,8 @@ public void Should_match_the_upgrade_version_of_the_new_beta() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta Before Modification")); } [Fact] @@ -981,20 +901,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.1.1-beta Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta2 Before Modification")); } [Fact] @@ -1002,7 +923,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta2 Installed")); } } @@ -1066,32 +988,22 @@ public void Should_upgrade_the_package() version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.ToStringSafe().Should().Be("1.1.1-beta.1"); - version.ToStringSafe().Should().Be("1.1.1-beta.1"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta.1"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.1.1-beta installed. Version 1.1.1-beta.1 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.1.1-beta installed. Version 1.1.1-beta.1 is available based on your source")); } [Fact] @@ -1129,7 +1041,8 @@ public void Should_match_the_upgrade_version_of_the_new_beta() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta Before Modification")); } [Fact] @@ -1139,20 +1052,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.1.1-beta Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta.1 Before Modification")); } [Fact] @@ -1160,7 +1074,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta.1 Installed")); } } @@ -1223,32 +1138,22 @@ public void Should_upgrade_the_package() version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.ToStringSafe().Should().Be("1.1.1-beta2"); - version.ToStringSafe().Should().Be("1.1.1-beta2"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta2"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.1.1-beta.1 installed. Version 1.1.1-beta2 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.1.1-beta.1 installed. Version 1.1.1-beta2 is available based on your source")); } [Fact] @@ -1286,7 +1191,8 @@ public void Should_match_the_upgrade_version_of_the_new_beta() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta.1 Before Modification")); } [Fact] @@ -1296,20 +1202,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.1.1-beta.1 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta2 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta.1 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta.1 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.1-beta2 Before Modification")); } [Fact] @@ -1317,7 +1224,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.1-beta2 Installed")); } } @@ -1343,25 +1251,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("upgradepackage v1.1.1-beta is newer")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage v1.1.1-beta is newer")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1 ")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1 ")); } [Fact] @@ -1389,7 +1287,7 @@ public void Should_be_the_same_version_of_the_package() var version = packageReader.NuspecReader.GetVersion(); version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.Should().Be("1.1.1-beta"); - version.ToStringSafe().Should().Be("1.1.1-beta"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta"); } } @@ -1441,25 +1339,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("upgradepackage v1.1.1-beta is newer")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage v1.1.1-beta is newer")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1 ")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1 ")); } [Fact] @@ -1487,7 +1375,7 @@ public void Should_be_the_same_version_of_the_package() var version = packageReader.NuspecReader.GetVersion(); version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.Should().Be("1.1.1-beta"); - version.ToStringSafe().Should().Be("1.1.1-beta"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta"); } } @@ -1552,7 +1440,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -1575,25 +1463,15 @@ public void Should_contain_newer_version_in_directory() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -1649,25 +1527,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1 ")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1 ")); } [Fact] @@ -1692,7 +1560,7 @@ public void Should_be_the_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1741,25 +1609,15 @@ public override void Because() [Fact] public void Should_contain_a_message_that_you_have_the_latest_version_available() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).OrEmpty()) - { - if (message.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("installpackage v1.0.0 is the latest version available based on your source(s)")); } [Fact] public void Should_contain_a_message_that_the_package_was_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -1784,7 +1642,7 @@ public void Should_be_the_same_version_of_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -1875,7 +1733,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -1898,25 +1756,15 @@ public void Should_contain_newer_version_in_directory() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -1989,7 +1837,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -2024,25 +1872,15 @@ public void Should_contain_newer_version_in_directory() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -2125,32 +1963,22 @@ public void Should_not_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_was_not_able_to_upgrade() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -2211,20 +2039,15 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -2294,20 +2117,15 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -2365,25 +2183,15 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_message_the_package_was_not_found() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("nonexistentpackage not installed. The package was not found with the source(s) listed")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("nonexistentpackage not installed. The package was not found with the source(s) listed")); } [Fact] public void Should_contain_a_message_that_no_packages_were_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1")); } [Fact] @@ -2407,31 +2215,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + _packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("The package was not found")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("The package was not found"))); } } @@ -2477,13 +2270,8 @@ public void Should_not_have_a_rollback_directory() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -2536,13 +2324,8 @@ public void Should_not_install_a_package_in_the_lib_directory() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_upgrade_a_package() { - bool notInstalled = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) notInstalled = true; - } - - notInstalled.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -2566,31 +2349,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + _packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("Cannot upgrade a non-existent package")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("Cannot upgrade a non-existent package"))); } } @@ -2626,7 +2394,7 @@ public void Should_not_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2644,7 +2412,7 @@ public void Should_have_the_erroring_upgraded_package_in_the_lib_bad_directory() var packageFile = Path.Combine(Scenario.get_top_level(), "lib-bad", Configuration.PackageNames, "2.0.0", Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } @@ -2659,13 +2427,8 @@ public void Should_delete_the_rollback() [Fact] public void Should_contain_a_warning_message_that_it_was_unable_to_upgrade_a_package() { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("0/1")) installedSuccessfully = true; - } - - installedSuccessfully.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("0/1")); } [Fact] @@ -2689,31 +2452,16 @@ public void Should_not_have_warning_package_result() [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - - errorFound.Should().BeTrue(); + _packageResult.Messages.Should().Contain(m => m.MessageType == ResultType.Error); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - foreach (var message in _packageResult.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("chocolateyInstall.ps1")) errorFound = true; - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("chocolateyInstall.ps1"))); } } @@ -2741,7 +2489,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -2751,7 +2499,7 @@ public void Should_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -2761,47 +2509,33 @@ public void Should_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 3/3")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -2829,7 +2563,7 @@ public void Should_not_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2839,7 +2573,7 @@ public void Should_not_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2849,85 +2583,49 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_it_was_unable_to_upgrade_anything() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1")); } [Fact] public void Should_not_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_an_error_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => m.MessageType == ResultType.Error)); } [Fact] public void Should_have_expected_error_in_package_result() { - bool errorFound = false; - - foreach (var packageResult in Results) - { - foreach (var message in packageResult.Value.Messages) - { - if (message.MessageType == ResultType.Error) - { - if (message.Message.Contains("Unable to resolve dependency 'isexactversiondependency")) errorFound = true; - } - } - } - - errorFound.Should().BeTrue(); + Results.Should().AllSatisfy(r => + r.Value.Messages.Should().Contain(m => + m.MessageType == ResultType.Error && + m.Message.Contains("Unable to resolve dependency 'isexactversiondependency"))); } } @@ -2956,7 +2654,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -2966,7 +2664,7 @@ public void Should_not_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -2976,47 +2674,33 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_it_upgraded_only_the_package_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -3044,7 +2728,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -3054,7 +2738,7 @@ public void Should_not_upgrade_the_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3064,47 +2748,33 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_the_dependency_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -3132,7 +2802,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -3142,7 +2812,7 @@ public void Should_upgrade_the_parent_package_to_highest_version_that_meets_new_ var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -3152,47 +2822,33 @@ public void Should_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 3/3")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -3222,7 +2878,7 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -3232,7 +2888,7 @@ public void Should_upgrade_the_parent_package_to_highest_version_that_meets_new_ var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.1.0"); } } @@ -3242,47 +2898,33 @@ public void Should_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 3/3")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 3/3")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } @@ -3312,7 +2954,7 @@ public void Should_upgrade_the_package_to_highest_version_in_range() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -3322,7 +2964,7 @@ public void Should_not_upgrade_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3332,63 +2974,42 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_outputted_conflicting_upgrade_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") - && message.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")) - { - expectedMessage = true; - } - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => + m.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") + && m.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")); } } @@ -3420,7 +3041,7 @@ public void Should_upgrade_the_package_to_highest_version_in_range() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -3430,7 +3051,7 @@ public void Should_not_upgrade_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3440,64 +3061,43 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 2/2")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 2/2")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_outputted_conflicting_upgrade_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") - && message.Contains("hasdependency 1.0.0 constraint: isexactversiondependency (= 1.0.0)") - && message.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")) - { - expectedMessage = true; - } - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => + m.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") + && m.Contains("hasdependency 1.0.0 constraint: isexactversiondependency (= 1.0.0)") + && m.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")); } } @@ -3529,7 +3129,7 @@ public void Should_upgrade_the_package_to_highest_version_in_range() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } @@ -3539,7 +3139,7 @@ public void Should_not_upgrade_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3549,63 +3149,42 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_outputted_conflicting_upgrade_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") - && message.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")) - { - expectedMessage = true; - } - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => + m.Contains("One or more unresolved package dependency constraints detected in the Chocolatey lib folder") + && m.Contains("hasdependency 1.0.0 constraint: isdependency (>= 1.0.0 && < 2.0.0)")); } } @@ -3636,7 +3215,7 @@ public void Should_not_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3646,7 +3225,7 @@ public void Should_not_upgrade_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } @@ -3656,59 +3235,40 @@ public void Should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.0.0"); } } [Fact] public void Should_contain_a_message_that_nothing_was_upgraded() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 0/1")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 0/1")); } [Fact] public void Should_have_an_error_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeFalse()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } [Fact] public void Should_have_outputted_expected_error_message() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Error).OrEmpty()) - { - if (message.Contains("Unable to resolve dependency chain. This may be caused by a parent package depending on this package, try specifying a specific version to use or don't ignore any dependencies!")) expectedMessage = true; - } - - expectedMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Unable to resolve dependency chain. This may be caused by a parent package depending on this package, try specifying a specific version to use or don't ignore any dependencies!")); } } @@ -3740,20 +3300,15 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -3843,20 +3398,15 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] @@ -3937,13 +3487,14 @@ public override void Because() [Fact] public void Should_have_no_sources_enabled_result() { - MockLogger.ContainsMessage("Upgrading was NOT successful. There are no sources enabled for", LogLevel.Error).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Error.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Upgrading was NOT successful. There are no sources enabled for")); } [Fact] public void Should_not_have_any_packages_upgraded() { - Results.Count().Should().Be(0); + Results.Should().BeEmpty(); } } @@ -3963,14 +3514,14 @@ public override void Because() [Fact] public void Should_report_for_all_installed_packages() { - Results.Count().Should().Be(3); + Results.Should().HaveCount(3); } [Fact] public void Should_upgrade_packages_with_upgrades() { var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); - upgradePackageResult.Count.Should().Be(1, "upgradepackage must be there once"); + upgradePackageResult.Should().ContainSingle( "upgradepackage must be there once"); upgradePackageResult.First().Value.Version.Should().Be("1.1.0"); } @@ -3978,7 +3529,7 @@ public void Should_upgrade_packages_with_upgrades() public void Should_skip_packages_without_upgrades() { var installPackageResult = Results.Where(x => x.Key == "installpackage").ToList(); - installPackageResult.Count.Should().Be(1, "installpackage must be there once"); + installPackageResult.Should().ContainSingle( "installpackage must be there once"); installPackageResult.First().Value.Version.Should().Be("1.0.0"); } } @@ -4002,14 +3553,14 @@ public override void Because() [Fact] public void Should_report_for_all_installed_packages() { - Results.Count().Should().Be(3); + Results.Should().HaveCount(3); } [Fact] public void Should_upgrade_packages_with_upgrades() { var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); - upgradePackageResult.Count.Should().Be(1, "upgradepackage must be there once"); + upgradePackageResult.Should().ContainSingle( "upgradepackage must be there once"); upgradePackageResult.First().Value.Version.Should().Be("1.1.1-beta2"); } @@ -4022,7 +3573,7 @@ public void Should_upgrade_upgradepackage() var version = packageReader.NuspecReader.GetVersion(); version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.Should().Be("1.1.1-beta2"); - version.ToStringSafe().Should().Be("1.1.1-beta2"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta2"); } } @@ -4030,7 +3581,7 @@ public void Should_upgrade_upgradepackage() public void Should_skip_packages_without_upgrades() { var installPackageResult = Results.Where(x => x.Key == "installpackage").ToList(); - installPackageResult.Count.Should().Be(1, "installpackage must be there once"); + installPackageResult.Should().ContainSingle( "installpackage must be there once"); installPackageResult.First().Value.Version.Should().Be("1.0.0"); } } @@ -4056,14 +3607,14 @@ public override void Because() [Fact] public void Should_report_for_all_installed_packages() { - Results.Count().Should().Be(3); + Results.Should().HaveCount(3); } [Fact] public void Should_upgrade_packages_with_upgrades() { var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); - upgradePackageResult.Count.Should().Be(1, "upgradepackage must be there once"); + upgradePackageResult.Should().ContainSingle( "upgradepackage must be there once"); // available version will show as last stable upgradePackageResult.First().Value.Version.Should().Be("1.1.0"); } @@ -4077,7 +3628,7 @@ public void Should_not_upgrade_upgradepackage() var version = packageReader.NuspecReader.GetVersion(); version.Version.ToStringSafe().Should().Be("1.1.1.0"); version.OriginalVersion.Should().Be("1.1.1-beta"); - version.ToStringSafe().Should().Be("1.1.1-beta"); + version.ToNormalizedStringChecked().Should().Be("1.1.1-beta"); } } @@ -4085,7 +3636,7 @@ public void Should_not_upgrade_upgradepackage() public void Should_skip_packages_without_upgrades() { var installPackageResult = Results.Where(x => x.Key == "installpackage").ToList(); - installPackageResult.Count.Should().Be(1, "installpackage must be there once"); + installPackageResult.Should().ContainSingle( "installpackage must be there once"); installPackageResult.First().Value.Version.Should().Be("1.0.0"); } } @@ -4112,7 +3663,7 @@ public override void Because() [Fact] public void Should_have_a_single_package_result() { - Results.Count.Should().Be(1, "The returned package results do not have a single value!"); + Results.Should().ContainSingle( "The returned package results do not have a single value!"); } [Fact] @@ -4153,32 +3704,22 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.1-beta.1"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.1-beta.1"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta.1 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.1-beta.1 is available based on your source")); } [Fact] @@ -4219,7 +3760,8 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -4229,20 +3771,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.1-beta.1 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.0 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.0 Before Modification")); } [Fact] @@ -4252,7 +3795,8 @@ public void Should_have_executed_chocolateyInstall_script_for_new_package() { const string expectedMessage = "upgradepackage 1.1.1-beta.1 Installed"; - MockLogger.ContainsMessage(expectedMessage, LogLevel.Info).Should().BeTrue("No log message containing the sentence '{0}' could be found!".FormatWith(expectedMessage)); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains(expectedMessage), "No log message containing the sentence '{0}' could be found!".FormatWith(expectedMessage)); } } @@ -4273,7 +3817,7 @@ public override void Because() [Fact] public void Should_report_for_all_non_skipped_packages() { - Results.Count().Should().Be(1); + Results.Should().HaveCount(1); Results.First().Key.Should().Be("installpackage"); } @@ -4281,7 +3825,7 @@ public void Should_report_for_all_non_skipped_packages() public void Should_skip_packages_in_except_list() { var upgradePackageResult = Results.Where(x => x.Key == "upgradepackage").ToList(); - upgradePackageResult.Count.Should().Be(0, "upgradepackage should not be in the results list"); + upgradePackageResult.Should().BeEmpty("upgradepackage should not be in the results list"); } } @@ -4332,32 +3876,22 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have scriptpackage.hook v1.0.0 installed. Version 2.0.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have scriptpackage.hook v1.0.0 installed. Version 2.0.0 is available based on your source")); } [Fact] @@ -4478,32 +4012,22 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -4544,7 +4068,8 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -4554,20 +4079,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage 1.1.0 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("upgradepackage 1.1.0 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.0 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.1.0 Before Modification")); } [Fact] @@ -4575,7 +4101,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage 1.1.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.1.0 Installed")); } [Fact] @@ -4583,7 +4110,8 @@ public void Should_have_executed_chocolateyInstall_script_for_new_package() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_all_hook_script() { - MockLogger.ContainsMessage("pre-install-all.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-all.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4591,7 +4119,8 @@ public void Should_have_executed_pre_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_all_hook_script() { - MockLogger.ContainsMessage("post-install-all.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-all.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4599,7 +4128,8 @@ public void Should_have_executed_post_all_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_pre_upgradepackage_hook_script() { - MockLogger.ContainsMessage("pre-install-upgradepackage.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-upgradepackage.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4607,7 +4137,8 @@ public void Should_have_executed_pre_upgradepackage_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_post_upgradepackage_hook_script() { - MockLogger.ContainsMessage("post-install-upgradepackage.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-upgradepackage.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4615,7 +4146,8 @@ public void Should_have_executed_post_upgradepackage_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_uninstall_hook_script() { - MockLogger.ContainsMessage("post-uninstall-all.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("post-uninstall-all.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4623,7 +4155,8 @@ public void Should_not_have_executed_uninstall_hook_script() [Platform(Exclude = "Mono")] public void Should_not_have_executed_installpackage_hook_script() { - MockLogger.ContainsMessage("pre-install-installpackage.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-install-installpackage.ps1 hook ran for upgradepackage 1.1.0")); } [Fact] @@ -4631,7 +4164,8 @@ public void Should_not_have_executed_installpackage_hook_script() [Platform(Exclude = "Mono")] public void Should_have_executed_beforemodify_hook_script_for_previous_version() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for upgradepackage 1.0.0", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for upgradepackage 1.0.0")); } [Fact] @@ -4639,7 +4173,8 @@ public void Should_have_executed_beforemodify_hook_script_for_previous_version() [Platform(Exclude = "Mono")] public void Should_not_have_executed_beforemodify_hook_script_for_upgrade_version() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for upgradepackage 1.1.0")); } } public class When_upgrading_an_existing_package_with_uppercase_id : ScenariosBase @@ -4688,32 +4223,22 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have UpperCase v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have UpperCase v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] @@ -4751,7 +4276,8 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("UpperCase 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("UpperCase 1.0.0 Before Modification")); } [Fact] @@ -4761,20 +4287,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("UpperCase 1.0.0 Before Modification")) - .Any(p => p.EndsWith("UpperCase 1.1.0 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("UpperCase 1.1.0 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("UpperCase 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("UpperCase 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("UpperCase 1.1.0 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("UpperCase 1.1.0 Before Modification")); } [Fact] @@ -4782,7 +4309,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("UpperCase 1.1.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("UpperCase 1.1.0 Installed")); } } @@ -4824,43 +4352,29 @@ public void Should_upgrade_the_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("1.1.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("1.1.0"); } } [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have unsupportedelements v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have unsupportedelements v1.0.0 installed. Version 1.1.0 is available based on your source")); } [Fact] public void Should_contain_a_warning_message_about_unsupported_elements() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("Issues found with nuspec elements")) upgradeMessage = true; - } - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Issues found with nuspec elements")); } [Fact] @@ -4898,7 +4412,8 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("unsupportedelements 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("unsupportedelements 1.0.0 Before Modification")); } [Fact] @@ -4908,20 +4423,21 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("unsupportedelements 1.0.0 Before Modification")) - .Any(p => p.EndsWith("unsupportedelements 1.1.0 Installed")) - .Should().BeTrue(); + .Should().Contain(p => p.EndsWith("unsupportedelements 1.1.0 Installed")); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("unsupportedelements 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("unsupportedelements 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("unsupportedelements 1.1.0 Before Modification", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("unsupportedelements 1.1.0 Before Modification")); } [Fact] @@ -4929,7 +4445,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("unsupportedelements 1.1.0 Installed", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("unsupportedelements 1.1.0 Installed")); } } @@ -4988,25 +4505,15 @@ public void Should_upgrade_the_package() [Fact] public void Should_contain_a_warning_message_that_it_upgraded_successfully() { - bool upgradedSuccessMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; - } - - upgradedSuccessMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 1/1")); } [Fact] public void Should_contain_a_warning_message_with_old_and_new_versions() { - bool upgradeMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).OrEmpty()) - { - if (message.Contains("You have upgradepackage v1.0.0 installed. Version {0} is available based on your source".FormatWith(NonNormalizedVersion))) upgradeMessage = true; - } - - upgradeMessage.Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("You have upgradepackage v1.0.0 installed. Version {0} is available based on your source".FormatWith(NonNormalizedVersion))); } [Fact] @@ -5039,7 +4546,7 @@ public void Config_should_match_package_result_name() [Fact] public void Should_match_the_upgrade_version() { - _packageResult.Version.Should().Be(NonNormalizedVersion); + _packageResult.Version.Should().Be(NormalizedVersion); } [Fact] @@ -5047,7 +4554,8 @@ public void Should_match_the_upgrade_version() [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Before Modification", LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage 1.0.0 Before Modification")); } [Fact] @@ -5057,20 +4565,22 @@ public void Should_have_executed_chocolateyBeforeModify_before_chocolateyInstall { MockLogger.MessagesFor(LogLevel.Info).OrEmpty() .SkipWhile(p => !p.Contains("upgradepackage 1.0.0 Before Modification")) - .Any(p => p.EndsWith("upgradepackage {0} Installed".FormatWith(NonNormalizedVersion))) + .Any(p => p.EndsWith("upgradepackage {0} Installed".FormatWith(NormalizedVersion))) .Should().BeTrue(); } [Fact] public void Should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.ContainsMessage("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage 1.0.0 Uninstalled")); } [Fact] public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage {0} Before Modification".FormatWith(NonNormalizedVersion), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("upgradepackage {0} Before Modification".FormatWith(NormalizedVersion))); } [Fact] @@ -5078,7 +4588,8 @@ public void Should_not_have_executed_chocolateyBeforeModify_script_for_new_packa [Platform(Exclude = "Mono")] public void Should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.ContainsMessage("upgradepackage {0} Installed".FormatWith(NonNormalizedVersion), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgradepackage {0} Installed".FormatWith(NormalizedVersion))); } } @@ -5167,14 +4678,15 @@ public void Should_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".FormatWith(DependencyName)); using (var packageReader = new PackageArchiveReader(packageFile)) { - packageReader.NuspecReader.GetVersion().ToStringSafe().Should().Be("2.0.0"); + packageReader.NuspecReader.GetVersion().ToNormalizedStringChecked().Should().Be("2.0.0"); } } [Fact] public void Should_contain_a_message_that_everything_upgraded_successfully() { - MockLogger.ContainsMessage("upgraded 2/2", LogLevel.Warn).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Warn.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("upgraded 2/2")); } [Fact] @@ -5182,7 +4694,8 @@ public void Should_contain_a_message_that_everything_upgraded_successfully() [Platform(Exclude = "Mono")] public void Should_run_beforemodify_hook_script_for_previous_version_of_target() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "1.0.0"))); } [Fact] @@ -5190,7 +4703,8 @@ public void Should_run_beforemodify_hook_script_for_previous_version_of_target() [Platform(Exclude = "Mono")] public void Should_run_already_installed_target_package_beforeModify() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "1.0.0"))); } [Fact] @@ -5198,7 +4712,8 @@ public void Should_run_already_installed_target_package_beforeModify() [Platform(Exclude = "Mono")] public void Should_not_run_beforemodify_hook_script_for_upgrade_version_of_target() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"))); } [Fact] @@ -5206,7 +4721,8 @@ public void Should_not_run_beforemodify_hook_script_for_upgrade_version_of_targe [Platform(Exclude = "Mono")] public void Should_not_run_target_package_beforeModify_for_upgraded_version() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(TargetPackageName, "2.0.0"))); } [Fact] @@ -5214,7 +4730,8 @@ public void Should_not_run_target_package_beforeModify_for_upgraded_version() [Platform(Exclude = "Mono")] public void Should_run_pre_all_hook_script_for_upgraded_version_of_target() { - MockLogger.ContainsMessage("pre-install-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"))); } [Fact] @@ -5222,7 +4739,8 @@ public void Should_run_pre_all_hook_script_for_upgraded_version_of_target() [Platform(Exclude = "Mono")] public void Should_run_post_all_hook_script_for_upgraded_version_of_target() { - MockLogger.ContainsMessage("post-install-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-all.ps1 hook ran for {0} {1}".FormatWith(TargetPackageName, "2.0.0"))); } [Fact] @@ -5230,7 +4748,8 @@ public void Should_run_post_all_hook_script_for_upgraded_version_of_target() [Platform(Exclude = "Mono")] public void Should_run_beforemodify_hook_script_for_previous_version_of_dependency() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "1.0.0"))); } [Fact] @@ -5238,7 +4757,8 @@ public void Should_run_beforemodify_hook_script_for_previous_version_of_dependen [Platform(Exclude = "Mono")] public void Should_run_already_installed_dependency_package_beforeModify() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "1.0.0"))); } [Fact] @@ -5246,7 +4766,8 @@ public void Should_run_already_installed_dependency_package_beforeModify() [Platform(Exclude = "Mono")] public void Should_not_run_beforemodify_hook_script_for_upgrade_version_of_dependency() { - MockLogger.ContainsMessage("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("pre-beforemodify-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"))); } [Fact] @@ -5254,7 +4775,8 @@ public void Should_not_run_beforemodify_hook_script_for_upgrade_version_of_depen [Platform(Exclude = "Mono")] public void Should_not_run_dependency_package_beforeModify_for_upgraded_version() { - MockLogger.ContainsMessage("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "2.0.0"), LogLevel.Info).Should().BeFalse(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().NotContain(m => m.Contains("Ran BeforeModify: {0} {1}".FormatWith(DependencyName, "2.0.0"))); } [Fact] @@ -5262,7 +4784,8 @@ public void Should_not_run_dependency_package_beforeModify_for_upgraded_version( [Platform(Exclude = "Mono")] public void Should_run_pre_all_hook_script_for_upgraded_version_of_dependency() { - MockLogger.ContainsMessage("pre-install-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("pre-install-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"))); } [Fact] @@ -5270,34 +4793,26 @@ public void Should_run_pre_all_hook_script_for_upgraded_version_of_dependency() [Platform(Exclude = "Mono")] public void Should_run_post_all_hook_script_for_upgraded_version_of_dependency() { - MockLogger.ContainsMessage("post-install-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"), LogLevel.Info).Should().BeTrue(); + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToStringSafe()) + .WhoseValue.Should().Contain(m => m.Contains("post-install-all.ps1 hook ran for {0} {1}".FormatWith(DependencyName, "2.0.0"))); } [Fact] public void Should_have_a_successful_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Success.Should().BeTrue(); - } + Results.Should().AllSatisfy(r => r.Value.Success.Should().BeTrue()); } [Fact] public void Should_not_have_inconclusive_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Inconclusive.Should().BeFalse()); } [Fact] public void Should_not_have_warning_package_result() { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.Should().BeFalse(); - } + Results.Should().AllSatisfy(r => r.Value.Warning.Should().BeFalse()); } } } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs index 0b52a14c63..959f2f3ebb 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyExportCommandSpecs.cs @@ -161,8 +161,7 @@ public void Should_log_a_message() public void Should_log_the_message_we_expect() { var messages = MockLogger.MessagesFor(LogLevel.Info); - messages.Should().NotBeEmpty(); - messages.Count.Should().Be(1); + messages.Should().ContainSingle(); messages[0].Should().Contain("Export would have been with options"); } } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs index e9dfcf98ed..1a9528eeb4 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs @@ -133,7 +133,7 @@ public void Should_not_set_template_properties_if_none_have_been_defined() { reset(); because(); - configuration.NewCommand.TemplateProperties.Count.Should().Be(0); + configuration.NewCommand.TemplateProperties.Should().HaveCount(0); } [Fact] @@ -144,7 +144,7 @@ public void Should_set_template_properties_when_args_are_separated_by_equals() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new"); @@ -159,7 +159,7 @@ public void Should_set_template_properties_only_once() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("one"); @@ -174,7 +174,7 @@ public void Should_ignore_casing_differences_when_setting_template_properties() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("one"); @@ -190,7 +190,7 @@ public void Should_not_set_template_properties_when_args_are_not_separated_by_eq because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("PackageName"); templateProperty.Value.Should().Be("bill"); @@ -206,7 +206,7 @@ public void Should_not_set_override_configuration_Name_when_unparsed_without_equ because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("PackageName"); templateProperty.Value.Should().Be("bill"); @@ -235,7 +235,7 @@ public void Should_set_template_properties_when_args_are_separated_by_equals_wit because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new"); @@ -249,7 +249,7 @@ public void Should_set_template_properties_without_surrounding_quotes() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new this"); @@ -263,7 +263,7 @@ public void Should_set_template_properties_without_removing_quote() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new \"this"); @@ -277,7 +277,7 @@ public void Should_set_template_properties_without_surrounding_apostrophes() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new this"); @@ -291,7 +291,7 @@ public void Should_set_template_properties_without_removing_apostrophe() because(); var properties = configuration.NewCommand.TemplateProperties; - properties.Count.Should().Be(1); + properties.Should().HaveCount(1); var templateProperty = properties.FirstOrDefault(); templateProperty.Key.Should().Be("bob"); templateProperty.Value.Should().Be("new 'this"); diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs index db6bb60b7a..9ff9939e94 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs @@ -129,7 +129,7 @@ public void Should_property_bar_equal_baz() public void Should_log_warning_on_duplicate_foo() { var warnings = MockLogger.MessagesFor(LogLevel.Warn); - warnings.Count.Should().Be(1); + warnings.Should().HaveCount(1); warnings[0].Should().BeEquivalentTo("A value for 'foo' has already been added with the value '1'. Ignoring foo='2'."); } } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs index bc3c8ec0bd..1db4187be8 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs @@ -336,8 +336,8 @@ public void Should_log_a_message() public void Should_log_the_message_we_expect() { var messages = MockLogger.MessagesFor(tests.LogLevel.Info); - messages.Should().NotBeEmpty(); - messages.Count.Should().Be(1); + messages.Should().NotBeEmpty() + .And.ContainSingle(); messages[0].Should().Contain("Pin would have called"); } } @@ -385,7 +385,7 @@ public void Should_log_a_message() [Fact] public void Should_log_one_message() { - MockLogger.Messages.Count.Should().Be(1); + MockLogger.Messages.Should().ContainSingle(); } } diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs index eaa83f5d6b..15cd6c3d65 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs @@ -76,7 +76,7 @@ public void Should_log_a_message() [Fact] public void Should_log_one_message() { - MockLogger.Messages.Count.Should().Be(1); + MockLogger.Messages.Should().HaveCount(1); } [Fact] diff --git a/src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetLoggerSpecs.cs b/src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetLoggerSpecs.cs index c8aa53d3e9..643c7c3b22 100644 --- a/src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetLoggerSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetLoggerSpecs.cs @@ -56,7 +56,7 @@ public void Should_log_debug_level_with_nuget_prefix_on_all_lines_when_calling_L _logger.LogDebug(testMessage); var loggerName = LogLevel.Debug.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -71,7 +71,7 @@ public void Should_log_debug_level_with_nuget_prefix_when_calling_LogDebug() _logger.LogDebug(testMessage); var loggerName = LogLevel.Debug.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -86,7 +86,7 @@ public void Should_log_error_level_with_nuget_prefix_on_all_lines_when_calling_L _logger.LogError(testMessage); var loggerName = LogLevel.Error.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -101,7 +101,7 @@ public void Should_log_error_level_with_nuget_prefix_when_calling_LogError() _logger.LogError(testMessage); var loggerName = LogLevel.Error.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -114,7 +114,7 @@ public void Should_log_error_level_with_nuget_prefix_when_calling_LogError() public void Should_log_expected_log_level_when_calling_Log_with_log_message(NuGetLogLevel nugetLogLevel, LogLevel logLevel, string testMessage, string expectedMessage) { _logger.Log(new LogMessage(nugetLogLevel, testMessage)); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(logLevel.ToStringSafe()); MockLogger.Messages[logLevel.ToStringSafe()].Should().Contain(expectedMessage); @@ -127,7 +127,7 @@ public void Should_log_expected_log_level_when_calling_Log_with_log_message(NuGe public void Should_log_expected_log_level_when_calling_Log_with_nuget_log_level(NuGetLogLevel nugetLogLevel, LogLevel logLevel, string testMessage, string expectedMessage) { _logger.Log(nugetLogLevel, testMessage); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(logLevel.ToStringSafe()); MockLogger.Messages[logLevel.ToStringSafe()].Should().Contain(expectedMessage); @@ -140,7 +140,7 @@ public void Should_log_expected_log_level_when_calling_Log_with_nuget_log_level( public async Task Should_log_expected_log_level_when_calling_LogAsync_with_nuget_log_level(NuGetLogLevel nugetLogLevel, LogLevel logLevel, string testMessage, string expectedMessage) { await _logger.LogAsync(nugetLogLevel, testMessage); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(logLevel.ToStringSafe()); MockLogger.Messages[logLevel.ToStringSafe()].Should().Contain(expectedMessage); @@ -153,7 +153,7 @@ public async Task Should_log_expected_log_level_when_calling_LogAsync_with_nuget public async Task Should_log_expected_log_level_when_calling_LogAsync_with_nuget_log_message(NuGetLogLevel nugetLogLevel, LogLevel logLevel, string testMessage, string expectedMessage) { await _logger.LogAsync(new LogMessage(nugetLogLevel, testMessage)); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(logLevel.ToStringSafe()); MockLogger.Messages[logLevel.ToStringSafe()].Should().Contain(expectedMessage); @@ -168,7 +168,7 @@ public void Should_log_info_level_with_nuget_prefix_on_all_lines_when_calling_Lo _logger.LogInformationSummary(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -183,7 +183,7 @@ public void Should_log_info_level_with_nuget_prefix_when_calling_LogInformationS _logger.LogInformationSummary(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -194,7 +194,7 @@ public void Should_log_info_level_with_nuget_prefix_when_calling_LogInformationS public void Should_log_verbose_level_when_calling_Log_with_nuget_log_level(NuGetLogLevel nuGetLogLevel, string testMessage, string expectedMessage) { _logger.Log(nuGetLogLevel, testMessage); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain("Info"); MockLogger.Messages["Info"].Should().Contain(expectedMessage); @@ -205,7 +205,7 @@ public void Should_log_verbose_level_when_calling_Log_with_nuget_log_level(NuGet public void Should_log_verbose_level_when_calling_Log_with_nuget_log_message(NuGetLogLevel nuGetLogLevel, string testMessage, string expectedMessage) { _logger.Log(new LogMessage(nuGetLogLevel, testMessage)); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain("Info"); MockLogger.Messages["Info"].Should().Contain(expectedMessage); @@ -216,7 +216,7 @@ public void Should_log_verbose_level_when_calling_Log_with_nuget_log_message(NuG public async Task Should_log_verbose_level_when_calling_LogAsync_with_nuget_log_level(NuGetLogLevel nuGetLogLevel, string testMessage, string expectedMessage) { await _logger.LogAsync(nuGetLogLevel, testMessage); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain("Info"); MockLogger.Messages["Info"].Should().Contain(expectedMessage); @@ -227,7 +227,7 @@ public async Task Should_log_verbose_level_when_calling_LogAsync_with_nuget_log_ public async Task Should_log_verbose_level_when_calling_LogAsync_with_nuget_log_message(NuGetLogLevel nuGetLogLevel, string testMessage, string expectedMessage) { await _logger.LogAsync(new LogMessage(nuGetLogLevel, testMessage)); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain("Info"); MockLogger.Messages["Info"].Should().Contain(expectedMessage); @@ -242,7 +242,7 @@ public void Should_log_verbose_level_with_nuget_prefix_on_all_lines_when_calling _logger.LogInformation(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -257,7 +257,7 @@ public void Should_log_verbose_level_with_nuget_prefix_on_all_lines_when_calling _logger.LogMinimal(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -272,7 +272,7 @@ public void Should_log_verbose_level_with_nuget_prefix_on_all_lines_when_calling _logger.LogVerbose(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -287,7 +287,7 @@ public void Should_log_verbose_level_with_nuget_prefix_when_calling_LogInformati _logger.LogInformation(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -302,7 +302,7 @@ public void Should_log_verbose_level_with_nuget_prefix_when_calling_LogMinimal() _logger.LogMinimal(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -317,7 +317,7 @@ public void Should_log_verbose_level_with_nuget_prefix_when_calling_LogVerbose() _logger.LogVerbose(testMessage); var loggerName = LogLevel.Info.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(2); + MockLogger.LoggerNames.Should().HaveCount(2); MockLogger.LoggerNames.Should().Contain("Verbose"); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -332,7 +332,7 @@ public void Should_log_warn_level_with_nuget_prefix_on_all_lines_when_calling_Lo _logger.LogWarning(testMessage); var loggerName = LogLevel.Warn.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); @@ -347,7 +347,7 @@ public void Should_log_warn_level_with_nuget_prefix_when_calling_LogWarning() _logger.LogWarning(testMessage); var loggerName = LogLevel.Warn.ToStringSafe(); - MockLogger.LoggerNames.Count.Should().Be(1); + MockLogger.LoggerNames.Should().ContainSingle(); MockLogger.LoggerNames.Should().Contain(typeof(ChocolateyNugetLogger).FullName); MockLogger.Messages.Keys.Should().Contain(loggerName); MockLogger.Messages[loggerName].Should().Contain(expectedMessage); diff --git a/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs b/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs index f4927ee7d3..8933f70902 100644 --- a/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/nuget/NugetCommonSpecs.cs @@ -67,7 +67,7 @@ public void Should_create_repository_when_source_is_null() because(); - packageRepositories.Count().Should().Be(0); + packageRepositories.Should().BeEmpty(); } [Fact] diff --git a/src/chocolatey.tests/infrastructure.app/services/ChocolateyConfigSettingsServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/ChocolateyConfigSettingsServiceSpecs.cs index 6e1b3cc4b7..72e69d6c79 100644 --- a/src/chocolatey.tests/infrastructure.app/services/ChocolateyConfigSettingsServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/ChocolateyConfigSettingsServiceSpecs.cs @@ -363,7 +363,7 @@ public void Should_output_features_in_alphabetical_order() MockLogger.Messages.Keys.Should().Contain("Info"); var infoMessages = MockLogger.Messages["Info"]; - infoMessages.Count.Should().Be(2); + infoMessages.Should().HaveCount(2); infoMessages[0].Should().Contain("allowEmptyChecksums"); infoMessages[1].Should().Contain("virusCheck"); } @@ -410,7 +410,7 @@ public void Should_output_config_in_alphabetical_order() MockLogger.Messages.Keys.Should().Contain("Info"); var infoMessages = MockLogger.Messages["Info"]; - infoMessages.Count.Should().Be(2); + infoMessages.Should().HaveCount(2); infoMessages[0].Should().Contain("cacheLocation"); infoMessages[1].Should().Contain("webRequestTimeoutSeconds"); } @@ -457,7 +457,7 @@ public void Should_output_sources_in_alphabetical_order() MockLogger.Messages.Keys.Should().Contain("Info"); var infoMessages = MockLogger.Messages["Info"]; - infoMessages.Count.Should().Be(2); + infoMessages.Should().HaveCount(2); infoMessages[0].Should().Contain("alpha"); infoMessages[1].Should().Contain("beta"); } @@ -568,7 +568,7 @@ public void Should_return_feature_status() { MockLogger.Messages.Keys.Should().Contain("Info"); var infoMessages = MockLogger.Messages["Info"]; - infoMessages.Count.Should().Be(1); + infoMessages.Should().ContainSingle(); infoMessages[0].Should().Contain("Enabled"); } } diff --git a/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs index 6e3ac5d7fe..fc0d2e56af 100644 --- a/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs @@ -261,7 +261,7 @@ public void Should_contain_package_files() [Fact] public void Should_contain_the_correct_number_of_package_files() { - result.Files.Count.Should().Be(files.Count); + result.Files.Should().HaveCount(files.Count); } [Fact] diff --git a/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs index 4d94a13b62..bbf04ed593 100644 --- a/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs @@ -310,8 +310,8 @@ public void Generated_package_should_be_in_current_directory() because(); var infos = MockLogger.MessagesFor(tests.LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Chocolatey would have searched for a nuspec file in \"c:\\projects\\chocolatey\" and attempted to compile it."); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Chocolatey would have searched for a nuspec file in \"c:\\projects\\chocolatey\" and attempted to compile it."); } [Fact] @@ -324,8 +324,8 @@ public void Generated_package_should_be_in_specified_directory() because(); var infos = MockLogger.MessagesFor(tests.LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Chocolatey would have searched for a nuspec file in \"c:\\packages\" and attempted to compile it."); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Chocolatey would have searched for a nuspec file in \"c:\\packages\" and attempted to compile it."); } } } diff --git a/src/chocolatey.tests/infrastructure.app/services/RulesServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/RulesServiceSpecs.cs index 420c504ee5..910ed73e85 100644 --- a/src/chocolatey.tests/infrastructure.app/services/RulesServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/RulesServiceSpecs.cs @@ -62,12 +62,16 @@ public override void Because() [Fact] public void GetsRulesFromService() { - _detectedRules.Count().Should().Be(4); + _detectedRules.Should().HaveCount(4); IEnumerable ruleIds = _detectedRules.Select(t => t.Id); - ruleIds.Should().Contain(UnsupportedElementUsed); - ruleIds.Should().Contain(EmptyRequiredElement); - ruleIds.Should().Contain(InvalidTypeElement); - ruleIds.Should().Contain(MissingElementOnRequiringLicenseAcceptance); + + ruleIds.Should().Contain(new[] + { + UnsupportedElementUsed, + EmptyRequiredElement, + InvalidTypeElement, + MissingElementOnRequiringLicenseAcceptance + }); } } } diff --git a/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs index 78d2c13cbe..25eecef08f 100644 --- a/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs @@ -80,8 +80,8 @@ public void Should_log_current_directory_if_no_outputdirectory() because(); var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Would have generated a new package specification at c:\\chocolatey\\Bob"); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Would have generated a new package specification at c:\\chocolatey\\Bob"); } [Fact] @@ -92,8 +92,8 @@ public void Should_log_output_directory_if_outputdirectory_is_specified() because(); var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Would have generated a new package specification at c:\\packages\\Bob"); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Would have generated a new package specification at c:\\packages\\Bob"); } } @@ -132,8 +132,8 @@ public void Should_write_file_withe_replaced_tokens() because(); var debugs = MockLogger.MessagesFor(LogLevel.Debug); - debugs.Count.Should().Be(1); - debugs[0].Should().Be("Bob"); + debugs.Should().ContainSingle(); + debugs.Should().HaveElementAt(0,"Bob"); } [Fact] @@ -144,12 +144,12 @@ public void Should_log_info_if_regular_output() because(); var debugs = MockLogger.MessagesFor(LogLevel.Debug); - debugs.Count.Should().Be(1); - debugs[0].Should().Be("Bob"); + debugs.Should().ContainSingle(); + debugs.Should().HaveElementAt(0,"Bob"); var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be(string.Format(@"Generating template to a file{0} at 'c:\packages\bob.nuspec'", Environment.NewLine)); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,string.Format(@"Generating template to a file{0} at 'c:\packages\bob.nuspec'", Environment.NewLine)); } } @@ -294,13 +294,13 @@ public void Should_generate_all_files_and_directories() because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\chocolatey\\Bob"); - directories[1].Should().Be("c:\\chocolatey\\Bob\\tools"); + directories.Should().HaveCount(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\chocolatey\\Bob"); + directories.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\tools"); - files.Count.Should().Be(2, "There should be 2 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\chocolatey\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\chocolatey\\Bob\\random.txt"); + files.Should().HaveCount(2, "There should be 2 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\chocolatey\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\random.txt"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine)); } @@ -313,13 +313,13 @@ public void Should_generate_all_files_and_directories_even_with_outputdirectory( because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\packages\\Bob"); - directories[1].Should().Be("c:\\packages\\Bob\\tools"); + directories.Should().HaveCount(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\packages\\Bob"); + directories.Should().HaveElementAt(1,"c:\\packages\\Bob\\tools"); - files.Count.Should().Be(2, "There should be 2 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\packages\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\packages\\Bob\\random.txt"); + files.Should().HaveCount(2, "There should be 2 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\packages\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\packages\\Bob\\random.txt"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine)); } @@ -392,16 +392,16 @@ public void Should_generate_all_files_and_directories() because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\chocolatey\\Bob"); - directories[1].Should().Be("c:\\chocolatey\\Bob\\tools"); - directories[2].Should().Be("c:\\chocolatey\\Bob\\tools\\lower"); + directories.Should().HaveCount(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\chocolatey\\Bob"); + directories.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\tools"); + directories.Should().HaveElementAt(2,"c:\\chocolatey\\Bob\\tools\\lower"); - files.Count.Should().Be(4, "There should be 4 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\chocolatey\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\chocolatey\\Bob\\random.txt"); - files[2].Should().Be("c:\\chocolatey\\Bob\\tools\\chocolateyInstall.ps1"); - files[3].Should().Be("c:\\chocolatey\\Bob\\tools\\lower\\another.ps1"); + files.Should().HaveCount(4, "There should be 4 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\chocolatey\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\random.txt"); + files.Should().HaveElementAt(2,"c:\\chocolatey\\Bob\\tools\\chocolateyInstall.ps1"); + files.Should().HaveElementAt(3,"c:\\chocolatey\\Bob\\tools\\lower\\another.ps1"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine)); } @@ -414,16 +414,16 @@ public void Should_generate_all_files_and_directories_even_with_outputdirectory( because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\packages\\Bob"); - directories[1].Should().Be("c:\\packages\\Bob\\tools"); - directories[2].Should().Be("c:\\packages\\Bob\\tools\\lower"); + directories.Should().HaveCount(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\packages\\Bob"); + directories.Should().HaveElementAt(1,"c:\\packages\\Bob\\tools"); + directories.Should().HaveElementAt(2,"c:\\packages\\Bob\\tools\\lower"); - files.Count.Should().Be(4, "There should be 4 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\packages\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\packages\\Bob\\random.txt"); - files[2].Should().Be("c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); - files[3].Should().Be("c:\\packages\\Bob\\tools\\lower\\another.ps1"); + files.Should().HaveCount(4, "There should be 4 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\packages\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\packages\\Bob\\random.txt"); + files.Should().HaveElementAt(2,"c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); + files.Should().HaveElementAt(3,"c:\\packages\\Bob\\tools\\lower\\another.ps1"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine)); } @@ -496,18 +496,18 @@ public void Should_generate_all_files_and_directories() because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(5, "There should be 5 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\chocolatey\\Bob"); - directories[1].Should().Be("c:\\chocolatey\\Bob\\tools"); - directories[2].Should().Be("c:\\chocolatey\\Bob\\tools\\lower"); - directories[3].Should().Be("c:\\chocolatey\\Bob\\empty"); - directories[4].Should().Be("c:\\chocolatey\\Bob\\empty\\nested"); - - files.Count.Should().Be(4, "There should be 4 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\chocolatey\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\chocolatey\\Bob\\random.txt"); - files[2].Should().Be("c:\\chocolatey\\Bob\\tools\\chocolateyInstall.ps1"); - files[3].Should().Be("c:\\chocolatey\\Bob\\tools\\lower\\another.ps1"); + directories.Should().HaveCount(5, "There should be 5 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\chocolatey\\Bob"); + directories.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\tools"); + directories.Should().HaveElementAt(2,"c:\\chocolatey\\Bob\\tools\\lower"); + directories.Should().HaveElementAt(3,"c:\\chocolatey\\Bob\\empty"); + directories.Should().HaveElementAt(4,"c:\\chocolatey\\Bob\\empty\\nested"); + + files.Should().HaveCount(4, "There should be 4 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\chocolatey\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\chocolatey\\Bob\\random.txt"); + files.Should().HaveElementAt(2,"c:\\chocolatey\\Bob\\tools\\chocolateyInstall.ps1"); + files.Should().HaveElementAt(3,"c:\\chocolatey\\Bob\\tools\\lower\\another.ps1"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine)); } @@ -520,18 +520,18 @@ public void Should_generate_all_files_and_directories_even_with_outputdirectory( because(); var directories = directoryCreated.ToList(); - directories.Count.Should().Be(5, "There should be 5 directories, but there was: " + string.Join(", ", directories)); - directories[0].Should().Be("c:\\packages\\Bob"); - directories[1].Should().Be("c:\\packages\\Bob\\tools"); - directories[2].Should().Be("c:\\packages\\Bob\\tools\\lower"); - directories[3].Should().Be("c:\\packages\\Bob\\empty"); - directories[4].Should().Be("c:\\packages\\Bob\\empty\\nested"); - - files.Count.Should().Be(4, "There should be 4 files, but there was: " + string.Join(", ", files)); - files[0].Should().Be("c:\\packages\\Bob\\__name_replace__.nuspec"); - files[1].Should().Be("c:\\packages\\Bob\\random.txt"); - files[2].Should().Be("c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); - files[3].Should().Be("c:\\packages\\Bob\\tools\\lower\\another.ps1"); + directories.Should().HaveCount(5, "There should be 5 directories, but there was: " + string.Join(", ", directories)); + directories.Should().HaveElementAt(0,"c:\\packages\\Bob"); + directories.Should().HaveElementAt(1,"c:\\packages\\Bob\\tools"); + directories.Should().HaveElementAt(2,"c:\\packages\\Bob\\tools\\lower"); + directories.Should().HaveElementAt(3,"c:\\packages\\Bob\\empty"); + directories.Should().HaveElementAt(4,"c:\\packages\\Bob\\empty\\nested"); + + files.Should().HaveCount(4, "There should be 4 files, but there was: " + string.Join(", ", files)); + files.Should().HaveElementAt(0,"c:\\packages\\Bob\\__name_replace__.nuspec"); + files.Should().HaveElementAt(1,"c:\\packages\\Bob\\random.txt"); + files.Should().HaveElementAt(2,"c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); + files.Should().HaveElementAt(3,"c:\\packages\\Bob\\tools\\lower\\another.ps1"); MockLogger.MessagesFor(LogLevel.Info).Last().Should().Be(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine)); } @@ -849,8 +849,8 @@ public void Should_log_template_location_if_no_template_name() because(); var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Would have listed templates in {0}".FormatWith(ApplicationParameters.TemplatesLocation)); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Would have listed templates in {0}".FormatWith(ApplicationParameters.TemplatesLocation)); } [Fact] @@ -860,8 +860,8 @@ public void Should_log_template_name_if_template_name() because(); var infos = MockLogger.MessagesFor(LogLevel.Info); - infos.Count.Should().Be(1); - infos[0].Should().Be("Would have listed information about {0}".FormatWith(config.TemplateCommand.Name)); + infos.Should().ContainSingle(); + infos.Should().HaveElementAt(0,"Would have listed information about {0}".FormatWith(config.TemplateCommand.Name)); } } } diff --git a/src/chocolatey.tests/infrastructure/cryptography/CryptoHashProviderSpecs.cs b/src/chocolatey.tests/infrastructure/cryptography/CryptoHashProviderSpecs.cs index e589ec5c9a..db4685c48e 100644 --- a/src/chocolatey.tests/infrastructure/cryptography/CryptoHashProviderSpecs.cs +++ b/src/chocolatey.tests/infrastructure/cryptography/CryptoHashProviderSpecs.cs @@ -91,7 +91,7 @@ public override void Because() [Fact] public void Should_log_a_warning() { - MockLogger.MessagesFor(LogLevel.Warn).Count.Should().Be(1); + MockLogger.MessagesFor(LogLevel.Warn).Should().HaveCount(1); } [Fact] diff --git a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs index 618468f76e..126fec8e3b 100644 --- a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -180,13 +180,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(); } } @@ -218,10 +218,10 @@ public void GetExecutablePath_should_find_existing_executable() } else { - new string[] + FileSystem.GetExecutablePath("ls").Should().BeOneOf(new string[] { "/bin/ls", "/usr/bin/ls" - }.Should().Contain(FileSystem.GetExecutablePath("ls")); + }); } } @@ -234,13 +234,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(); } } } diff --git a/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs b/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs index 55e57efc18..995998b67f 100644 --- a/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs +++ b/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs @@ -531,7 +531,7 @@ public void Should_not_return_the_specified_error_message() // { // var messages = MockLogger.MessagesFor(LogLevel.Error); // messages.Should().NotBeEmpty(); - // messages.Count.Should().Be(1); + // messages.Should().ContainSingle(); // messages[0].Should().Contain("Trying to call ensureFunction on"); // } } diff --git a/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs b/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs index f11eb8df04..a2087de2f9 100644 --- a/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs +++ b/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs @@ -79,7 +79,7 @@ public void Should_log_warning_each_time() // don't care } - MockLogger.MessagesFor(LogLevel.Warn).Count.Should().Be(2); + MockLogger.MessagesFor(LogLevel.Warn).Should().HaveCount(2); } [Fact] @@ -117,7 +117,7 @@ public void Should_return_immediately_when_successful() i.Should().Be(1); - MockLogger.MessagesFor(LogLevel.Warn).Count.Should().Be(0); + MockLogger.MessagesFor(LogLevel.Warn).Should().BeEmpty(); } } @@ -137,7 +137,7 @@ public void Should_log_an_error_message() "You have an error" ); - MockLogger.MessagesFor(LogLevel.Error).Count.Should().Be(1); + MockLogger.MessagesFor(LogLevel.Error).Should().ContainSingle(); } [Fact] @@ -164,7 +164,7 @@ public void Should_log_a_warning_message_when_set_to_warn() logWarningInsteadOfError: true ); - MockLogger.MessagesFor(LogLevel.Warn).Count.Should().Be(1); + MockLogger.MessagesFor(LogLevel.Warn).Should().ContainSingle(); } [Fact]