d6cab4af58
* Move dotnet-new templates to Sdk attribute * Update to MSBuild 15.1.0-preview-000454-01 To pick up a fix for Microsoft/msbuild#1431. * Fix template newlines * Fix casing on Microsoft.Net.Sdk * Move migration test csproj's to Sdk attribute * Disable parallel sdk restore Each SDK restore operation will try to manipulate the same assets.json file since the dependency name&version are injected into a common csproj file. This can cause runtime failures when two NuGets try to restore the project at once. * Make casing of SDK 'NET' and not 'Net' * Remove redundatn imports * Fix test string * Additional race * Replacing the SDK with the Web.Sdk when it is a Web project. * Fixing the test by writting the csproj before running the migration rule.
66 lines
2.9 KiB
C#
66 lines
2.9 KiB
C#
// 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.Linq;
|
|
using FluentAssertions;
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
using Xunit;
|
|
using Microsoft.DotNet.ProjectJsonMigration;
|
|
using System;
|
|
using System.IO;
|
|
using Microsoft.Build.Construction;
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
|
using NuGet.Frameworks;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Collections.Generic;
|
|
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
|
|
|
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|
{
|
|
public class GivenThatIWantToMigrateRuntimeOptions : TestBase
|
|
{
|
|
private static readonly string s_runtimeConfigFileName = "runtimeconfig.template.json";
|
|
|
|
[Fact]
|
|
public void RuntimeOptions_are_copied_from_projectJson_to_runtimeconfig_template_json_file()
|
|
{
|
|
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions");
|
|
var projectDir = testInstance.Path;
|
|
var projectPath = Path.Combine(testInstance.Path, "project.json");
|
|
|
|
var project = JObject.Parse(File.ReadAllText(projectPath));
|
|
var rawRuntimeOptions = (JObject)project.GetValue("runtimeOptions");
|
|
|
|
var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);
|
|
|
|
var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement));
|
|
var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null);
|
|
new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);
|
|
|
|
var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);
|
|
|
|
File.Exists(migratedRuntimeOptionsPath).Should().BeTrue();
|
|
|
|
var migratedRuntimeOptionsContent = JObject.Parse(File.ReadAllText(migratedRuntimeOptionsPath));
|
|
JToken.DeepEquals(rawRuntimeOptions, migratedRuntimeOptionsContent).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Migrating_ProjectJson_with_no_RuntimeOptions_produces_no_runtimeconfig_template_json_file()
|
|
{
|
|
var testInstance = TestAssetsManager.CreateTestInstance("PJTestAppSimple");
|
|
var projectDir = testInstance.Path;
|
|
|
|
var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);
|
|
|
|
var testSettings = new MigrationSettings(projectDir, projectDir, default(ProjectRootElement));
|
|
var testInputs = new MigrationRuleInputs(new[] { projectContext }, null, null, null);
|
|
new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);
|
|
|
|
var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);
|
|
|
|
File.Exists(migratedRuntimeOptionsPath).Should().BeFalse();
|
|
}
|
|
}
|
|
}
|