Switching the CopyToOutput for build and publish and the file for pack to use None Update instead of include. Also, fixed the exclude patterns for web apps.

This commit is contained in:
Livar Cunha 2017-02-22 23:16:54 -08:00
parent 1228c7ef55
commit b660311772
9 changed files with 175 additions and 103 deletions

View file

@ -477,7 +477,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Theory]
[InlineData("compile", "Compile", 3, "")]
[InlineData("embed", "EmbeddedResource", 3, ";rootfile.cs")]
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")]
public void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
string group,
string itemName,
@ -514,8 +513,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
if (string.IsNullOrEmpty(item.Include))
{
item.Remove.Should()
.Be(@"src\**\*;rootfile.cs;src\file2.cs");
item.Remove.Should()
.Be(@"src\**\*;rootfile.cs;src\file2.cs");
}
else if (item.Include.Contains(@"src\file1.cs"))
{
@ -550,10 +549,56 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
}
[Theory]
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")]
public void MigratingCopyToOutputIncludeExcludePopulatesAppropriateProjectItemElement(
string group,
string itemName,
int expectedNumberOfCompileItems,
string expectedRootFiles)
{
var testDirectory = Temp.CreateDirectory().Path;
WriteExtraFiles(testDirectory);
var pj = @"
{
""buildOptions"": {
""<group>"": {
""include"": [""root"", ""src"", ""rootfile.cs""],
""exclude"": [""src"", ""rootfile.cs""],
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
""excludeFiles"": [""src/file2.cs""]
}
}
}".Replace("<group>", group);
var mockProj = RunBuildOptionsRuleOnPj(pj,
testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal))
.Should().Be(expectedNumberOfCompileItems);
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)))
{
VerifyContentMetadata(item);
if (string.IsNullOrEmpty(item.Update))
{
}
else if (item.Update.Contains(@"src\file1.cs"))
{
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
}
else
{
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs");
}
}
}
[Theory]
[InlineData("compile", "Compile", "")]
[InlineData("embed", "EmbeddedResource", ";rootfile.cs")]
[InlineData("copyToOutput", "None", ";rootfile.cs")]
public void MigratingGroupIncludeOnlyPopulatesAppropriateProjectItemElement(
string group,
string itemName,
@ -572,8 +617,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = RunBuildOptionsRuleOnPj(pj,
testDirectory: testDirectory);
Console.WriteLine(mockProj.RawXml);
mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)).Should().Be(1);
var defaultIncludePatterns = GetDefaultIncludePatterns(group);
@ -607,6 +650,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
}
[Theory]
[InlineData("copyToOutput", "None", ";rootfile.cs")]
public void MigratingCopyToOutputIncludeOnlyPopulatesAppropriateProjectItemElement(
string group,
string itemName,
string expectedRootFiles)
{
var testDirectory = Temp.CreateDirectory().Path;
WriteExtraFiles(testDirectory);
var pj = @"
{
""buildOptions"": {
""<group>"": [""root"", ""src"", ""rootfile.cs""]
}
}".Replace("<group>", group);
var mockProj = RunBuildOptionsRuleOnPj(pj,
testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)).Should().Be(1);
mockProj.Items.Single().Update.Should().Be($@"root\**\*;src\**\*{expectedRootFiles}");
}
[Fact]
public void MigratingTestProjectAddsGenerateRuntimeConfigurationFiles()
{

View file

@ -178,23 +178,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(4);
contentItems.Count().Should().Be(3);
// 2 for Base Build options
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2);
// 2 for Configuration BuildOptions (1 Remove, 1 Include)
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(2);
// 2 for Configuration BuildOptions (1 Remove, 1 Update)
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1);
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Include));
var configRemoveContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove));
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Update));
//var configRemoveContentItem = contentItems.First(
// item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove));
// Directories are not converted to globs in the result because we did not write the directory
configRemoveContentItem.Remove.Should().Be(@"root;src;rootfile.cs");
configIncludeContentItem.Include.Should().Be(@"root;src;rootfile.cs");
configIncludeContentItem.Exclude.Should().Be(@"src;root\rootfile.cs;src\file2.cs");
//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");
}
[Fact]
@ -226,35 +226,46 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(5);
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);
// 2 for Base Build options
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2);
// 3 for Configuration BuildOptions (1 Remove, 2 Include)
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3);
// 3 for Configuration BuildOptions (1 Remove, 2 Update)
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1);
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains("root"));
&& item.Update.Contains("root"));
var configIncludeContentItem2 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains(@"src\file1.cs"));
item => item.ConditionChain().Count() == 0
&& item.Update.Contains(@"src\file1.cs"));
var configRemoveContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove));
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));
// Directories are not converted to globs in the result because we did not write the directory
configRemoveContentItem.Removes()
.Should().BeEquivalentTo("root", "src", "rootfile.cs", @"src\file1.cs", @"src\file2.cs");
//configRemoveContentItem.Removes()
// .Should().BeEquivalentTo("root", "src", "rootfile.cs", @"src\file1.cs", @"src\file2.cs");
configIncludeContentItem.Includes().Should().BeEquivalentTo("root", "src", "rootfile.cs");
configIncludeContentItem.Excludes()
.Should().BeEquivalentTo("rootfile.cs", "someotherfile.cs", @"src\file2.cs");
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "rootfile.cs");
//configIncludeContentItem.Excludes()
// .Should().BeEquivalentTo("rootfile.cs", "someotherfile.cs", @"src\file2.cs");
configIncludeContentItem2.Includes().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
//configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src");
}
[Fact]
@ -287,15 +298,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains("root"));
&& item.Update.Contains("root"));
var configIncludeContentItem2 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains(@"src\file1.cs"));
&& item.Update.Contains(@"src\file1.cs"));
configIncludeContentItem.Includes().Should().BeEquivalentTo("root", "src");
configIncludeContentItem.Excludes()
.Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "src");
// configIncludeContentItem.Excludes()
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
@ -303,8 +314,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem2.Includes().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs");
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs");
configIncludeContentItem2.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
@ -345,36 +356,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include == "root");
&& item.Update == "root");
var configIncludeContentItem2 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include == "src");
&& item.Update == "src");
var configIncludeContentItem3 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains(@"src\file1.cs"));
&& item.Update.Contains(@"src\file1.cs"));
// Directories are not converted to globs in the result because we did not write the directory
configIncludeContentItem.Includes().Should().BeEquivalentTo("root");
configIncludeContentItem.Excludes()
.Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.Updates().Should().BeEquivalentTo("root");
// configIncludeContentItem.Excludes()
// .Should().BeEquivalentTo("rootfile.cs", "src", @"src\file2.cs");
configIncludeContentItem.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
configIncludeContentItem2.Include.Should().Be("src");
configIncludeContentItem2.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
configIncludeContentItem2.Update.Should().Be("src");
// configIncludeContentItem2.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
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");
configIncludeContentItem3.Includes().Should().BeEquivalentTo(@"src\file1.cs");
configIncludeContentItem3.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src\file1.cs");
// configIncludeContentItem3.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem3.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem3.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
@ -427,13 +438,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains("src"));
&& item.Update.Contains("src"));
var configRemoveContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& !string.IsNullOrEmpty(item.Remove));
configIncludeContentItem.Include.Should().Be("src");
configIncludeContentItem.Update.Should().Be("src");
configIncludeContentItem.GetMetadataWithName("Link").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
@ -492,31 +503,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var configIncludeEncompassedItem = contentItems.FirstOrDefault(
item => item.ConditionChain().Count() > 0
&& item.Include == "root");
&& item.Update == "root");
configIncludeEncompassedItem.Should().BeNull();
var configIncludeContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include == "src");
&& item.Update == "src");
var configIncludeContentItem2 = contentItems.First(
item => item.ConditionChain().Count() > 0
&& item.Include.Contains(@"src\file3.cs"));
&& item.Update.Contains(@"src\file3.cs"));
var configRemoveContentItem = contentItems.First(
item => item.ConditionChain().Count() > 0
&& !string.IsNullOrEmpty(item.Remove));
configIncludeContentItem.Include.Should().Be("src");
configIncludeContentItem.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
configIncludeContentItem.Update.Should().Be("src");
//configIncludeContentItem.Excludes().Should().BeEquivalentTo("src", "rootfile.cs", @"src\rootfile.cs", @"src\file2.cs");
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");
configIncludeContentItem2.Includes().Should().BeEquivalentTo(@"src\file3.cs");
configIncludeContentItem2.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file3.cs");
//configIncludeContentItem2.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem2.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();

View file

@ -204,7 +204,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
.Where(item => item.GetMetadataWithName("Pack").Value == "true");
contentItems.Count().Should().Be(1);
contentItems.First().Include.Should().Be(@"path\to\some\file.cs;path\to\some\other\file.cs");
contentItems.First().Update.Should().Be(@"path\to\some\file.cs;path\to\some\other\file.cs");
}
[Fact]
@ -229,7 +229,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.GetMetadataWithName("PackagePath") != null);
contentItems.Count().Should().Be(1);
contentItems.First().Include.Should().Be(@"path\to\some\file.cs");
contentItems.First().Update.Should().Be(@"path\to\some\file.cs");
contentItems.First().GetMetadataWithName("PackagePath").Value.Should().Be(
Path.Combine("some", "other", "path"));
}
@ -256,7 +256,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.GetMetadataWithName("PackagePath") != null);
contentItems.Count().Should().Be(1);
contentItems.First().Include.Should().Be(@"path\to\some\file.cs");
contentItems.First().Update.Should().Be(@"path\to\some\file.cs");
contentItems.First().GetMetadataWithName("PackagePath").Value.Should().BeEmpty();
}
@ -290,7 +290,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.GetMetadataWithName("PackagePath") != null);
contentItems.Count().Should().Be(1);
contentItems.First().Include.Should().Be(@"path\to\some\file.cs");
contentItems.First().Update.Should().Be(@"path\to\some\file.cs");
contentItems.First().GetMetadataWithName("PackagePath").Value.Should().Be(expectedPackagePath);
}

View file

@ -38,18 +38,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
item.Metadata.Count(m => m.Name == "CopyToPublishDirectory").Should().Be(1);
if (item.Include.Contains(@"src\file1.cs"))
if (item.Update.Contains(@"src\file1.cs"))
{
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
item.Exclude.Should().Be(@"src\file2.cs");
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
item.Exclude.Should().BeEmpty();
}
else
{
item.Include.Should()
.Be(@"root\**\*;src\**\*;rootfile.cs");
item.Exclude.Should()
.Be(@"src\**\*;rootfile.cs;src\file2.cs");
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs");
item.Exclude.Should().BeEmpty();
}
}
}
@ -128,29 +125,25 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal)).Should().Be(3);
// From ProjectReader #L725 (Both are empty)
var defaultIncludePatterns = Enumerable.Empty<string>();
var defaultExcludePatterns = Enumerable.Empty<string>();
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal)))
{
if (item.Include.Contains(@"root\**\*"))
if (item.Update.Contains(@"root\**\*"))
{
item.Include.Should().Be(@"root\**\*");
item.Exclude.Should().Be(@"src\**\*;rootfile.cs;src\file3.cs");
item.Update.Should().Be(@"root\**\*");
//item.Exclude.Should().Be(@"src\**\*;rootfile.cs;src\file3.cs");
}
else if (item.Include.Contains(@"src\file1.cs"))
else if (item.Update.Contains(@"src\file1.cs"))
{
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
item.Exclude.Should().Be(@"src\file2.cs;src\file3.cs");
item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
//item.Exclude.Should().Be(@"src\file2.cs;src\file3.cs");
}
else
{
item.Include.Should()
item.Update.Should()
.Be(@"src\**\*;rootfile.cs");
item.Exclude.Should()
.Be(@"src\**\*;rootfile.cs;src\file2.cs;src\file3.cs");
//item.Exclude.Should()
// .Be(@"src\**\*;rootfile.cs;src\file2.cs;src\file3.cs");
}
}
}