Intermediate commit to get a WIP PR out. This adds the None Update with CopyToOutputDirectory set to Never.

This commit is contained in:
Livar Cunha 2017-02-23 18:46:44 -08:00
parent b660311772
commit f05bbd92a6
6 changed files with 311 additions and 90 deletions

View file

@ -0,0 +1,38 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace Microsoft.DotNet.Internal.ProjectModel.Files
{
// Similar to IncludeContext, except that it replaces the include information with the exclude information and clears
// out the exclude information. This is to be used by migration to do CopyToOutput with Never set as its metadata.
internal class ExcludeContext : IncludeContext
{
public ExcludeContext(
string sourceBasePath,
string option,
JObject rawObject,
string[] defaultBuiltInInclude,
string[] defaultBuiltInExclude) : base(
sourceBasePath,
option,
rawObject,
defaultBuiltInInclude,
defaultBuiltInExclude)
{
IncludePatterns = ExcludePatterns;
ExcludePatterns = new List<string>();
IncludeFiles = ExcludeFiles;
ExcludeFiles = new List<string>();
BuiltInsInclude = BuiltInsExclude;
BuiltInsExclude = new List<string>();
}
}
}

View file

@ -39,6 +39,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
CustomRemovePatterns = new List<string>(); CustomRemovePatterns = new List<string>();
SourceBasePath = sourceBasePath; SourceBasePath = sourceBasePath;
Option = option; Option = option;
RawObject = rawObject;
var token = rawObject.Value<JToken>(option); var token = rawObject.Value<JToken>(option);
if (token == null) if (token == null)
@ -117,20 +118,22 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files
public List<string> CustomRemovePatterns { get; } public List<string> CustomRemovePatterns { get; }
public List<string> IncludePatterns { get; } public List<string> IncludePatterns { get; protected set; }
public List<string> ExcludePatterns { get; } public List<string> ExcludePatterns { get; protected set; }
public List<string> IncludeFiles { get; } public List<string> IncludeFiles { get; protected set; }
public List<string> ExcludeFiles { get; } public List<string> ExcludeFiles { get; protected set; }
public List<string> BuiltInsInclude { get; } public List<string> BuiltInsInclude { get; protected set; }
public List<string> BuiltInsExclude { get; } public List<string> BuiltInsExclude { get; protected set; }
public IDictionary<string, IncludeContext> Mappings { get; } public IDictionary<string, IncludeContext> Mappings { get; }
public JObject RawObject { get; }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
var other = obj as IncludeContext; var other = obj as IncludeContext;

View file

@ -150,6 +150,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
new UpdateContextTransform("None", transformMappings: true) new UpdateContextTransform("None", transformMappings: true)
.WithMetadata("CopyToOutputDirectory", "PreserveNewest"); .WithMetadata("CopyToOutputDirectory", "PreserveNewest");
private IncludeContextTransform DoNotCopyToOutputFilesTransform =>
new UpdateContextTransform("None", transformMappings: true)
.WithMetadata("CopyToOutputDirectory", "Never");
private IncludeContextTransform CopyToOutputFilesTransformForWeb => private IncludeContextTransform CopyToOutputFilesTransformForWeb =>
new UpdateContextTransform( new UpdateContextTransform(
"None", "None",
@ -197,6 +201,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
return copyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory)); return copyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory));
}; };
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> DoNotCopyToOutputFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) =>
{
return DoNotCopyToOutputFilesTransform.Transform(GetDoNotCopyToOutputIncludeContext(compilerOptions, projectDirectory));
};
private readonly string[] DefaultEmptyExcludeOption = new string[0]; private readonly string[] DefaultEmptyExcludeOption = new string[0];
private readonly ProjectPropertyGroupElement _configurationPropertyGroup; private readonly ProjectPropertyGroupElement _configurationPropertyGroup;
@ -268,7 +278,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{ {
CompileFilesTransformExecute, CompileFilesTransformExecute,
EmbedFilesTransformExecute, EmbedFilesTransformExecute,
CopyToOutputFilesTransformExecute CopyToOutputFilesTransformExecute,
DoNotCopyToOutputFilesTransformExecute
}; };
} }
@ -531,6 +542,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
null); null);
} }
private IncludeContext GetDoNotCopyToOutputIncludeContext(CommonCompilerOptions compilerOptions, string projectDirectory)
{
// Defaults from src/Microsoft.DotNet.ProjectModel/ProjectReader.cs #608
var copyToOutputIncludeContext = compilerOptions.CopyToOutputInclude ??
new IncludeContext(
projectDirectory,
"copyToOutput",
new JObject(),
null,
null);
var doNotCopyToOutputIncludeContext =
new ExcludeContext(
copyToOutputIncludeContext.SourceBasePath,
copyToOutputIncludeContext.Option,
copyToOutputIncludeContext.RawObject,
copyToOutputIncludeContext.BuiltInsInclude?.ToArray(),
copyToOutputIncludeContext.BuiltInsExclude?.ToArray());
return doNotCopyToOutputIncludeContext;
}
private string FormatLanguageVersion(string langVersion) private string FormatLanguageVersion(string langVersion)
{ {
if (langVersion.StartsWith("csharp", StringComparison.OrdinalIgnoreCase)) if (langVersion.StartsWith("csharp", StringComparison.OrdinalIgnoreCase))

View file

@ -501,9 +501,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata), MigrationTrace.Instance); mergedItem.AddMetadata(MergeMetadata(existingItem.Metadata, item.Metadata), MigrationTrace.Instance);
Console.WriteLine($"BEFORE MERGED: {mergedItem.Update}, ITEM: {item.Update}, EXISTING: {existingItem.Update}");
item.RemoveUpdates(commonUpdates); item.RemoveUpdates(commonUpdates);
existingItem.RemoveUpdates(commonUpdates); existingItem.RemoveUpdates(commonUpdates);
Console.WriteLine($"MERGED: {mergedItem.Update}, ITEM: {item.Update}, EXISTING: {existingItem.Update}");
var mergeResult = new MergeResult var mergeResult = new MergeResult
{ {
InputItem = string.IsNullOrEmpty(item.Update) ? null : item, InputItem = string.IsNullOrEmpty(item.Update) ? null : item,
@ -518,7 +522,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
ICollection<ProjectMetadataElement> existingMetadataElements, ICollection<ProjectMetadataElement> existingMetadataElements,
ICollection<ProjectMetadataElement> newMetadataElements) ICollection<ProjectMetadataElement> newMetadataElements)
{ {
var mergedMetadata = new List<ProjectMetadataElement>(existingMetadataElements); var mergedMetadata = new List<ProjectMetadataElement>(existingMetadataElements.Select(m => (ProjectMetadataElement) m.Clone()));
foreach (var newMetadata in newMetadataElements) foreach (var newMetadata in newMetadataElements)
{ {
@ -526,11 +530,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
m.Name.Equals(newMetadata.Name, StringComparison.OrdinalIgnoreCase)); m.Name.Equals(newMetadata.Name, StringComparison.OrdinalIgnoreCase));
if (existingMetadata == null) if (existingMetadata == null)
{ {
mergedMetadata.Add(newMetadata); mergedMetadata.Add((ProjectMetadataElement) newMetadata.Clone());
} }
else else
{ {
MergeMetadata(existingMetadata, newMetadata); MergeMetadata(existingMetadata, (ProjectMetadataElement) newMetadata.Clone());
} }
} }
@ -541,7 +545,25 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{ {
if (existingMetadata.Value != newMetadata.Value) if (existingMetadata.Value != newMetadata.Value)
{ {
existingMetadata.Value = string.Join(";", new [] { existingMetadata.Value, newMetadata.Value }); if (existingMetadata.Name == "CopyToOutputDirectory" ||
existingMetadata.Name == "CopyToPublishDirectory")
{
existingMetadata.Value =
existingMetadata.Value == "Never" || newMetadata.Value == "Never" ?
"Never" :
"PreserveNewest";
}
else if (existingMetadata.Name == "Pack")
{
existingMetadata.Value =
existingMetadata.Value == "false" || newMetadata.Value == "false" ?
"false" :
"true";
}
else
{
existingMetadata.Value = string.Join(";", new [] { existingMetadata.Value, newMetadata.Value });
}
} }
} }

View file

@ -549,13 +549,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
} }
[Theory] [Fact]
[InlineData("copyToOutput", "None", 2, ";rootfile.cs")] public void MigratingCopyToOutputIncludeExcludePopulatesAppropriateProjectItemElement()
public void MigratingCopyToOutputIncludeExcludePopulatesAppropriateProjectItemElement(
string group,
string itemName,
int expectedNumberOfCompileItems,
string expectedRootFiles)
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
WriteExtraFiles(testDirectory); WriteExtraFiles(testDirectory);
@ -563,29 +558,38 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var pj = @" var pj = @"
{ {
""buildOptions"": { ""buildOptions"": {
""<group>"": { ""copyToOutput"": {
""include"": [""root"", ""src"", ""rootfile.cs""], ""include"": [""root"", ""src"", ""rootfile.cs""],
""exclude"": [""src"", ""rootfile.cs""], ""exclude"": [""anothersource"", ""rootfile1.cs""],
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""], ""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
""excludeFiles"": [""src/file2.cs""] ""excludeFiles"": [""src/file3.cs""]
} }
} }
}".Replace("<group>", group); }";
var mockProj = RunBuildOptionsRuleOnPj(pj, var mockProj = RunBuildOptionsRuleOnPj(pj,
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)) mockProj.Items.Count(i => i.ItemType.Equals("None", StringComparison.Ordinal))
.Should().Be(expectedNumberOfCompileItems); .Should().Be(4);
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals(itemName, StringComparison.Ordinal))) var copyItems = mockProj.Items.Where(i =>
i.ItemType.Equals("None", StringComparison.Ordinal) &&
i.Metadata.Any(m => m.Name == "CopyToOutputDirectory" && m.Value == "PreserveNewest"));
copyItems.Count().Should().Be(2);
var excludeItems = mockProj.Items.Where(i =>
i.ItemType.Equals("None", StringComparison.Ordinal) &&
i.Metadata.Any(m => m.Name == "CopyToOutputDirectory" && m.Value == "Never"));
excludeItems.Count().Should().Be(2);
foreach (var item in copyItems)
{ {
VerifyContentMetadata(item); VerifyContentMetadata(item);
if (string.IsNullOrEmpty(item.Update)) if (item.Update.Contains(@"src\file1.cs"))
{
}
else if (item.Update.Contains(@"src\file1.cs"))
{ {
item.Update.Should().Be(@"src\file1.cs;src\file2.cs"); item.Update.Should().Be(@"src\file1.cs;src\file2.cs");
} }
@ -594,6 +598,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs"); item.Update.Should().Be(@"root\**\*;src\**\*;rootfile.cs");
} }
} }
foreach (var item in excludeItems)
{
VerifyContentMetadata(item);
if (item.Update.Contains(@"src\file3.cs"))
{
item.Update.Should().Be(@"src\file3.cs");
}
else
{
item.Update.Should().Be(@"anothersource\**\*;rootfile1.cs");
}
}
} }
[Theory] [Theory]
@ -827,12 +845,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{ {
Directory.CreateDirectory(Path.Combine(directory, "root")); Directory.CreateDirectory(Path.Combine(directory, "root"));
Directory.CreateDirectory(Path.Combine(directory, "src")); Directory.CreateDirectory(Path.Combine(directory, "src"));
Directory.CreateDirectory(Path.Combine(directory, "anothersource"));
File.WriteAllText(Path.Combine(directory, "root", "file1.txt"), "content"); File.WriteAllText(Path.Combine(directory, "root", "file1.txt"), "content");
File.WriteAllText(Path.Combine(directory, "root", "file2.txt"), "content"); File.WriteAllText(Path.Combine(directory, "root", "file2.txt"), "content");
File.WriteAllText(Path.Combine(directory, "root", "file3.txt"), "content"); File.WriteAllText(Path.Combine(directory, "root", "file3.txt"), "content");
File.WriteAllText(Path.Combine(directory, "src", "file1.cs"), "content"); File.WriteAllText(Path.Combine(directory, "src", "file1.cs"), "content");
File.WriteAllText(Path.Combine(directory, "src", "file2.cs"), "content"); File.WriteAllText(Path.Combine(directory, "src", "file2.cs"), "content");
File.WriteAllText(Path.Combine(directory, "src", "file3.cs"), "content"); File.WriteAllText(Path.Combine(directory, "src", "file3.cs"), "content");
File.WriteAllText(Path.Combine(directory, "anothersource", "file4.cs"), "content");
File.WriteAllText(Path.Combine(directory, "rootfile.cs"), "content"); File.WriteAllText(Path.Combine(directory, "rootfile.cs"), "content");
} }

View file

@ -157,9 +157,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
""buildOptions"": { ""buildOptions"": {
""copyToOutput"": { ""copyToOutput"": {
""include"": [""src""], ""include"": [""src""],
""exclude"": [""src"", ""rootfile.cs""], ""exclude"": [""anothersource"", ""rootfile.cs""],
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""], ""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
""excludeFiles"": [""src/file2.cs""] ""excludeFiles"": [""anothersource/file2.cs""]
} }
}, },
""configurations"": { ""configurations"": {
@ -167,9 +167,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
""buildOptions"": { ""buildOptions"": {
""copyToOutput"": { ""copyToOutput"": {
""include"": [""root"", ""src"", ""rootfile.cs""], ""include"": [""root"", ""src"", ""rootfile.cs""],
""exclude"": [""src"", ""root/rootfile.cs""], ""exclude"": [""anothersource"", ""root/rootfile.cs""],
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""], ""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
""excludeFiles"": [""src/file2.cs""] ""excludeFiles"": [""src/file3.cs""]
} }
} }
} }
@ -178,23 +178,65 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(3); contentItems.Count().Should().Be(8);
// 2 for Base Build options contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(4);
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2);
// 2 for Configuration BuildOptions (1 Remove, 1 Update) contentItems.Where(i =>
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1); i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest")).Should().HaveCount(2);
var configIncludeContentItem = contentItems.First( contentItems.Where(i =>
item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Update)); i.ConditionChain().Count() == 0 &&
//var configRemoveContentItem = contentItems.First( i.Metadata.Any(m => m.Value == "Never")).Should().HaveCount(2);
// 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 contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(4);
//configRemoveContentItem.Remove.Should().Be(@"root;src;rootfile.cs"); contentItems.Where(i =>
configIncludeContentItem.Update.Should().Be(@"root;rootfile.cs"); i.ConditionChain().Count() == 1 &&
//configIncludeContentItem.Exclude.Should().Be(@"src;root\rootfile.cs;src\file2.cs"); i.Metadata.Any(m => m.Value == "PreserveNewest")).Should().HaveCount(1);
contentItems.Where(i =>
i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "Never")).Should().HaveCount(2);
contentItems.First(i =>
i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update)).Update.Should().Be(@"root;rootfile.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"src\file3.cs")).Update.Should().Be(@"src\file3.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"root\rootfile.cs")).Update.Should().Be(@"root\rootfile.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"src\file1.cs")).Update.Should().Be(@"src\file1.cs;src\file2.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src")).Update.Should().Be(@"src");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"anothersource\file2.cs")).Update.Should().Be(@"anothersource\file2.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"anothersource;rootfile.cs")).Update.Should().Be(@"anothersource;rootfile.cs");
} }
[Fact] [Fact]
@ -214,7 +256,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
""testconfig"": { ""testconfig"": {
""buildOptions"": { ""buildOptions"": {
""copyToOutput"": { ""copyToOutput"": {
""include"": [""root"", ""src"", ""rootfile.cs""], ""include"": [""root"", ""anothersource"", ""rootfile.cs""],
""exclude"": [""rootfile.cs"", ""someotherfile.cs""], ""exclude"": [""rootfile.cs"", ""someotherfile.cs""],
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""], ""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
""excludeFiles"": [""src/file2.cs""] ""excludeFiles"": [""src/file2.cs""]
@ -226,46 +268,71 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
foreach(var c in contentItems) contentItems.Count().Should().Be(9);
{ contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(4);
Console.WriteLine($"Include: {c.Include}, Update: {c.Update}, Remove: {c.Remove}, Condition: {c.ConditionChain().Count()}"); contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(5);
}
contentItems.Count().Should().Be(3); contentItems.Where(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest")).Should().HaveCount(2);
contentItems.Where(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never")).Should().HaveCount(2);
// 2 for Base Build options contentItems.Where(i =>
contentItems.Where(i => i.ConditionChain().Count() == 0).Should().HaveCount(2); i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "PreserveNewest")).Should().HaveCount(1);
contentItems.Where(i =>
i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "Never")).Should().HaveCount(3);
// 3 for Configuration BuildOptions (1 Remove, 2 Update) contentItems.First(i =>
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(1); i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"src\file1.cs")).Update.Should().Be(@"src\file1.cs;src\file2.cs");
var configIncludeContentItem = contentItems.First( contentItems.First(i =>
item => item.ConditionChain().Count() > 0 i.ConditionChain().Count() == 0 &&
&& item.Update.Contains("root")); i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src")).Update.Should().Be(@"src");
var configIncludeContentItem2 = contentItems.First( contentItems.First(i =>
item => item.ConditionChain().Count() == 0 i.ConditionChain().Count() == 0 &&
&& item.Update.Contains(@"src\file1.cs")); i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src\file3.cs")).Update.Should().Be(@"src\file3.cs");
var configIncludeContentItem3 = contentItems.First( contentItems.First(i =>
item => item.ConditionChain().Count() == 0 i.ConditionChain().Count() == 0 &&
&& item.Update.Equals(@"src")); i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"rootfile.cs")).Update.Should().Be(@"rootfile.cs");
//var configRemoveContentItem = contentItems.First( contentItems.First(i =>
// item => item.ConditionChain().Count() > 0 && !string.IsNullOrEmpty(item.Remove)); i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"root;anothersource")).Update.Should().Be(@"root;anothersource");
// Directories are not converted to globs in the result because we did not write the directory contentItems.First(i =>
//configRemoveContentItem.Removes() i.ConditionChain().Count() == 1 &&
// .Should().BeEquivalentTo("root", "src", "rootfile.cs", @"src\file1.cs", @"src\file2.cs"); i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"src\file2.cs")).Update.Should().Be(@"src\file2.cs");
configIncludeContentItem.Updates().Should().BeEquivalentTo("root", "rootfile.cs"); contentItems.First(i =>
//configIncludeContentItem.Excludes() i.ConditionChain().Count() == 1 &&
// .Should().BeEquivalentTo("rootfile.cs", "someotherfile.cs", @"src\file2.cs"); i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"rootfile.cs")).Update.Should().Be(@"rootfile.cs");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file1.cs", @"src\file2.cs"); contentItems.First(i =>
//configIncludeContentItem2.Excludes().Should().BeEquivalentTo(@"src\file2.cs"); i.ConditionChain().Count() == 1 &&
i.Metadata.Any(m => m.Value == "Never") &&
configIncludeContentItem3.Updates().Should().BeEquivalentTo(@"src"); !string.IsNullOrEmpty(i.Update) &&
i.Update.Contains(@"someotherfile.cs")).Update.Should().Be(@"someotherfile.cs");
} }
[Fact] [Fact]
@ -293,6 +360,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal)))
{
Console.WriteLine($"Update: {item.Update}, Include: {item.Include}, Remove: {item.Remove}");
foreach(var meta in item.Metadata)
{
Console.WriteLine($"\tMetadata: Name: {meta.Name}, Value: {meta.Value}");
}
foreach(var condition in item.ConditionChain())
{
Console.WriteLine($"\tCondition: {condition}");
}
}
contentItems.Count().Should().Be(2); contentItems.Count().Should().Be(2);
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(2); contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(2);
@ -423,16 +504,45 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(4); contentItems.Count().Should().Be(7);
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList(); var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
rootBuildOptionsContentItems.Count().Should().Be(2); rootBuildOptionsContentItems.Count().Should().Be(5);
foreach (var buildOptionContentItem in rootBuildOptionsContentItems) foreach (var buildOptionContentItem in rootBuildOptionsContentItems)
{ {
buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull(); buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull();
buildOptionContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
} }
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src\file1.cs")).Update.Should().Be(@"src\file1.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "PreserveNewest") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"root")).Update.Should().Be(@"root");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src\file2.cs")).Update.Should().Be(@"src\file2.cs");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"src")).Update.Should().Be(@"src");
contentItems.First(i =>
i.ConditionChain().Count() == 0 &&
i.Metadata.Any(m => m.Value == "Never") &&
!string.IsNullOrEmpty(i.Update) &&
i.Update.Equals(@"rootfile.cs")).Update.Should().Be(@"rootfile.cs");
var configItems = contentItems.Where(i => i.ConditionChain().Count() == 1); var configItems = contentItems.Where(i => i.ConditionChain().Count() == 1);
configItems.Should().HaveCount(2); configItems.Should().HaveCount(2);
@ -450,7 +560,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)"); configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configRemoveContentItem.Remove.Should().Be("src"); configRemoveContentItem.Remove.Should().Be("src");
} }
@ -490,15 +600,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var contentItems = mockProj.Items.Where(item => item.ItemType == "None"); var contentItems = mockProj.Items.Where(item => item.ItemType == "None");
contentItems.Count().Should().Be(5); contentItems.Count().Should().Be(8);
contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3); contentItems.Where(i => i.ConditionChain().Count() == 1).Should().HaveCount(3);
var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList(); var rootBuildOptionsContentItems = contentItems.Where(i => i.ConditionChain().Count() == 0).ToList();
rootBuildOptionsContentItems.Count().Should().Be(2); rootBuildOptionsContentItems.Count().Should().Be(5);
foreach (var buildOptionContentItem in rootBuildOptionsContentItems) foreach (var buildOptionContentItem in rootBuildOptionsContentItems)
{ {
buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull(); buildOptionContentItem.GetMetadataWithName("Link").Should().BeNull();
buildOptionContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");
} }
var configIncludeEncompassedItem = contentItems.FirstOrDefault( var configIncludeEncompassedItem = contentItems.FirstOrDefault(
@ -519,16 +628,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
&& !string.IsNullOrEmpty(item.Remove)); && !string.IsNullOrEmpty(item.Remove));
configIncludeContentItem.Update.Should().Be("src"); 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").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)"); configIncludeContentItem.GetMetadataWithName("Link").Value.Should().Be("/some/dir/%(FileName)%(Extension)");
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("Never");
configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file3.cs"); configIncludeContentItem2.Updates().Should().BeEquivalentTo(@"src\file3.cs");
//configIncludeContentItem2.Exclude.Should().Be(@"src\file2.cs");
configIncludeContentItem2.GetMetadataWithName("Link").Should().BeNull(); configIncludeContentItem2.GetMetadataWithName("Link").Should().BeNull();
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull(); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Should().NotBeNull();
configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest"); configIncludeContentItem2.GetMetadataWithName("CopyToOutputDirectory").Value.Should().Be("PreserveNewest");