2016-03-29 16:06: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.IO ;
using System.Linq ;
2016-04-28 16:30:32 -07:00
using FluentAssertions ;
using Microsoft.DotNet.InternalAbstractions ;
using Microsoft.DotNet.ProjectModel ;
2016-03-29 16:06:10 -07:00
using Microsoft.DotNet.TestFramework ;
2016-04-28 16:30:32 -07:00
using Microsoft.DotNet.Tools.Test.Utilities ;
2016-03-31 16:25:52 -07:00
using Newtonsoft.Json.Linq ;
2016-04-28 16:30:32 -07:00
using Xunit ;
2016-03-29 16:06:10 -07:00
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildStandAloneTests : TestBase
{
[Fact]
public void BuildingAStandAloneProjectProducesARuntimeConfigDevJsonFile ( )
{
var testInstance = TestAssetsManager . CreateTestInstance ( "PortableTests" )
. WithLockFiles ( ) ;
var netstandardappOutput = Build ( testInstance ) ;
netstandardappOutput . Should ( ) . Exist ( ) . And . HaveFile ( "StandaloneApp.runtimeconfig.dev.json" ) ;
}
2016-03-31 16:25:52 -07:00
[Fact]
public void BuildingAStandAloneProjectProducesARuntimeConfigJsonFile ( )
{
var testInstance = TestAssetsManager . CreateTestInstance ( "PortableTests" )
. WithLockFiles ( ) ;
var netstandardappOutput = Build ( testInstance ) ;
netstandardappOutput . Should ( ) . Exist ( ) . And . HaveFile ( "StandaloneApp.runtimeconfig.json" ) ;
}
[Fact]
2016-04-05 12:06:30 -07:00
public void RuntimeOptionsGetsCopiedToRuntimeConfigJsonForAStandaloneApp ( )
2016-03-31 16:25:52 -07:00
{
var testInstance = TestAssetsManager . CreateTestInstance ( "PortableTests" )
. WithLockFiles ( ) ;
var netstandardappOutput = Build ( testInstance ) ;
var runtimeConfigJsonPath = Path . Combine ( netstandardappOutput . FullName , "StandaloneApp.runtimeconfig.json" ) ;
using ( var stream = new FileStream ( runtimeConfigJsonPath , FileMode . Open , FileAccess . Read , FileShare . Read ) )
{
var reader = new StreamReader ( stream ) ;
var rawProject = JObject . Parse ( reader . ReadToEnd ( ) ) ;
var runtimeOptions = rawProject [ "runtimeOptions" ] ;
runtimeOptions [ "somethingString" ] . Value < string > ( ) . Should ( ) . Be ( "anything" ) ;
runtimeOptions [ "somethingBoolean" ] . Value < bool > ( ) . Should ( ) . BeTrue ( ) ;
runtimeOptions [ "someArray" ] . ToObject < string [ ] > ( ) . Should ( ) . Contain ( "one" , "two" ) ;
runtimeOptions [ "someObject" ] . Value < JObject > ( ) [ "someProperty" ] . Value < string > ( ) . Should ( ) . Be ( "someValue" ) ;
}
}
2016-03-29 16:06:10 -07:00
public DirectoryInfo Build ( TestInstance testInstance )
{
var projectPath = Path . Combine ( testInstance . TestRoot , "StandaloneApp" ) ;
var result = new BuildCommand (
projectPath : projectPath )
. ExecuteWithCapturedOutput ( ) ;
var contexts = ProjectContext . CreateContextForEachFramework (
projectPath ,
null ,
2016-04-28 16:30:32 -07:00
RuntimeEnvironmentRidExtensions . GetAllCandidateRuntimeIdentifiers ( ) ) ;
2016-03-29 16:06:10 -07:00
var runtime = contexts . FirstOrDefault ( c = > ! string . IsNullOrEmpty ( c . RuntimeIdentifier ) ) ? . RuntimeIdentifier ;
result . Should ( ) . Pass ( ) ;
var outputBase = new DirectoryInfo (
2016-04-12 17:29:07 -07:00
Path . Combine ( testInstance . TestRoot , "StandaloneApp" , "bin" , "Debug" , "netcoreapp1.0" ) ) ;
2016-03-29 16:06:10 -07:00
return outputBase . Sub ( runtime ) ;
}
}
}