Merging metadata with different values by setting the metadata values to be string joined and semi-column separated. This fixes the problem of having multiple mappings for the same file in a include/mappings.

This commit is contained in:
Livar Cunha 2016-10-25 15:26:04 -07:00
parent 2cc007520d
commit 71aa93b164
2 changed files with 66 additions and 2 deletions

View file

@ -260,6 +260,40 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
contentItems.First().GetMetadataWithName("PackagePath").Value.Should().BeEmpty();
}
[Fact]
public void Migrating_same_file_with_multiple_mappings_string_joins_the_mappings_in_PackagePath()
{
var mockProj = RunPackOptionsRuleOnPj(@"
{
""packOptions"": {
""files"": {
""include"": [""path/to/some/file.cs""],
""mappings"": {
""other/path/file.cs"": ""path/to/some/file.cs"",
""different/path/file1.cs"": ""path/to/some/file.cs""
}
}
}
}");
var expectedPackagePath = string.Join(
";",
new [] {
Path.Combine("different", "path"),
Path.Combine("other", "path")
});
var contentItems = mockProj.Items
.Where(item => item.ItemType.Equals("Content", StringComparison.Ordinal))
.Where(item =>
item.GetMetadataWithName("Pack").Value == "true" &&
item.GetMetadataWithName("PackagePath") != null);
contentItems.Count().Should().Be(1);
contentItems.First().Include.Should().Be(@"path\to\some\file.cs");
contentItems.First().GetMetadataWithName("PackagePath").Value.Should().Be(expectedPackagePath);
}
private ProjectRootElement RunPackOptionsRuleOnPj(string packOptions, string testDirectory = null)
{
testDirectory = testDirectory ?? Temp.CreateDirectory().Path;