Skip to content

Commit

Permalink
(chocolateyGH-268) Use MockLogger.contains_message in verification ex…
Browse files Browse the repository at this point in the history
…pressions.
  • Loading branch information
Richard J Foster authored and Richard J Foster committed Mar 9, 2016
1 parent 8c07704 commit 04fdfe5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
18 changes: 3 additions & 15 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();
}
}

Expand Down

0 comments on commit 04fdfe5

Please sign in to comment.