forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swaroop-sridhar/staticHostTest
Add a test case
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/installer/test/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/StaticHost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BundleTests.Helpers; | ||
using Microsoft.DotNet.Cli.Build.Framework; | ||
using Microsoft.DotNet.CoreSetup.Test; | ||
using Microsoft.NET.HostModel.AppHost; | ||
using Microsoft.NET.HostModel.Bundle; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using Xunit; | ||
|
||
namespace AppHost.Bundle.Tests | ||
{ | ||
public class StaticHost : IClassFixture<StaticHost.SharedTestState> | ||
{ | ||
private SharedTestState sharedTestState; | ||
|
||
public StaticHost(SharedTestState fixture) | ||
{ | ||
sharedTestState = fixture; | ||
} | ||
|
||
// This helper is used in lieu of SDK support for publishing apps using the static_apphost. | ||
// It replaces the apphost with static_apphost, and along with appropeiate app.dll updates in the host. | ||
// For now, we heave behind the hostpolicy and hostfxr DLLs in the publish directory, because | ||
// removing them requires deps.json update. | ||
void ReplaceApphostWithStaticHost(TestProjectFixture fixture) | ||
{ | ||
var staticHost = Path.Combine(fixture.RepoDirProvider.HostArtifacts, | ||
RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("static_apphost")); | ||
HostWriter.CreateAppHost(staticHost, | ||
BundleHelper.GetHostPath(fixture), | ||
BundleHelper.GetAppPath(fixture)); | ||
|
||
} | ||
|
||
[Fact] | ||
private void Can_Run_App_With_StatiHost() | ||
{ | ||
var fixture = sharedTestState.TestFixture.Copy(); | ||
var appExe = BundleHelper.GetHostPath(fixture); | ||
|
||
ReplaceApphostWithStaticHost(fixture); | ||
|
||
Command.Create(appExe) | ||
.CaptureStdErr() | ||
.CaptureStdOut() | ||
.Execute() | ||
.Should() | ||
.Pass() | ||
.And | ||
.HaveStdOutContaining("Hello World"); | ||
} | ||
|
||
[Fact] | ||
private void Can_Run_SingleFile_App_With_StatiHost() | ||
{ | ||
var fixture = sharedTestState.TestFixture.Copy(); | ||
|
||
ReplaceApphostWithStaticHost(fixture); | ||
|
||
string singleFile = BundleHelper.BundleApp(fixture); | ||
|
||
Command.Create(singleFile) | ||
.CaptureStdErr() | ||
.CaptureStdOut() | ||
.Execute() | ||
.Should() | ||
.Pass() | ||
.And | ||
.HaveStdOutContaining("Hello World"); | ||
} | ||
|
||
public class SharedTestState : IDisposable | ||
{ | ||
public TestProjectFixture TestFixture { get; set; } | ||
public RepoDirectoriesProvider RepoDirectories { get; set; } | ||
|
||
public SharedTestState() | ||
{ | ||
RepoDirectories = new RepoDirectoriesProvider(); | ||
TestFixture = new TestProjectFixture("StandaloneApp", RepoDirectories); | ||
TestFixture | ||
.EnsureRestoredForRid(TestFixture.CurrentRid, RepoDirectories.CorehostPackages) | ||
.PublishProject(runtime: TestFixture.CurrentRid, | ||
outputDirectory: BundleHelper.GetPublishPath(TestFixture)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
TestFixture.Dispose(); | ||
} | ||
} | ||
} | ||
} |