PR Feedback

This commit is contained in:
Bryan Thornbury 2016-08-23 13:50:05 -07:00
parent 903764aa7d
commit b0554d3ff3
72 changed files with 769 additions and 680 deletions

View file

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Common;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenAProjectMigrator : TestBase
{
[Fact]
public void It_copies_ProjectDirectory_contents_to_OutputDirectory_when_the_directories_are_different()
{
var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppSimple", callingMethod: "z")
.WithLockFiles().Path;
var outputDirectory = Temp.CreateDirectory().Path;
var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory);
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, outputDirectory, "1.0.0", mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
projectMigrator.Migrate(testSettings);
foreach (var projectDirectoryRelativeFilePath in projectDirectoryRelativeFilePaths)
{
File.Exists(Path.Combine(outputDirectory, projectDirectoryRelativeFilePath)).Should().BeTrue();
}
}
[Fact]
public void It_throws_when_migrating_a_deprecated_projectJson()
{
var testProjectDirectory =
TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
.WithLockFiles().Path;
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
Action migrateAction = () => projectMigrator.Migrate(testSettings);
migrateAction.ShouldThrow<Exception>().Where(
e => e.Message.Contains("MIGRATE1011::Deprecated Project:")
&& e.Message.Contains("The 'packInclude' option is deprecated. Use 'files' in 'packOptions' instead.")
&& e.Message.Contains("The 'compilationOptions' option is deprecated. Use 'buildOptions' instead."));
}
[Fact]
public void It_throws_when_migrating_a_non_csharp_app()
{
var testProjectDirectory =
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
.WithLockFiles().Path;
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testProjectDirectory, testProjectDirectory, "1.0.0", mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
Action migrateAction = () => projectMigrator.Migrate(testSettings);
migrateAction.ShouldThrow<Exception>().Where(
e => e.Message.Contains("MIGRATE20013::Non-Csharp App: Cannot migrate project"));
}
private IEnumerable<string> EnumerateFilesWithRelativePath(string testProjectDirectory)
{
return
Directory.EnumerateFiles(testProjectDirectory, "*", SearchOption.AllDirectories)
.Select(file => PathUtility.GetRelativePath(testProjectDirectory, file));
}
private class FakeEmptyMigrationRule : IMigrationRule
{
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
{
return;
}
}
}
}

View file

@ -15,6 +15,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.Include = "include1;include2;aaa";
var includes = item.Includes().ToArray();
includes.Should().HaveCount(3);
includes[0].Should().Be("include1");
includes[1].Should().Be("include2");
includes[2].Should().Be("aaa");
@ -28,6 +30,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item.Exclude = "include1;include2;aaa";
var excludes = item.Excludes().ToArray();
excludes.Should().HaveCount(3);
excludes[0].Should().Be("include1");
excludes[1].Should().Be("include2");
excludes[2].Should().Be("aaa");
@ -74,7 +78,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var project = ProjectRootElement.Create();
var item1 = project.AddItem("test", "include1;include2");
item1.AddIncludes(new string[] {"include2", "include3"});
item1.UnionIncludes(new string[] {"include2", "include3"});
item1.Include.Should().Be("include1;include2;include3");
}
@ -85,7 +89,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var project = ProjectRootElement.Create();
var item1 = project.AddItem("test", "include1");
item1.Exclude = "exclude1;exclude2";
item1.AddExcludes(new string[] {"exclude2", "exclude3"});
item1.UnionExcludes(new string[] {"exclude2", "exclude3"});
item1.Exclude.Should().Be("exclude1;exclude2;exclude3");
}
@ -98,7 +102,24 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
item1.AddMetadata("name", "value");
item1.HasMetadata.Should().BeTrue();
var item2 = project.AddItem("test1", "hey");
var item2 = project.AddItem("test1", "include1");
item2.AddMetadata(item1.Metadata);
item2.HasMetadata.Should().BeTrue();
item2.Metadata.First().Name.Should().Be("name");
item2.Metadata.First().Value.Should().Be("value");
}
[Fact]
public void AddMetadata_adds_metadata_from_an_item_generated_from_another_project()
{
var project = ProjectRootElement.Create();
var item1 = project.AddItem("test", "include1");
item1.AddMetadata("name", "value");
item1.HasMetadata.Should().BeTrue();
var project2 = ProjectRootElement.Create();
var item2 = project2.AddItem("test1", "include1");
item2.AddMetadata(item1.Metadata);
item2.HasMetadata.Should().BeTrue();

View file

@ -0,0 +1 @@
https://github.com/Microsoft/msbuild/issues/927

View file

@ -1 +1 @@
hey
https://github.com/Microsoft/msbuild/issues/927

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25123" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25123</VisualStudioVersion>
@ -8,8 +8,8 @@
<PropertyGroup Label="Globals">
<ProjectGuid>1F2EF070-AC5F-4078-AFB0-65745AC691B9</ProjectGuid>
<RootNamespace>Microsoft.DotNet.ProjectJsonMigration.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' “>..\artifact\obj\$(RootNamespace)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' “>..\artifacts\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>

View file

@ -13,9 +13,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
/// </summary>
public class ProjectJsonBuilder
{
private static readonly string s_defaultProjectJsonTestAsset = "TestAppWithRuntimeOptions";
private TestAssetsManager _testAssetsManager;
private readonly TestAssetsManager _testAssetsManager;
private JObject _projectJson;
private bool _baseDefined = false;
@ -41,11 +39,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
return _projectJson;
}
public ProjectJsonBuilder FromDefaultBase()
{
return FromTestAssetBase(s_defaultProjectJsonTestAsset);
}
public ProjectJsonBuilder FromTestAssetBase(string testAssetName)
{
var testProjectDirectory = _testAssetsManager.CreateTestInstance(testAssetName).Path;

View file

@ -8,6 +8,7 @@ using System.IO;
using System.Linq;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.ProjectModel.Files;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
@ -68,7 +69,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
[Fact]
public void Migrating_EmitEntryPoint_true_populates_OutputType_and_TargetExt_fields()
public void Migrating_EmitEntryPoint_true_populates_OutputType_field()
{
var mockProj = RunBuildOptionsRuleOnPj(@"
{
@ -78,10 +79,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}");
mockProj.Properties.Count(p => p.Name == "OutputType").Should().Be(1);
mockProj.Properties.Count(p => p.Name == "TargetExt").Should().Be(1);
mockProj.Properties.First(p => p.Name == "OutputType").Value.Should().Be("Exe");
mockProj.Properties.First(p => p.Name == "TargetExt").Value.Should().Be(".dll");
}
[Fact]
@ -362,7 +360,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[InlineData("compile", "Compile")]
[InlineData("embed", "EmbeddedResource")]
[InlineData("copyToOutput", "Content")]
private void Migrating_compile_include_exclude_Populates_compile_item(
private void Migrating_group_include_exclude_Populates_appropriate_ProjectItemElement(
string group,
string itemName)
{
@ -404,6 +402,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)))
{
if (item.ItemType == "Content")
{
item.Metadata.Count(m => m.Name == "CopyToOutputDirectory").Should().Be(1);
}
if (item.Include.Contains(@"src\file1.cs"))
{
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");

View file

@ -10,6 +10,7 @@ using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.ProjectJsonMigration.Tests;
namespace Microsoft.DotNet.ProjectJsonMigrationMigration.Tests
@ -32,7 +33,7 @@ namespace Microsoft.DotNet.ProjectJsonMigrationMigration.Tests
}");
mockProj.Properties.Count(
prop => prop.Name == "OutputType" || prop.Name == "TargetExt" || prop.Name == "DebugType").Should().Be(3);
prop => prop.Name == "OutputType" || prop.Name == "DebugType").Should().Be(2);
mockProj.Properties.First(p => p.Name == "OutputType")
.Parent.Condition.Should()
@ -59,11 +60,11 @@ namespace Microsoft.DotNet.ProjectJsonMigrationMigration.Tests
}");
mockProj.Properties.Count(property =>
property.Name == "OutputType" || property.Name == "TargetExt" || property.Name == "DebugType")
.Should().Be(3);
property.Name == "OutputType" || property.Name == "DebugType")
.Should().Be(2);
foreach (var property in mockProj.Properties.Where(property =>
property.Name == "OutputType" || property.Name == "TargetExt" || property.Name == "DebugType"))
property.Name == "OutputType" || property.Name == "DebugType"))
{
property.Parent.Condition.Should().Be(string.Empty);
}
@ -141,7 +142,7 @@ namespace Microsoft.DotNet.ProjectJsonMigrationMigration.Tests
action.ShouldThrow<Exception>()
.WithMessage(
"Unable to migrate projects with excluded files in configurations.");
"MIGRATE20012::Configuration Exclude: Unable to migrate projects with excluded files in configurations.");
}
private ProjectRootElement RunConfigurationsRuleOnPj(string s, string testDirectory = null)
{

View file

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
namespace Microsoft.DotNet.Migration.Tests
{
@ -60,7 +61,7 @@ namespace Microsoft.DotNet.Migration.Tests
var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));
projectReferences.Count().Should().Be(1);
projectReferences.First().Include.Should().Be("../TestLibrary/TestLibrary.csproj");
projectReferences.First().Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
}
[Fact]
@ -79,7 +80,7 @@ namespace Microsoft.DotNet.Migration.Tests
Action action = () => new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
action.ShouldThrow<Exception>()
.WithMessage("Cannot migrate unresolved project dependency, please ensure restore has been run.");
.Where(e => e.Message.Contains("MIGRATE1014::Unresolved Dependency: Unresolved project dependency (TestLibrary)"));
}
}
}

View file

@ -10,6 +10,7 @@ using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
@ -34,12 +35,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(2);
// From ProjectReader #L725 (Both are empty)
var defaultIncludePatterns = Enumerable.Empty<string>();
var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns;
foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal)))
{
item.Metadata.Count(m => m.Name == "CopyToPublishDirectory").Should().Be(1);
if (item.Include.Contains(@"src\file1.cs"))
{
item.Include.Should().Be(@"src\file1.cs;src\file2.cs");

View file

@ -14,6 +14,7 @@ using NuGet.Frameworks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{

View file

@ -9,23 +9,25 @@ using Microsoft.DotNet.ProjectJsonMigration;
using System;
using System.IO;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenThatIWantToMigrateScripts : TestBase
{
[Theory]
[InlineData("compile:FullTargetFramework", "$(TargetFrameworkIdentifier)=$(TargetFrameworkVersion)")]
[InlineData("compile:FullTargetFramework", "$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)")]
[InlineData("compile:Configuration", "$(Configuration)")]
[InlineData("compile:OutputFile", "$(TargetPath)")]
[InlineData("compile:OutputDir", "$(TargetDir)")]
[InlineData("publish:ProjectPath", "$(MSBuildThisFileDirectory)")]
[InlineData("publish:Configuration", "$(Configuration)")]
[InlineData("publish:OutputPath", "$(TargetDir)")]
[InlineData("publish:FullTargetFramework", "$(TargetFrameworkIdentifier)=$(TargetFrameworkVersion)")]
[InlineData("publish:FullTargetFramework", "$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)")]
[InlineData("project:Version", "$(Version)")]
[InlineData("project:Name", "$(MSBuildThisFileName)")]
[InlineData("project:Name", "$(AssemblyName)")]
[InlineData("project:Directory", "$(MSBuildProjectDirectory)")]
[InlineData("publish:Runtime", "$(RuntimeIdentifier)")]
public void Formatting_script_commands_replaces_variables_with_the_right_msbuild_properties(
string variable,
string msbuildReplacement)
@ -41,7 +43,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[InlineData("compile:RuntimeOutputDir")]
[InlineData("compile:RuntimeIdentifier")]
[InlineData("publish:TargetFramework")]
[InlineData("publish:Runtime")]
public void Formatting_script_commands_throws_when_variable_is_unsupported(string unsupportedVariable)
{
var scriptMigrationRule = new MigrateScriptsRule();
@ -158,7 +159,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
count += 1;
var scriptExtensionProperties =
propertyGroup.Properties.Where(p => p.Name.Contains($"MigratedScriptExtension_{count}")).ToArray();
propertyGroup.Properties.Where(p => p.Name.Contains($"MigratedScriptExtension_{scriptName}_{count}")).ToArray();
scriptExtensionProperties.All(p => p.Value == ".sh" || p.Value == ".cmd").Should().BeTrue();
scriptExtensionProperties.Count().Should().Be(2);

View file

@ -9,6 +9,7 @@ using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
@ -19,7 +20,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager)
.FromDefaultBase()
.FromTestAssetBase("TestAppWithRuntimeOptions")
.WithCustomProperty("buildOptions", new Dictionary<string, string>
{
{ "emitEntryPoint", "false" }

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.ProjectModel;
using NuGet.Frameworks;

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{

View file

@ -4,6 +4,8 @@ using Xunit;
using Xunit.Runner.DotNet;
using FluentAssertions;
using System.Linq;
using Microsoft.DotNet.ProjectJsonMigration.Models;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.ProjectJsonMigration.Tests.Transforms
{
@ -23,15 +25,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests.Transforms
var transform1 = new AddItemTransform<string>("item",
fullItemTransformSetIncludeValue,
"exclude1",
t => true,
mergeExisting: true)
t => true)
.WithMetadata(metadata[0]);
var transform2 = new AddItemTransform<string>("item",
fullItemTransformSetIncludeValue,
"exclude2",
t => true,
mergeExisting: true)
t => true)
.WithMetadata(metadata[1]);
var mockProj = ProjectRootElement.Create();
@ -64,26 +64,5 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests.Transforms
foundMetadata.All(kv => kv.Value).Should().BeTrue();
}
// [Fact]
// public void It_adds_duplicate_properties_to_the_project_with_specified_value_when_the_property_exists()
// {
// var mockProj = ProjectRootElement.Create();
// var propertyGroup = mockProj.AddPropertyGroup();
// var propertyName = "Property1";
// var propertyValue = "Value1";
//
// var propertyTransform = new AddPropertyTransform<string>(propertyName, propertyValue, t => true);
// propertyTransform.Transform("_");
// propertyTransform.Transform("_", mockProj, propertyGroup);
//
// propertyGroup.Properties.Count.Should().Be(2);
//
// foreach (var property in propertyGroup.Properties)
// {
// property.Name.Should().Be(propertyName);
// property.Value.Should().Be(propertyValue);
// }
// }
}
}

View file

@ -1,39 +0,0 @@
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
namespace Microsoft.DotNet.Migration.Tests
{
public class GivenAnAddBoolPropertyTransform
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_returns_a_property_to_the_project_with_boolean_value(bool propertyValue)
{
var propertyName = "Property1";
var propertyTransform = new AddBoolPropertyTransform(propertyName, t => true);
var property = propertyTransform.Transform(propertyValue);
property.Name.Should().Be(propertyName);
property.Value.Should().Be(propertyValue.ToString());
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void It_returns_null_when_condition_is_false(bool propertyValue)
{
var propertyName = "Property1";
var propertyTransform = new AddBoolPropertyTransform(propertyName, t => false);
propertyTransform.Transform(propertyValue).Should().BeNull();
}
}
}

View file

@ -6,6 +6,8 @@ using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Models;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.Migration.Tests
{

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.Migration.Tests
{

View file

@ -1,57 +0,0 @@
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
namespace Microsoft.DotNet.Migration.Tests
{
public class GivenAnAddStringPropertyTransform
{
[Fact]
public void It_adds_a_property_to_the_project_with_string_value()
{
var propertyName = "Property1";
var propertyValue = "TestValue1";
var propertyTransform = new AddStringPropertyTransform(propertyName, t => true);
var property = propertyTransform.Transform(propertyValue);
property.Name.Should().Be(propertyName);
property.Value.Should().Be(propertyValue);
}
[Fact]
public void It_returns_null_when_propertyValue_is_null_and_condition_is_passed()
{
var propertyName = "Property1";
string propertyValue = null;
var propertyTransform = new AddStringPropertyTransform(propertyName, t => true);
propertyTransform.Transform(propertyValue).Should().BeNull();
}
[Fact]
public void It_returns_null_when_propertyValue_is_null_and_condition_is_not_passed()
{
var mockProj = ProjectRootElement.Create();
var propertyName = "Property1";
string propertyValue = null;
var propertyTransform = new AddStringPropertyTransform(propertyName);
propertyTransform.Transform(propertyValue).Should().BeNull();
}
[Fact]
public void It_returns_null_when_condition_is_false()
{
var propertyName = "Property1";
var propertyValue = "TestValue1";
var propertyTransform = new AddStringPropertyTransform(propertyName, t => false);
propertyTransform.Transform(propertyValue).Should().BeNull();
}
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
namespace Microsoft.DotNet.Migration.Tests
{

View file

@ -18,5 +18,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
args = $"new {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"new {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}

View file

@ -10,61 +10,65 @@ using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Tools.Common;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Migrate;
using Build3Command = Microsoft.DotNet.Tools.Test.Utilities.Build3Command;
using TemporaryDotnetNewTemplateProject = Microsoft.DotNet.Cli.TemporaryDotnetNewTemplateProject;
namespace Microsoft.DotNet.Migration.Tests
{
public class GivenThatIWantToMigrateTestApps : TestBase
{
private class Failure
{
public string Phase {get; set;}
public string Message {get; set;}
public string ProjectJson {get; set;}
}
[Theory]
// TODO: Standalone apps [InlineData("TestAppSimple", false)]
// https://github.com/dotnet/sdk/issues/73 [InlineData("TestAppWithLibrary/TestApp", false)]
[InlineData("TestAppWithRuntimeOptions", false)]
public void It_migrates_a_project(string projectName, bool isLibrary)
[InlineData("TestAppWithRuntimeOptions")]
public void It_migrates_apps(string projectName)
{
var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, callingMethod: "i").WithLockFiles().Path;
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
CleanBinObj(projectDirectory);
MigrateProject(projectDirectory);
Restore(projectDirectory);
BuildMSBuild(projectDirectory);
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
var outputsIdentical = projectJsonBuildOutputs.SetEquals(msbuildBuildOutputs);
// diagnostics
var outputsIdentical =
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
if (!outputsIdentical)
{
Console.WriteLine("Project.json Outputs:");
Console.WriteLine(string.Join("\n", projectJsonBuildOutputs));
Console.WriteLine("");
Console.WriteLine("MSBuild Outputs:");
Console.WriteLine(string.Join("\n", msbuildBuildOutputs));
OutputDiagnostics(outputComparisonData);
}
outputsIdentical.Should().BeTrue();
VerifyAllMSBuildOutputsRunnable(projectDirectory);
}
if (!isLibrary)
[Fact]
public void It_migrates_dotnet_new_console_with_identical_outputs()
{
var projectDirectory = Temp.CreateDirectory().Path;
var outputComparisonData = GetDotnetNewComparisonData(projectDirectory, "console");
var outputsIdentical =
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
if (!outputsIdentical)
{
VerifyMSBuildOutputRunnable(projectDirectory);
OutputDiagnostics(outputComparisonData);
}
outputsIdentical.Should().BeTrue();
VerifyAllMSBuildOutputsRunnable(projectDirectory);
}
[Fact]
// Outputs Not Identical: https://github.com/dotnet/sdk/issues/97
public void It_migrates_dotnet_new_web_with_outputs_containing_project_json_outputs()
{
var projectDirectory = Temp.CreateDirectory().Path;
var outputComparisonData = GetDotnetNewComparisonData(projectDirectory, "web");
var projectJsonOutputIsSubsetOfMSBuildOutput =
outputComparisonData.ProjectJsonBuildOutputs.IsProperSubsetOf(outputComparisonData.MSBuildBuildOutputs);
if (!projectJsonOutputIsSubsetOfMSBuildOutput)
{
OutputDiagnostics(outputComparisonData);
}
projectJsonOutputIsSubsetOfMSBuildOutput.Should().BeTrue();
}
[Theory]
@ -75,29 +79,14 @@ namespace Microsoft.DotNet.Migration.Tests
{
var projectDirectory =
TestAssetsManager.CreateTestInstance(projectName, callingMethod: "i").WithLockFiles().Path;
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
CleanBinObj(projectDirectory);
var msBuildHasAdditionalOutputsButIncludesProjectJsonOutputs =
outputComparisonData.ProjectJsonBuildOutputs.IsProperSubsetOf(outputComparisonData.MSBuildBuildOutputs);
MigrateProject(projectDirectory);
Restore(projectDirectory);
BuildMSBuild(projectDirectory);
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
var msBuildHasAdditionalOutputsButIncludesProjectJsonOutputs = projectJsonBuildOutputs.IsProperSubsetOf(msbuildBuildOutputs);
// diagnostics
if (!msBuildHasAdditionalOutputsButIncludesProjectJsonOutputs)
{
Console.WriteLine("Project.json Outputs:");
Console.WriteLine(string.Join("\n", projectJsonBuildOutputs));
Console.WriteLine("");
Console.WriteLine("MSBuild Outputs:");
Console.WriteLine(string.Join("\n", msbuildBuildOutputs));
OutputDiagnostics(outputComparisonData);
}
msBuildHasAdditionalOutputsButIncludesProjectJsonOutputs.Should().BeTrue();
@ -107,7 +96,7 @@ namespace Microsoft.DotNet.Migration.Tests
public void It_migrates_an_app_with_scripts_and_the_scripts_run()
{
var projectDirectory =
TestAssetsManager.CreateTestInstance("TestAppWithMigrateAbleScripts", callingMethod: "i").WithLockFiles().Path;
TestAssetsManager.CreateTestInstance("TestAppWithMigrateableScripts", callingMethod: "i").WithLockFiles().Path;
BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
@ -121,26 +110,25 @@ namespace Microsoft.DotNet.Migration.Tests
var outputsIdentical = projectJsonBuildOutputs.SetEquals(msbuildBuildOutputs);
outputsIdentical.Should().BeTrue();
VerifyMSBuildOutputRunnable(projectDirectory);
VerifyAllMSBuildOutputsRunnable(projectDirectory);
var outputDir =
PathUtility.EnsureTrailingSlash(Path.Combine(projectDirectory, "bin", "Debug", "netcoreapp1.0"));
msBuildStdOut.Should().Contain($"precompile_output ?Debug? ?{outputDir}? ?.NETCoreApp=v1.0?");
msBuildStdOut.Should().Contain($"postcompile_output ?Debug? ?{outputDir}? ?.NETCoreApp=v1.0?");
msBuildStdOut.Should().Contain($"precompile_output ?Debug? ?{outputDir}? ?.NETCoreApp,Version=v1.0?");
msBuildStdOut.Should().Contain($"postcompile_output ?Debug? ?{outputDir}? ?.NETCoreApp,Version=v1.0?");
}
private string RunNetcoreappMSBuildOutput(string projectDirectory)
private MigratedBuildComparisonData GetDotnetNewComparisonData(string projectDirectory, string dotnetNewType)
{
var dllFileName = Path.GetFileName(projectDirectory) + ".dll";
DotnetNew(projectDirectory, dotnetNewType);
Restore(projectDirectory);
var runnableDll = Path.Combine(projectDirectory, "bin","Debug", "netcoreapp1.0", dllFileName);
var result = new TestCommand("dotnet").ExecuteWithCapturedOutput(runnableDll);
result.Should().Pass();
return result.StdOut;
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
return outputComparisonData;
}
private void VerifyMSBuildOutputRunnable(string projectDirectory)
private void VerifyAllMSBuildOutputsRunnable(string projectDirectory)
{
var dllFileName = Path.GetFileName(projectDirectory) + ".dll";
@ -153,6 +141,21 @@ namespace Microsoft.DotNet.Migration.Tests
}
}
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory)
{
BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
CleanBinObj(projectDirectory);
MigrateProject(projectDirectory);
Restore(projectDirectory);
BuildMSBuild(projectDirectory);
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
return new MigratedBuildComparisonData(projectJsonBuildOutputs, msbuildBuildOutputs);
}
private IEnumerable<string> CollectBuildOutputs(string projectDirectory)
{
var fullBinPath = Path.GetFullPath(Path.Combine(projectDirectory, "bin"));
@ -182,10 +185,18 @@ namespace Microsoft.DotNet.Migration.Tests
private void MigrateProject(string projectDirectory)
{
var dotnetNew = new TemporaryDotnetNewTemplateProject();
var sdkVersion = new ProjectJsonParser(dotnetNew.ProjectJson).SdkPackageVersion;
var migrationSettings = new MigrationSettings(projectDirectory, projectDirectory, sdkVersion, dotnetNew.MSBuildProject);
new ProjectMigrator().Migrate(migrationSettings);
var result =
MigrateCommand.Run(new [] { "-p", projectDirectory });
result.Should().Be(0);
}
private void DotnetNew(string projectDirectory, string dotnetNewType)
{
new NewCommand().WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput($"-t {dotnetNewType}")
.Should()
.Pass();
}
private void Restore(string projectDirectory)
@ -197,16 +208,46 @@ namespace Microsoft.DotNet.Migration.Tests
.Pass();
}
private string BuildMSBuild(string projectDirectory)
private string BuildMSBuild(string projectDirectory, string configuration="Debug")
{
var result = new Build3Command()
.WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput();
.ExecuteWithCapturedOutput($"/p:Configuration={configuration}");
result
.Should()
.Pass();
return result.StdOut;
}
private void OutputDiagnostics(MigratedBuildComparisonData comparisonData)
{
OutputDiagnostics(comparisonData.MSBuildBuildOutputs, comparisonData.ProjectJsonBuildOutputs);
}
private void OutputDiagnostics(HashSet<string> msbuildBuildOutputs, HashSet<string> projectJsonBuildOutputs)
{
Console.WriteLine("Project.json Outputs:");
Console.WriteLine(string.Join("\n", projectJsonBuildOutputs));
Console.WriteLine("");
Console.WriteLine("MSBuild Outputs:");
Console.WriteLine(string.Join("\n", msbuildBuildOutputs));
}
private class MigratedBuildComparisonData
{
public HashSet<string> ProjectJsonBuildOutputs { get; }
public HashSet<string> MSBuildBuildOutputs { get; }
public MigratedBuildComparisonData(HashSet<string> projectJsonBuildOutputs,
HashSet<string> msBuildBuildOutputs)
{
ProjectJsonBuildOutputs = projectJsonBuildOutputs;
MSBuildBuildOutputs = msBuildBuildOutputs;
}
}
}
}

View file

@ -0,0 +1 @@
https://github.com/Microsoft/msbuild/issues/927

View file

@ -0,0 +1 @@
https://github.com/Microsoft/msbuild/issues/927

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25123" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25123</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>1F2EF070-AC5F-4078-AFB0-65745AC691B9</ProjectGuid>
<RootNamespace>Microsoft.DotNet.ProjectJsonMigration.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,39 @@
{
"version": "1.0.0-*",
"buildOptions": {
"copyToOutput": ["MSBuild.exe", "MSBuild.exe.config"]
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.DotNet.ProjectJsonMigration": {
"target": "project"
},
"xunit": "2.2.0-beta3-build3330",
"dotnet-test-xunit": "1.0.0-rc2-318883-21",
"FluentAssertions": "4.0.0",
"moq.netcore": "4.4.0-beta8",
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"Microsoft.DotNet.Cli.Utils": {
"target": "project"
},
"dotnet": {
"target":"project"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"netstandardapp1.5",
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}