2016-08-22 19:24:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration.Tests;
|
|
|
|
|
|
2016-09-14 22:30:11 +00:00
|
|
|
|
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
public class GivenThatIWantToMigrateConfigurations : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsProduceExpectedPropertiesInAGroupWithACondition()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""emitEntryPoint"": ""true"",
|
|
|
|
|
""debugType"": ""full""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(
|
2016-08-23 20:50:05 +00:00
|
|
|
|
prop => prop.Name == "OutputType" || prop.Name == "DebugType").Should().Be(2);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
mockProj.Properties.First(p => p.Name == "OutputType")
|
|
|
|
|
.Parent.Condition.Should()
|
|
|
|
|
.Contain("'$(Configuration)' == 'testconfig'");
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 21:40:46 +00:00
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void FrameworksBuildOptionsProduceExpectedPropertiesInAGroupWithACondition()
|
2016-09-08 21:40:46 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""frameworks"": {
|
|
|
|
|
""netcoreapp1.0"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""emitEntryPoint"": ""true"",
|
|
|
|
|
""debugType"": ""full""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(
|
|
|
|
|
prop => prop.Name == "OutputType" || prop.Name == "DebugType").Should().Be(2);
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.First(p => p.Name == "OutputType")
|
|
|
|
|
.Parent.Condition.Should()
|
2016-10-12 21:59:36 +00:00
|
|
|
|
.Contain("'$(TargetFramework)' == 'netcoreapp1.0'");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
}
|
2016-11-02 22:05:45 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ItDoesNotAddADefineForTheFramework()
|
2016-11-02 22:05:45 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""frameworks"": {
|
|
|
|
|
""netcoreapp1.0"": {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(
|
2017-01-05 19:46:02 +00:00
|
|
|
|
prop => prop.Name == "DefineConstants" && prop.Value.Contains("NETCOREAPP10")).Should().Be(0);
|
2016-11-02 22:05:45 +00:00
|
|
|
|
}
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ItDoesNotAddADefineForReleaseConfiguration()
|
|
|
|
|
{
|
|
|
|
|
var mockProj = RunRulesOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""frameworks"": {
|
|
|
|
|
""netcoreapp1.0"": {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}",
|
|
|
|
|
new IMigrationRule[]
|
|
|
|
|
{
|
|
|
|
|
new AddDefaultsToProjectRule(),
|
|
|
|
|
new MigrateConfigurationsRule(),
|
|
|
|
|
new RemoveDefaultsFromProjectRule()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(
|
|
|
|
|
prop => prop.Name == "DefineConstants" && prop.Value.Contains("Release")).Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ItDoesNotAddADefineForDebugConfiguration()
|
|
|
|
|
{
|
|
|
|
|
var mockProj = RunRulesOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""frameworks"": {
|
|
|
|
|
""netcoreapp1.0"": {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}",
|
|
|
|
|
new IMigrationRule[]
|
|
|
|
|
{
|
|
|
|
|
new AddDefaultsToProjectRule(),
|
|
|
|
|
new MigrateConfigurationsRule(),
|
|
|
|
|
new RemoveDefaultsFromProjectRule()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(
|
|
|
|
|
prop => prop.Name == "DefineConstants" && prop.Value.Contains("Debug")).Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ConfigurationBuildOptionsPropertiesAreNotWrittenWhenTheyOverlapWithBuildOptions()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""emitEntryPoint"": ""true"",
|
|
|
|
|
""debugType"": ""full""
|
|
|
|
|
},
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""emitEntryPoint"": ""true"",
|
|
|
|
|
""debugType"": ""full""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
|
|
|
|
mockProj.Properties.Count(property =>
|
2016-08-23 20:50:05 +00:00
|
|
|
|
property.Name == "OutputType" || property.Name == "DebugType")
|
|
|
|
|
.Should().Be(2);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
foreach (var property in mockProj.Properties.Where(property =>
|
2016-08-23 20:50:05 +00:00
|
|
|
|
property.Name == "OutputType" || property.Name == "DebugType"))
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
property.Parent.Condition.Should().Be(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsIncludesAndRemoveAreWrittenWhenTheyDifferFromBaseBuildOptions()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""root"", ""src"", ""rootfile.cs""],
|
2016-09-21 21:41:16 +00:00
|
|
|
|
""exclude"": [""src"", ""root/rootfile.cs""],
|
2016-08-22 19:24:10 +00:00
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
contentItems.Count().Should().Be(3);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-09-08 21:40:46 +00:00
|
|
|
|
// 2 for Base Build options
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
// 2 for Configuration BuildOptions (1 Remove, 1 Update)
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1);
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
2017-02-23 07:16:54 +00:00
|
|
|
|
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Update));
|
|
|
|
|
//var configRemoveContentItem = contentItems.First(
|
|
|
|
|
// item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove));
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
// Directories are not converted to globs in the result because we did not write the directory
|
2017-02-23 07:16:54 +00:00
|
|
|
|
//configRemoveContentItem.Remove.Should().Be(@"root;src;rootfile.cs");
|
|
|
|
|
configIncludeContentItem.Update.Should().Be(@"root;rootfile.cs");
|
|
|
|
|
//configIncludeContentItem.Exclude.Should().Be(@"src;root\rootfile.cs;src\file2.cs");
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsWhichHaveDifferentExcludesThanBuildOptionsOverwrites()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-09-08 21:40:46 +00:00
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src""],
|
|
|
|
|
""exclude"": [""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file3.cs""]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""root"", ""src"", ""rootfile.cs""],
|
2016-09-08 21:40:46 +00:00
|
|
|
|
""exclude"": [""rootfile.cs"", ""someotherfile.cs""],
|
2016-08-22 19:24:10 +00:00
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
foreach(var c in contentItems)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Include: {c.Include}, Update: {c.Update}, Remove: {c.Remove}, Condition: {c.ConditionChain().Count()}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentItems.Count().Should().Be(3);
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
// 2 for Base Build options
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2);
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
// 3 for Configuration BuildOptions (1 Remove, 2 Update)
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1);
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains("root"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem2 = contentItems.First(
|
2017-02-23 07:16:54 +00:00
|
|
|
|
item => item.ConditionChain().Count() == 0
|
|
|
|
|
&& item.Update.Contains(@"src\file1.cs"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
var configIncludeContentItem3 = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() == 0
|
|
|
|
|
&& item.Update.Equals(@"src"));
|
|
|
|
|
|
|
|
|
|
//var configRemoveContentItem = contentItems.First(
|
|
|
|
|
// item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
// Directories are not converted to globs in the result because we did not write the directory
|
2017-02-23 07:16:54 +00:00
|
|
|
|
//configRemoveContentItem.Removes()
|
|
|
|
|
// .Should().BeEquivalentTo("root", "src", "rootfile.cs", @"src\file1.cs", @"src\file2.cs");
|
|
|
|
|
|
|
|
|
|
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "rootfile.cs");
|
|
|
|
|
//configIncludeContentItem.Excludes()
|
|
|
|
|
// .Should().BeEquivalentTo("rootfile.cs", "someotherfile.cs", @"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
|
|
|
|
|
//configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsWhichHaveMappingsToDirectoryAddLinkMetadataWithItemMetadata()
|
2016-09-08 21:40:46 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""mappings"": {
|
|
|
|
|
""/some/dir/"" : {
|
|
|
|
|
""include"": [""src"", ""root""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
contentItems.Count().Should().Be(2);
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(2);
|
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains("root"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem2 = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains(@"src\file1.cs"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "src");
|
|
|
|
|
// configIncludeContentItem.Excludes()
|
|
|
|
|
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
|
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
|
|
|
|
|
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
|
|
|
|
|
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInSameConfigurationMergedItemsHaveLinkMetadata()
|
2016-09-08 21:40:46 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src"", ""root""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""],
|
|
|
|
|
""mappings"": {
|
|
|
|
|
""/some/dir/"" : {
|
|
|
|
|
""include"": [""src""],
|
|
|
|
|
""exclude"": [""src"", ""src/rootfile.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
contentItems.Count().Should().Be(3);
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3);
|
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update == "root");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem2 = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update == "src");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem3 = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains(@"src\file1.cs"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
// Directories are not converted to globs in the result because we did not write the directory
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem.Updates().Should().BeEquivalentTo("root");
|
|
|
|
|
// configIncludeContentItem.Excludes()
|
|
|
|
|
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Should().BeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem2.Update.Should().Be("src");
|
|
|
|
|
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src\file1.cs");
|
|
|
|
|
// configIncludeContentItem3.Exclude.Should().Be(@"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem3.GetMetadataWithName("Link").Should().BeNull();
|
|
|
|
|
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInRootBuildoptionsHasRemove()
|
2016-09-08 21:40:46 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""buildOptions"" : {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src"", ""root""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""mappings"": {
|
|
|
|
|
""/some/dir/"" : {
|
|
|
|
|
""include"": [""src""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
contentItems.Count().Should().Be(4);
|
|
|
|
|
|
|
|
|
|
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
|
|
|
|
|
rootBuildOptionsContentItems.Count().Should().Be(2);
|
|
|
|
|
foreach (var buildOptionContentItem in rootBuildOptionsContentItems)
|
|
|
|
|
{
|
|
|
|
|
buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull();
|
|
|
|
|
buildOptionContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var configItems = contentItems.Where(i => i.ConditionChain().Count() == 1);
|
|
|
|
|
configItems.Should().HaveCount(2);
|
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains("src"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configRemoveContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
|
|
|
|
&& !string.IsNullOrEmpty(item.Remove));
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem.Update.Should().Be("src");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
|
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
|
|
|
|
configRemoveContentItem.Remove.Should().Be("src");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-01-05 19:46:02 +00:00
|
|
|
|
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInSameConfigurationAndRootBuildOptionsHaveRemovesAndLinkMetadataAndEncompassedItemsAreMerged()
|
2016-09-08 21:40:46 +00:00
|
|
|
|
{
|
|
|
|
|
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj(@"
|
|
|
|
|
{
|
|
|
|
|
""buildOptions"" : {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src"", ""root""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file1.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
""configurations"": {
|
|
|
|
|
""testconfig"": {
|
|
|
|
|
""buildOptions"": {
|
|
|
|
|
""copyToOutput"": {
|
|
|
|
|
""include"": [""src"", ""root""],
|
|
|
|
|
""exclude"": [""src"", ""rootfile.cs""],
|
|
|
|
|
""includeFiles"": [""src/file3.cs""],
|
|
|
|
|
""excludeFiles"": [""src/file2.cs""],
|
|
|
|
|
""mappings"": {
|
|
|
|
|
""/some/dir/"" : {
|
|
|
|
|
""include"": [""src""],
|
|
|
|
|
""exclude"": [""src"", ""src/rootfile.cs""]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2017-02-23 06:06:45 +00:00
|
|
|
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
contentItems.Count().Should().Be(5);
|
|
|
|
|
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3);
|
|
|
|
|
|
|
|
|
|
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
|
|
|
|
|
rootBuildOptionsContentItems.Count().Should().Be(2);
|
|
|
|
|
foreach (var buildOptionContentItem in rootBuildOptionsContentItems)
|
|
|
|
|
{
|
|
|
|
|
buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull();
|
|
|
|
|
buildOptionContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var configIncludeEncompassedItem = contentItems.FirstOrDefault(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update == "root");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
configIncludeEncompassedItem.Should().BeNull();
|
|
|
|
|
|
|
|
|
|
var configIncludeContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update == "src");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configIncludeContentItem2 = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
2017-02-23 07:16:54 +00:00
|
|
|
|
&& item.Update.Contains(@"src\file3.cs"));
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
var configRemoveContentItem = contentItems.First(
|
|
|
|
|
item => item.ConditionChain().Count() > 0
|
|
|
|
|
&& !string.IsNullOrEmpty(item.Remove));
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem.Update.Should().Be("src");
|
|
|
|
|
//configIncludeContentItem.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
2017-02-23 07:16:54 +00:00
|
|
|
|
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file3.cs");
|
|
|
|
|
//configIncludeContentItem2.Exclude.Should().Be(@"src\file2.cs");
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("Link").Should().BeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
|
|
|
|
|
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
|
|
|
|
|
|
|
|
|
|
configRemoveContentItem.Removes().Should().BeEquivalentTo("src");
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
2016-09-08 21:40:46 +00:00
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
private ProjectRootElement RunConfigurationsRuleOnPj(string s, string testDirectory = null)
|
|
|
|
|
{
|
|
|
|
|
testDirectory = testDirectory ?? Temp.CreateDirectory().Path;
|
2017-01-05 19:46:02 +00:00
|
|
|
|
return RunRulesOnPj(s, new[] { new MigrateConfigurationsRule() }, testDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProjectRootElement RunConfigurationsAndBuildOptionsRuleOnPj(string s, string testDirectory = null)
|
|
|
|
|
{
|
2017-01-05 19:46:02 +00:00
|
|
|
|
return RunRulesOnPj(
|
|
|
|
|
s,
|
|
|
|
|
new IMigrationRule[]
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
new MigrateBuildOptionsRule(),
|
|
|
|
|
new MigrateConfigurationsRule()
|
2017-01-05 19:46:02 +00:00
|
|
|
|
},
|
|
|
|
|
testDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProjectRootElement RunRulesOnPj(string s, IMigrationRule[] migrationRules, string testDirectory = null)
|
|
|
|
|
{
|
|
|
|
|
testDirectory = testDirectory ?? Temp.CreateDirectory().Path;
|
|
|
|
|
return TemporaryProjectFileRuleRunner.RunRules(migrationRules, s, testDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|