2016-08-22 12:24:10 -07:00
// 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 ;
2016-10-27 18:46:43 -07:00
using Microsoft.DotNet.Internal.ProjectModel ;
2016-08-22 12:24:10 -07:00
using NuGet.Frameworks ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using System.Collections.Generic ;
2016-08-23 13:50:05 -07:00
using Microsoft.DotNet.ProjectJsonMigration.Rules ;
2016-08-22 12:24:10 -07:00
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 ( )
{
2016-09-21 21:23:50 -07:00
var testInstance = TestAssetsManager . CreateTestInstance ( "TestAppWithRuntimeOptions" ) ;
2016-08-22 12:24:10 -07:00
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 ) ;
2016-12-07 11:49:15 -10:00
var testSettings = MigrationSettings . CreateMigrationSettingsTestHook ( projectDir , projectDir , default ( ProjectRootElement ) ) ;
2016-08-22 12:24:10 -07:00
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 ( )
{
2016-10-27 18:46:43 -07:00
var testInstance = TestAssetsManager . CreateTestInstance ( "PJTestAppSimple" ) ;
2016-08-22 12:24:10 -07:00
var projectDir = testInstance . Path ;
var projectContext = ProjectContext . Create ( projectDir , FrameworkConstants . CommonFrameworks . NetCoreApp10 ) ;
2016-12-07 11:49:15 -10:00
var testSettings = MigrationSettings . CreateMigrationSettingsTestHook ( projectDir , projectDir , default ( ProjectRootElement ) ) ;
2016-08-22 12:24:10 -07:00
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 ( ) ;
}
}
}