Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test case #2

Merged
merged 1 commit into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
}