Finish tests

This commit is contained in:
Justin Goshi 2017-01-26 11:00:50 -08:00
parent 61ae452fe2
commit 037da3fc01
5 changed files with 96 additions and 9 deletions

View file

@ -0,0 +1,19 @@
using System;
using System.Linq;
using System.Reflection;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var thisAssembly = typeof(Program).GetTypeInfo().Assembly;
var resources = from resourceName in thisAssembly.GetManifestResourceNames()
select resourceName;
var resourceNames = string.Join(",", resources);
Console.WriteLine($"{resources.Count()} Resources Found: {resourceNames}");
}
}
}

View file

@ -0,0 +1,20 @@
{
"version": "1.0.0-*",
"namedResource": [ "My.Alias", "Strings.resx" ],
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
}
}

View file

@ -825,7 +825,14 @@ namespace Microsoft.DotNet.Internal.ProjectModel
AddDeprecatedDiagnosticMessage(rawProject, project, "resourceExclude", resourceWarning);
AddDeprecatedDiagnosticMessage(rawProject, project, "resourceFiles", resourceWarning);
AddDeprecatedDiagnosticMessage(rawProject, project, "resourceBuiltIn", resourceWarning);
AddDeprecatedDiagnosticMessage(rawProject, project, "namedResource", resourceWarning);
// Issue: https://github.com/dotnet/cli/issues/5471
// This is why we mark it as an error which will fail migration.
AddDeprecatedDiagnosticMessage(
rawProject,
project,
"namedResource",
resourceWarning,
DiagnosticMessageSeverity.Error);
var contentWarning = "'publishOptions' to publish or 'copyToOutput' in 'buildOptions' to copy to build output";
AddDeprecatedDiagnosticMessage(rawProject, project, "content", contentWarning);
@ -842,7 +849,8 @@ namespace Microsoft.DotNet.Internal.ProjectModel
JObject rawProject,
Project project,
string option,
string message)
string message,
DiagnosticMessageSeverity severity = DiagnosticMessageSeverity.Warning)
{
var lineInfo = rawProject.Value<IJsonLineInfo>(option);
if (lineInfo == null)
@ -855,7 +863,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel
ErrorCodes.DOTNET1015,
$"The '{option}' option is deprecated. Use {message} instead.",
project.ProjectFilePath,
DiagnosticMessageSeverity.Warning,
severity,
lineInfo.LineNumber,
lineInfo.LinePosition));
}
@ -896,7 +904,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel
ConvertFromDeprecatedFormat(rawProject, jpath, "exclude", "exclude");
ConvertFromDeprecatedFormat(rawProject, jpath, "resourceExclude", "excludeFiles");
ConvertFromDeprecatedFormat(rawProject, jpath, "resourceFiles", "includeFiles");
ConvertFromDeprecatedFormat(rawProject, jpath, "namedResource", "mappings");
ConvertFromDeprecatedFormat(rawProject, $"{jpath}.builtIns", "resourceBuiltIn", "include");
}

View file

@ -252,11 +252,26 @@ namespace Microsoft.DotNet.ProjectJsonMigration
var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;
if (diagnostics.Any())
{
var deprecatedProjectJsonWarnings = string.Join(
Environment.NewLine,
diagnostics.Select(d => FormatDiagnosticMessage(d)));
var warnings = $"{projectDirectory}{Environment.NewLine}{deprecatedProjectJsonWarnings}";
Reporter.Output.WriteLine(warnings.Yellow());
var warnings = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Warning);
if (warnings.Any())
{
var deprecatedProjectJsonWarnings = string.Join(
Environment.NewLine,
diagnostics.Select(d => FormatDiagnosticMessage(d)));
var warningMessage = $"{projectDirectory}{Environment.NewLine}{deprecatedProjectJsonWarnings}";
Reporter.Output.WriteLine(warningMessage.Yellow());
}
var errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error);
if (errors.Any())
{
MigrationErrorCodes.MIGRATE1011(String.Format(
"{0}{1}{2}",
projectDirectory,
Environment.NewLine,
string.Join(Environment.NewLine, diagnostics.Select(d => FormatDiagnosticMessage(d)))))
.Throw();
}
}
var compilerName =

View file

@ -6,6 +6,7 @@ using FluentAssertions;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.Internal.ProjectModel;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Common;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
@ -38,6 +39,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
}
[Fact]
public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson()
{
var testProjectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedNamedResourceOption")
.CreateInstance()
.WithSourceFiles()
.Root
.FullName;
var mockProj = ProjectRootElement.Create();
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
testProjectDirectory,
testProjectDirectory,
mockProj);
var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
var report = projectMigrator.Migrate(testSettings);
var projectReport = report.ProjectMigrationReports.First();
var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();
errorMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
errorMessage.Should().Contain("The 'namedResource' option is deprecated. Use 'embed' in 'buildOptions' instead. (line: 3, file:");
}
[Fact]
public void ItHasErrorWhenMigratingANonCsharpApp()
{