Skip to content

Commit

Permalink
Switch remaining tests using StandaloneApp project to use pre-built a…
Browse files Browse the repository at this point in the history
…sset (dotnet#93810)
  • Loading branch information
elinor-fung authored Oct 23, 2023
1 parent e8287ad commit d7c1f8b
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 197 deletions.
18 changes: 0 additions & 18 deletions src/installer/tests/Assets/TestProjects/StandaloneApp/Program.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public void OldHost_LatestRuntime_ForwardCompatible_60()

private void OldHost_LatestRuntime_ForwardCompatible(TestProjectFixture previousVersionFixture)
{
TestProjectFixture fixture = sharedTestState.FixtureLatest.Copy();
string appExe = fixture.TestProject.AppExe;
TestApp app = sharedTestState.AppLatest.Copy();
string appExe = app.AppExe;

Assert.NotEqual(fixture.Framework, previousVersionFixture.Framework);
Assert.NotEqual(fixture.RepoDirProvider.MicrosoftNETCoreAppVersion, previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion);
Assert.NotEqual(RepoDirectoriesProvider.Default.Tfm, previousVersionFixture.Framework);
Assert.NotEqual(RepoDirectoriesProvider.Default.MicrosoftNETCoreAppVersion, previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion);

// Use the older apphost
// This emulates the case when:
// 1) Newer runtime installed
// 2) App rolls forward to newer runtime
File.Copy(previousVersionFixture.TestProject.AppExe, fixture.TestProject.AppExe, true);
File.Copy(previousVersionFixture.TestProject.AppExe, appExe, true);
Command.Create(appExe)
.EnableTracingAndCaptureOutputs()
.Execute()
Expand All @@ -90,7 +90,7 @@ private void OldHost_LatestRuntime_ForwardCompatible(TestProjectFixture previous
// Note that we don't have multi-level on hostfxr so we will always find the older\one-off hostfxr
if (OperatingSystem.IsWindows())
{
File.Copy(previousVersionFixture.TestProject.HostFxrDll, fixture.TestProject.HostFxrDll, true);
File.Copy(previousVersionFixture.TestProject.HostFxrDll, app.HostFxrDll, true);
Command.Create(appExe)
.EnableTracingAndCaptureOutputs()
.Execute()
Expand All @@ -105,37 +105,35 @@ public class SharedTestState : IDisposable
private static RepoDirectoriesProvider RepoDirectories { get; set; }

public TestProjectFixture Fixture60 { get; }
public TestProjectFixture FixtureLatest { get; }
public TestApp AppLatest { get; }

private const string AppName = "HelloWorld";

public SharedTestState()
{
RepoDirectories = new RepoDirectoriesProvider();

Fixture60 = CreateTestFixture("StandaloneApp6x", "net6.0", "6.0");

var fixtureLatest = new TestProjectFixture("StandaloneApp", RepoDirectories);
fixtureLatest
.EnsureRestoredForRid(fixtureLatest.CurrentRid)
.PublishProject(runtime: fixtureLatest.CurrentRid, selfContained: true);

FixtureLatest = fixtureLatest;
AppLatest = TestApp.CreateFromBuiltAssets(AppName);
AppLatest.PopulateSelfContained(TestApp.MockedComponent.None);
}

public void Dispose()
{
Fixture60.Dispose();
FixtureLatest.Dispose();
AppLatest?.Dispose();
}

private static TestProjectFixture CreateTestFixture(string testName, string netCoreAppFramework, string mnaVersion)
{
var repoDirectories = new RepoDirectoriesProvider(microsoftNETCoreAppVersion: mnaVersion);

// Use standalone instead of framework-dependent for ease of deployment.
var publishFixture = new TestProjectFixture(testName, repoDirectories, framework: netCoreAppFramework, assemblyName: "StandaloneApp");
var publishFixture = new TestProjectFixture(testName, repoDirectories, framework: netCoreAppFramework, assemblyName: AppName);
publishFixture
.EnsureRestoredForRid(publishFixture.CurrentRid)
.PublishProject(runtime: publishFixture.CurrentRid, selfContained: true);
.PublishProject(runtime: publishFixture.CurrentRid, selfContained: true, extraArgs: $"/p:AssemblyName={AppName}");

return publishFixture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public void CallDelegateOnComponentContext(bool validPath, bool validType, bool
[InlineData(true, true, false)]
public void CallDelegateOnApplicationContext(bool validPath, bool validType, bool validMethod)
{
var appProject = sharedState.ApplicationFixture.TestProject;
var app = sharedState.FrameworkDependentApp;
var componentProject = sharedState.ComponentWithNoDependenciesFixture.TestProject;
string[] args =
{
AppLoadAssemblyAndGetFunctionPointerArg,
sharedState.HostFxrPath,
appProject.AppDll,
app.AppDll,
validPath ? componentProject.AppDll : "BadPath...",
validType ? sharedState.ComponentTypeName : $"Component.BadType, {componentProject.AssemblyName}",
validMethod ? sharedState.ComponentEntryPoint1 : "BadMethod",
Expand All @@ -80,7 +80,7 @@ public void CallDelegateOnApplicationContext(bool validPath, bool validType, boo
.Execute();

result.Should()
.InitializeContextForApp(appProject.AppDll);
.InitializeContextForApp(app.AppDll);

if (validPath && validType && validMethod)
{
Expand All @@ -97,13 +97,13 @@ public void CallDelegateOnApplicationContext(bool validPath, bool validType, boo
[Fact]
public void CallDelegateOnSelfContainedApplicationContext()
{
var appProject = sharedState.SelfContainedApplicationFixture.TestProject;
var app = sharedState.SelfContainedApp;
var componentProject = sharedState.ComponentWithNoDependenciesFixture.TestProject;
string[] args =
{
AppLoadAssemblyAndGetFunctionPointerArg,
appProject.HostFxrDll,
appProject.AppDll,
app.HostFxrDll,
app.AppDll,
componentProject.AppDll,
sharedState.ComponentTypeName,
sharedState.ComponentEntryPoint1,
Expand All @@ -112,7 +112,7 @@ public void CallDelegateOnSelfContainedApplicationContext()
.Execute();

result.Should()
.InitializeContextForApp(appProject.AppDll)
.InitializeContextForApp(app.AppDll)
.And.Pass()
.And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1)
.And.ExecuteInIsolatedContext(componentProject.AssemblyName);
Expand Down Expand Up @@ -239,9 +239,10 @@ public class SharedTestState : SharedTestStateBase
public string HostFxrPath { get; }
public string DotNetRoot { get; }

public TestProjectFixture ApplicationFixture { get; }
public TestProjectFixture ComponentWithNoDependenciesFixture { get; }
public TestProjectFixture SelfContainedApplicationFixture { get; }
public TestApp FrameworkDependentApp { get; }
public TestApp SelfContainedApp { get; }

public string ComponentTypeName { get; }
public string ComponentEntryPoint1 => "ComponentEntryPoint1";
public string ComponentEntryPoint2 => "ComponentEntryPoint2";
Expand All @@ -253,26 +254,25 @@ public SharedTestState()
DotNetRoot = dotNet.BinPath;
HostFxrPath = dotNet.GreatestVersionHostFxrFilePath;

ApplicationFixture = new TestProjectFixture("PortableApp", RepoDirectories)
.EnsureRestored()
.PublishProject();
ComponentWithNoDependenciesFixture = new TestProjectFixture("ComponentWithNoDependencies", RepoDirectories)
.EnsureRestored()
.PublishProject();
SelfContainedApplicationFixture = new TestProjectFixture("StandaloneApp", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: true);

FrameworkDependentApp = TestApp.CreateFromBuiltAssets("HelloWorld");

SelfContainedApp = TestApp.CreateFromBuiltAssets("HelloWorld");
SelfContainedApp.PopulateSelfContained(TestApp.MockedComponent.None);

ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}";
}

protected override void Dispose(bool disposing)
{
if (ApplicationFixture != null)
ApplicationFixture.Dispose();
if (ComponentWithNoDependenciesFixture != null)
ComponentWithNoDependenciesFixture.Dispose();
if (SelfContainedApplicationFixture != null)
SelfContainedApplicationFixture.Dispose();

FrameworkDependentApp?.Dispose();
SelfContainedApp?.Dispose();

base.Dispose(disposing);
}
Expand Down
Loading

0 comments on commit d7c1f8b

Please sign in to comment.