Skip to content

Commit

Permalink
Merge pull request #334 from ferventcoder/ticket/stable/GH-331-transf…
Browse files Browse the repository at this point in the history
…orms

(GH-331) XDT configuration file transforms
  • Loading branch information
ferventcoder committed Jun 16, 2015
2 parents e5eb7fc + 7317c5b commit 0e06869
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 9 deletions.
43 changes: 41 additions & 2 deletions Scenarios.md
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 29 Scenario(s), 245 Observation(s) ]
### ChocolateyInstallCommand [ 30 Scenario(s), 254 Observation(s) ]

#### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies

Expand Down Expand Up @@ -223,6 +223,18 @@
* should not have warning package result
* should not install a package in the lib directory

#### when installing a package with config transforms

* should add the insert value in the config due to XDT InsertIfMissing
* should change the testReplace value in the config due to XDT Replace
* should contain a warning message that it installed successfully
* should have a successful package result
* should have a version of one dot zero dot zero
* should install the expected version of the package
* should not change the test value in the config due to XDT InsertIfMissing
* should not have inconclusive package result
* should not have warning package result

#### when installing a package with dependencies and dependency cannot be found

* should contain a warning message that it was unable to install any packages
Expand Down Expand Up @@ -456,7 +468,7 @@

* should throw an error that it is not allowed

### ChocolateyUpgradeCommand [ 23 Scenario(s), 183 Observation(s) ]
### ChocolateyUpgradeCommand [ 25 Scenario(s), 204 Observation(s) ]

#### when force upgrading a package

Expand Down Expand Up @@ -659,6 +671,33 @@
* should update the changed file
* should upgrade the package

#### when upgrading a package with config transforms

* should add the insertNew value in the config due to XDT InsertIfMissing
* should change the testReplace value in the config due to XDT Replace
* should contain a warning message that it upgraded successfully
* should have a successful package result
* should match the upgrade version of one dot one dot zero
* should not change the insert value in the config due to upgrade and XDT InsertIfMissing
* should not change the test value in the config from original one dot zero dot zero due to upgrade and XDT InsertIfMissing
* should not have inconclusive package result
* should not have warning package result
* should upgrade the package

#### when upgrading a package with config transforms when config was edited

* should add the insertNew value in the config due to XDT InsertIfMissing
* should change the testReplace value in the config due to XDT Replace
* should contain a warning message that it upgraded successfully
* should have a config with the comment from the original
* should have a successful package result
* should match the upgrade version of one dot one dot zero
* should not change the insert value in the config due to upgrade and XDT InsertIfMissing
* should not change the test value in the config from original one dot zero dot zero due to upgrade and XDT InsertIfMissing
* should not have inconclusive package result
* should not have warning package result
* should upgrade the package

#### when upgrading a package with dependencies happy

* should contain a message that everything upgraded successfully
Expand Down
Expand Up @@ -90,7 +90,9 @@
<Compile Include="TODO.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="context\badpackage\badpackage.1.0.nupkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
@@ -1 +1 @@
1.1.0
1.0.0
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="test" value="default 1.0.0"/>
<add key="testReplace" value="default 1.0.0"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings xdt:Transform="InsertIfMissing">
<add key="test" value="1.0.0" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
<add key="testReplace" value="1.0.0" xdt:Locator="Match(key)" xdt:Transform="Replace"/>
<add key="insert" value="1.0.0" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing"/>
</appSettings>
</configuration>
@@ -1 +1 @@
1.1.0
1.0.0
@@ -1 +1 @@
1.1.0
1.0.0
Binary file not shown.
Binary file not shown.
Expand Up @@ -5,7 +5,7 @@
<!-- Read this before publishing packages to chocolatey.org: https://github.com/chocolatey/chocolatey/wiki/CreatePackages -->
<id>upgradepackage</id>
<title>upgradepackage</title>
<version>1.1.0</version>
<version>1.0.0</version>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<summary>__REPLACE__</summary>
Expand Down
90 changes: 90 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Expand Up @@ -19,6 +19,9 @@ namespace chocolatey.tests.integration.scenarios
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.XPath;
using Microsoft.Web.XmlTransform;
using NuGet;
using Should;
using bdddoc.core;
Expand Down Expand Up @@ -2837,5 +2840,92 @@ public void should_have_a_version_of_one_dot_zero_dot_zero()
packageResult.Version.ShouldEqual("1.0.0");
}
}

[Concern(typeof(ChocolateyInstallCommand))]
public class when_installing_a_package_with_config_transforms : ScenariosBase
{
private PackageResult packageResult;
private string _xmlFilePath = string.Empty;
private XPathNavigator _xPathNavigator;

public override void Context()
{
base.Context();
Configuration.PackageNames = Configuration.Input = "upgradepackage";
Scenario.add_packages_to_source_location(Configuration, "upgradepackage.1.0.0*" + Constants.PackageExtension);

_xmlFilePath = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe.config");
}

public override void Because()
{
Results = Service.install_run(Configuration);
packageResult = Results.FirstOrDefault().Value;
var xmlDocument = new XPathDocument(_xmlFilePath);
_xPathNavigator = xmlDocument.CreateNavigator();
}

[Fact]
public void should_install_the_expected_version_of_the_package()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension);
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.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).or_empty_list_if_null())
{
if (message.Contains("1/1")) installedSuccessfully = true;
}

installedSuccessfully.ShouldBeTrue();
}

[Fact]
public void should_have_a_successful_package_result()
{
packageResult.Success.ShouldBeTrue();
}

[Fact]
public void should_not_have_inconclusive_package_result()
{
packageResult.Inconclusive.ShouldBeFalse();
}

[Fact]
public void should_not_have_warning_package_result()
{
packageResult.Warning.ShouldBeFalse();
}

[Fact]
public void should_have_a_version_of_one_dot_zero_dot_zero()
{
packageResult.Version.ShouldEqual("1.0.0");
}

[Fact]
public void should_not_change_the_test_value_in_the_config_due_to_XDT_InsertIfMissing()
{
_xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='test']/@value").TypedValue.to_string().ShouldEqual("default 1.0.0");
}

[Fact]
public void should_change_the_testReplace_value_in_the_config_due_to_XDT_Replace()
{
_xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='testReplace']/@value").TypedValue.to_string().ShouldEqual("1.0.0");
}

[Fact]
public void should_add_the_insert_value_in_the_config_due_to_XDT_InsertIfMissing()
{
_xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='insert']/@value").TypedValue.to_string().ShouldEqual("1.0.0");
}
}
}
}

0 comments on commit 0e06869

Please sign in to comment.