2016-06-06 22:08:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.ProjectModel.Loader.Tests
|
|
|
|
|
{
|
|
|
|
|
public class ProjectLoadContextTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LoadContextCanLoadProjectOutput()
|
|
|
|
|
{
|
2016-06-11 00:28:23 +00:00
|
|
|
|
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithCultureSpecificResource")
|
2016-06-06 22:08:46 +00:00
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
|
|
|
|
|
2016-06-11 00:28:23 +00:00
|
|
|
|
var runtimeIdentifier = DependencyContext.Default.Target.Runtime;
|
2016-06-06 22:08:46 +00:00
|
|
|
|
|
2016-06-11 00:28:23 +00:00
|
|
|
|
var context = ProjectContext.Create(testInstance.TestRoot, NuGetFramework.Parse("netcoreapp1.0"), new[] { runtimeIdentifier });
|
|
|
|
|
var loadContext = context.CreateLoadContext(runtimeIdentifier, Constants.DefaultConfiguration);
|
2016-06-06 22:08:46 +00:00
|
|
|
|
|
|
|
|
|
// Load the project assembly
|
2016-06-11 00:28:23 +00:00
|
|
|
|
var assembly = loadContext.LoadFromAssemblyName(new AssemblyName("TestProjectWithCultureSpecificResource"));
|
2016-06-06 22:08:46 +00:00
|
|
|
|
|
|
|
|
|
// Call Program.GetMessage() and assert the output
|
2016-06-11 00:28:23 +00:00
|
|
|
|
var type = assembly.GetType("TestProjectWithCultureSpecificResource.Program");
|
|
|
|
|
var message = (string)type.GetRuntimeMethod("GetMessage", Type.EmptyTypes).Invoke(null, new object[0]);
|
2016-06-06 22:08:46 +00:00
|
|
|
|
Assert.Equal("Hello World!" + Environment.NewLine + "Bonjour!", message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|