Fixing a failing test and adding a few more E2E tests around binplace content for migrated projects.
This commit is contained in:
parent
733ee18c5a
commit
8e35beccb8
11 changed files with 172 additions and 24 deletions
|
@ -2,8 +2,8 @@
|
|||
"version": "1.0.0-*",
|
||||
"content": "*.txt",
|
||||
"contentExclude": "ExcludeThis1.txt",
|
||||
"contentFiles": [ "../ContentFile1.txt", "../ContentFile2.txt" ],
|
||||
"contentBuiltIn": [ "../ContentFileBuiltIn1.txt", "../ContentFileBuiltIn2.txt" ],
|
||||
"contentFiles": [ "ContentFile1.txt1", "ContentFile2.txt1" ],
|
||||
"contentBuiltIn": [ "ContentFileBuiltIn1.txt1", "ContentFileBuiltIn2.txt1" ],
|
||||
"publishExclude": "ExcludeThis2.txt",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
|
|
|
@ -97,7 +97,8 @@
|
|||
"wwwroot",
|
||||
"**/*.cshtml",
|
||||
"appsettings.json",
|
||||
"web.config"
|
||||
"web.config",
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
|
||||
|
|
|
@ -62,7 +62,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
.WithMappingsToTransform(_mappingsToTransfrom);
|
||||
|
||||
private IncludeContextTransform DoNotPackFilesTransform =>
|
||||
new UpdateContextTransform("None", transformMappings: true)
|
||||
new UpdateContextTransform(
|
||||
"None",
|
||||
transformMappings: true,
|
||||
excludePatternsRule: pattern => ProjectFilesCollection.DefaultBuiltInExcludePatterns.Contains(pattern))
|
||||
.WithMetadata("Pack", "false");
|
||||
|
||||
private Func<AddItemTransform<IncludeContext>, string, AddItemTransform<IncludeContext>> _mappingsToTransfrom =>
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
projectContext.ProjectFile.PublishOptions,
|
||||
migrationRuleInputs);
|
||||
|
||||
if (projectContext.ProjectFile.PublishOptions != null)
|
||||
{
|
||||
ExecuteTransformation(
|
||||
DoNotCopyToPublishDirectoryTransform,
|
||||
new ExcludeContext(
|
||||
|
@ -46,6 +48,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
projectContext.ProjectFile.PublishOptions.BuiltInsExclude?.ToArray()),
|
||||
migrationRuleInputs);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteTransformation(
|
||||
IncludeContextTransform transform,
|
||||
|
|
|
@ -220,6 +220,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
}
|
||||
}");
|
||||
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
var contentItemsToInclude = mockProj.Items
|
||||
.Where(item => item.ItemType.Equals("None", StringComparison.Ordinal))
|
||||
.Where(item => item.GetMetadataWithName("Pack").Value == "true");
|
||||
|
@ -231,8 +245,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
.Where(item => item.ItemType.Equals("None", StringComparison.Ordinal))
|
||||
.Where(item => item.GetMetadataWithName("Pack").Value == "false");
|
||||
|
||||
contentItemsToInclude.Count().Should().Be(1);
|
||||
contentItemsToInclude.First().Update.Should().Be(@"path\to\file\to\exclude.cs");
|
||||
contentItemsToExclude.Count().Should().Be(1);
|
||||
contentItemsToExclude.First().Update.Should().Be(@"path\to\file\to\exclude.cs");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
// 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 Microsoft.Build.Construction;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.Tools.Migrate;
|
||||
using BuildCommand = Microsoft.DotNet.Tools.Test.Utilities.BuildCommand;
|
||||
using System.Runtime.Loader;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using MigrateCommand = Microsoft.DotNet.Tools.Migrate.MigrateCommand;
|
||||
|
||||
namespace Microsoft.DotNet.Migration.Tests
|
||||
{
|
||||
public class GivenThatIWantMigratedAppsToBinplaceContent : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void ItBinplacesContentOnBuildForConsoleApps()
|
||||
{
|
||||
var projectDirectory = TestAssets
|
||||
.GetProjectJson("TestAppWithContents")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.WithRestoreFiles()
|
||||
.WithEmptyGlobalJson()
|
||||
.Root;
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.WithForwardingToConsole()
|
||||
.Execute($"migrate {projectDirectory.FullName}")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var command = new RestoreCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var result = new BuildCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var outputDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0");
|
||||
outputDir.Should().Exist().And.HaveFile("testcontentfile.txt");
|
||||
outputDir.GetDirectory("dir").Should().Exist().And.HaveFile("mappingfile.txt");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItBinplacesContentOnPublishForConsoleApps()
|
||||
{
|
||||
var projectDirectory = TestAssets
|
||||
.GetProjectJson("TestAppWithContents")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.WithRestoreFiles()
|
||||
.WithEmptyGlobalJson()
|
||||
.Root;
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.WithForwardingToConsole()
|
||||
.Execute($"migrate {projectDirectory.FullName}")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var command = new RestoreCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var result = new PublishCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var publishDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0", "publish");
|
||||
publishDir.Should().Exist().And.HaveFile("testcontentfile.txt");
|
||||
publishDir.GetDirectory("dir").Should().Exist().And.HaveFile("mappingfile.txt");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItBinplacesContentOnPublishForWebApps()
|
||||
{
|
||||
var projectDirectory = TestAssets
|
||||
.GetProjectJson("ProjectJsonWebTemplate")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.WithRestoreFiles()
|
||||
.WithEmptyGlobalJson()
|
||||
.Root;
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.WithForwardingToConsole()
|
||||
.Execute($"migrate {projectDirectory.FullName}")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var command = new RestoreCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var result = new PublishCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
var publishDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0", "publish");
|
||||
publishDir.Should().Exist().And.HaveFile("README.md");
|
||||
publishDir.GetDirectory("wwwroot").Should().Exist();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -224,10 +224,10 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
outputDir.Should().Exist()
|
||||
.And.HaveFiles(new[]
|
||||
{
|
||||
"ContentFile1.txt",
|
||||
"ContentFile2.txt",
|
||||
"ContentFileBuiltIn1.txt",
|
||||
"ContentFileBuiltIn2.txt",
|
||||
"ContentFile1.txt1",
|
||||
"ContentFile2.txt1",
|
||||
"ContentFileBuiltIn1.txt1",
|
||||
"ContentFileBuiltIn2.txt1",
|
||||
"IncludeThis.txt",
|
||||
});
|
||||
Directory.Exists(Path.Combine(outputDir.FullName, "ExcludeThis1.txt")).Should().BeFalse();
|
||||
|
@ -237,10 +237,10 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
publishDir.Should().Exist()
|
||||
.And.HaveFiles(new[]
|
||||
{
|
||||
"ContentFile1.txt",
|
||||
"ContentFile2.txt",
|
||||
"ContentFileBuiltIn1.txt",
|
||||
"ContentFileBuiltIn2.txt",
|
||||
"ContentFile1.txt1",
|
||||
"ContentFile2.txt1",
|
||||
"ContentFileBuiltIn1.txt1",
|
||||
"ContentFileBuiltIn2.txt1",
|
||||
"IncludeThis.txt",
|
||||
});
|
||||
Directory.Exists(Path.Combine(publishDir.FullName, "ExcludeThis1.txt")).Should().BeFalse();
|
||||
|
|
Loading…
Add table
Reference in a new issue