From 04fdfe5361df959ae07185cb54d34ebd0949c403 Mon Sep 17 00:00:00 2001 From: Richard J Foster Date: Sat, 9 Jan 2016 08:51:21 -0500 Subject: [PATCH] (GH-268) Use MockLogger.contains_message in verification expressions. --- .../scenarios/InstallScenarios.cs | 18 +++--------------- .../scenarios/UninstallScenarios.cs | 14 ++++---------- .../scenarios/UpgradeScenarios.cs | 12 +++++++++--- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index f23b5ff8f1..e7d9e732fc 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -93,25 +93,13 @@ public void should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_ [Fact] public void should_contain_a_message_that_it_would_have_run_a_powershell_script() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) - { - if (message.Contains("chocolateyinstall.ps1")) expectedMessage = true; - } - - expectedMessage.ShouldBeTrue(); + MockLogger.contains_message("chocolateyinstall.ps1", LogLevel.Info).ShouldBeTrue(); } [Fact] public void should_not_contain_a_message_that_it_would_have_run_powershell_modification_script() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) - { - if (message.Contains("chocolateyBeforeModify.ps1")) expectedMessage = true; - } - - expectedMessage.ShouldBeFalse(); + MockLogger.contains_message("chocolateyBeforeModify.ps1", LogLevel.Info).ShouldBeFalse(); } } @@ -331,7 +319,7 @@ public void should_have_a_version_of_one_dot_zero_dot_zero() [Fact] public void should_have_executed_chocolateyInstall_script() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.Contains("installpackage v1.0.0 has been installed")).ShouldBeTrue("Installpackage info message not seen. Info messages that were seen: {0}".format_with(string.Join(Environment.NewLine, MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()))); + MockLogger.contains_message("installpackage v1.0.0 has been installed", LogLevel.Info).ShouldBeTrue(); } } diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index 29652b1414..59fb2094c2 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -95,19 +95,13 @@ public void should_contain_a_message_that_it_would_have_uninstalled_a_package() [Fact] public void should_contain_a_message_that_it_would_have_run_a_powershell_script() { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) - { - if (message.Contains("chocolateyuninstall.ps1")) expectedMessage = true; - } - - expectedMessage.ShouldBeTrue(); + MockLogger.contains_message("chocolateyuninstall.ps1").ShouldBeTrue(); } [Fact] public void should_contain_a_message_that_it_would_have_run_powershell_modification_script() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.Contains("chocolateyBeforeModify.ps1")).ShouldBeTrue(); + MockLogger.contains_message("chocolateyBeforeModify.ps1").ShouldBeTrue(); } } @@ -229,13 +223,13 @@ public void config_should_match_package_result_name() [Fact] public void should_have_executed_chocolateyBeforeModify_script() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.Contains("installpackage 1.0.0 Before Modification")).ShouldBeTrue(); + MockLogger.contains_message("installpackage 1.0.0 Before Modification", LogLevel.Info).ShouldBeTrue(); } [Fact] public void should_have_executed_chocolateyUninstall_script() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.EndsWith("installpackage 1.0.0 Uninstalled")).ShouldBeTrue(); + MockLogger.contains_message("installpackage 1.0.0 Uninstalled", LogLevel.Info).ShouldBeTrue(); } } diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 2ba4db10fe..9d5dbf2e71 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -306,7 +306,7 @@ public void should_match_the_upgrade_version_of_one_dot_one_dot_zero() [Fact] public void should_have_executed_chocolateyBeforeModify_script_for_original_package() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.Contains("upgradepackage 1.0.0 Before Modification")).ShouldBeTrue(); + MockLogger.contains_message("upgradepackage 1.0.0 Before Modification", LogLevel.Info).ShouldBeTrue(); } [Fact] @@ -321,13 +321,19 @@ public void should_have_executed_chocolateyBeforeModify_before_chocolateyInstall [Fact] public void should_not_have_executed_chocolateyUninstall_script_for_original_package() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.EndsWith("upgradepackage 1.0.0 Uninstalled")).ShouldBeFalse(); + MockLogger.contains_message("upgradepackage 1.0.0 Uninstalled", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_not_have_executed_chocolateyBeforeModify_script_for_new_package() + { + MockLogger.contains_message("upgradepackage 1.1.0 Before Modification", LogLevel.Info).ShouldBeFalse(); } [Fact] public void should_have_executed_chocolateyInstall_script_for_new_package() { - MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null().Any(p => p.EndsWith("upgradepackage 1.1.0 Installed")).ShouldBeTrue(); + MockLogger.contains_message("upgradepackage 1.1.0 Installed", LogLevel.Info).ShouldBeTrue(); } }