namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ArgValidation
{
- public class GivenThatICareAboutDotnetArgValidationScenarios
+ public class GivenThatICareAboutDotnetArgValidationScenarios : IClassFixture<GivenThatICareAboutDotnetArgValidationScenarios.SharedTestState>
{
- private RepoDirectoriesProvider RepoDirectories { get; set; }
- private TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
+ private SharedTestState sharedTestState;
- public GivenThatICareAboutDotnetArgValidationScenarios()
+ public GivenThatICareAboutDotnetArgValidationScenarios(GivenThatICareAboutDotnetArgValidationScenarios.SharedTestState fixture)
{
- RepoDirectories = new RepoDirectoriesProvider();
-
- PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
+ sharedTestState = fixture;
}
[Fact]
public void Muxer_Exec_With_Missing_App_Assembly_Fails()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_Exec_With_Missing_App_Assembly_And_Bad_Extension_Fails()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_Exec_With_Bad_Extension_Fails()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Detect_Missing_Argument_Value()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
// Return a non-exisitent path that contains a mix of / and \
private string GetNonexistentAndUnnormalizedPath()
{
- return Path.Combine(PreviouslyBuiltAndRestoredPortableTestProjectFixture.SdkDotnet.BinPath, @"x\y/");
+ return Path.Combine(sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture.SdkDotnet.BinPath, @"x\y/");
+ }
+
+ public class SharedTestState : IDisposable
+ {
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+ public TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+ }
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture.Dispose();
+ }
}
}
}
[Fact]
public void Muxer_activation_of_dotnet_test_XUnit_on_Portable_Test_App_Succeeds()
{
- var portableTestAppFixture = new TestProjectFixture("PortableTestApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
+ using (var portableTestAppFixture = new TestProjectFixture("PortableTestApp", RepoDirectories))
+ {
+ portableTestAppFixture
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
- ActivateDotnetTestXunitOnTestProject(RepoDirectories, portableTestAppFixture);
+ ActivateDotnetTestXunitOnTestProject(RepoDirectories, portableTestAppFixture);
+ }
}
[Fact]
public void Muxer_activation_of_dotnet_test_XUnit_on_Standalone_Test_App_Succeeds()
{
- var standaloneTestAppFixture = new TestProjectFixture("StandaloneTestApp", RepoDirectories);
- standaloneTestAppFixture
- .EnsureRestoredForRid(standaloneTestAppFixture.CurrentRid, RepoDirectories.CorehostPackages)
- .BuildProject(runtime: standaloneTestAppFixture.CurrentRid);
+ using (var standaloneTestAppFixture = new TestProjectFixture("StandaloneTestApp", RepoDirectories))
+ {
+ standaloneTestAppFixture
+ .EnsureRestoredForRid(standaloneTestAppFixture.CurrentRid, RepoDirectories.CorehostPackages)
+ .BuildProject(runtime: standaloneTestAppFixture.CurrentRid);
- ActivateDotnetTestXunitOnTestProject(RepoDirectories, standaloneTestAppFixture);
+ ActivateDotnetTestXunitOnTestProject(RepoDirectories, standaloneTestAppFixture);
+ }
}
public void ActivateDotnetTestXunitOnTestProject(
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
{
- public class GivenThatICareAboutHostVersionCompatibility
+ public class GivenThatICareAboutHostVersionCompatibility : IClassFixture<GivenThatICareAboutHostVersionCompatibility.SharedTestState>
{
- private static TestProjectFixture Fixture20 { get; set; }
- private static TestProjectFixture Fixture21 { get; set; }
- private static TestProjectFixture FixtureLatest { get; set; }
+ private SharedTestState sharedTestState;
- static GivenThatICareAboutHostVersionCompatibility()
+ public GivenThatICareAboutHostVersionCompatibility(SharedTestState fixture)
{
- // If these versions are changed, also change the corresponding .csproj
- Fixture20 = CreateTestFixture("StandaloneApp20", "netcoreapp2.0", "2.0.7");
- Fixture21 = CreateTestFixture("StandaloneApp21", "netcoreapp2.1", "2.1.0");
- FixtureLatest = GivenThatICareAboutStandaloneAppActivation.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture;
+ sharedTestState = fixture;
}
- public static IEnumerable<object[]> PreviousVersions
+ [Fact]
+ public void Latest_Host_Is_Backwards_Compatible_With_Older_Runtime_20()
{
- get
- {
- yield return new object[] { Fixture20 };
- yield return new object[] { Fixture21 };
- }
+ Latest_Host_Is_Backwards_Compatible_With_Older_Runtime(sharedTestState.Fixture20);
+ }
+
+ [Fact]
+ public void Latest_Host_Is_Backwards_Compatible_With_Older_Runtime_21()
+ {
+ Latest_Host_Is_Backwards_Compatible_With_Older_Runtime(sharedTestState.Fixture21);
}
- [Theory]
- [MemberData(nameof(PreviousVersions))]
- public void Latest_Host_Is_Backwards_Compatible_With_Older_Runtime(TestProjectFixture previousVersionFixture)
+ private void Latest_Host_Is_Backwards_Compatible_With_Older_Runtime(TestProjectFixture previousVersionFixture)
{
if (!IsRidSupported())
{
TestProjectFixture fixture = previousVersionFixture.Copy();
string appExe = fixture.TestProject.AppExe;
- Assert.NotEqual(fixture.Framework, FixtureLatest.Framework);
- Assert.NotEqual(fixture.RepoDirProvider.MicrosoftNETCoreAppVersion, FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion);
+ Assert.NotEqual(fixture.Framework, sharedTestState.FixtureLatest.Framework);
+ Assert.NotEqual(fixture.RepoDirProvider.MicrosoftNETCoreAppVersion, sharedTestState.FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion);
// Baseline (no changes)
Command.Create(appExe)
// This emulates the case when:
// 1) Newer runtime installed
// 2) Newer runtime uninstalled (installer preserves newer apphost)
- File.Copy(FixtureLatest.TestProject.AppExe, fixture.TestProject.AppExe, true);
+ File.Copy(sharedTestState.FixtureLatest.TestProject.AppExe, fixture.TestProject.AppExe, true);
Command.Create(appExe)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.And
.HaveStdOutContaining("Hello World")
.And
- .HaveStdErrContaining($"--- Invoked apphost [version: {FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion}");
+ .HaveStdErrContaining($"--- Invoked apphost [version: {sharedTestState.FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion}");
// Use the newer apphost and hostFxr
// This emulates the case when:
// 1) Newer runtime installed
// 2) A roll-forward to the newer runtime did not occur
- File.Copy(FixtureLatest.TestProject.HostFxrDll, fixture.TestProject.HostFxrDll, true);
+ File.Copy(sharedTestState.FixtureLatest.TestProject.HostFxrDll, fixture.TestProject.HostFxrDll, true);
Command.Create(appExe)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.And
.HaveStdOutContaining("Hello World")
.And
- .HaveStdErrContaining($"--- Invoked apphost [version: {FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion}");
+ .HaveStdErrContaining($"--- Invoked apphost [version: {sharedTestState.FixtureLatest.RepoDirProvider.MicrosoftNETCoreAppVersion}");
}
- [Theory]
- [MemberData(nameof(PreviousVersions))]
- public void Old_Host_Is_Forward_Compatible_With_Latest_Runtime(TestProjectFixture previousVersionFixture)
+ [Fact]
+ public void Old_Host_Is_Forward_Compatible_With_Latest_Runtime_20()
+ {
+ Old_Host_Is_Forward_Compatible_With_Latest_Runtime(sharedTestState.Fixture20);
+ }
+
+ [Fact]
+ public void Old_Host_Is_Forward_Compatible_With_Latest_Runtime_21()
+ {
+ Old_Host_Is_Forward_Compatible_With_Latest_Runtime(sharedTestState.Fixture21);
+ }
+
+ private void Old_Host_Is_Forward_Compatible_With_Latest_Runtime(TestProjectFixture previousVersionFixture)
{
if (!IsRidSupported())
{
return;
}
- TestProjectFixture fixture = FixtureLatest.Copy();
+ TestProjectFixture fixture = sharedTestState.FixtureLatest.Copy();
string appExe = fixture.TestProject.AppExe;
Assert.NotEqual(fixture.Framework, previousVersionFixture.Framework);
.HaveStdErrContaining($"--- Invoked apphost [version: {previousVersionFixture.RepoDirProvider.MicrosoftNETCoreAppVersion}");
}
- 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");
-
- if (IsRidSupported())
- {
- publishFixture
- .EnsureRestoredForRid(publishFixture.CurrentRid, repoDirectories.CorehostPackages)
- .PublishProject(runtime: publishFixture.CurrentRid);
- }
-
- return publishFixture;
- }
-
private static bool IsRidSupported()
{
Platform platform = RuntimeEnvironment.OperatingSystemPlatform;
(platform == Platform.Linux && RuntimeEnvironment.GetRuntimeIdentifier() == "ubuntu.16.04-x64")
);
}
+
+ public class SharedTestState : IDisposable
+ {
+ private static RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public TestProjectFixture Fixture20 { get; set; }
+ public TestProjectFixture Fixture21 { get; set; }
+ public TestProjectFixture FixtureLatest { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ // If these versions are changed, also change the corresponding .csproj
+ Fixture20 = CreateTestFixture("StandaloneApp20", "netcoreapp2.0", "2.0.7");
+ Fixture21 = CreateTestFixture("StandaloneApp21", "netcoreapp2.1", "2.1.0");
+
+ var fixtureLatest = new TestProjectFixture("StandaloneApp", RepoDirectories);
+ fixtureLatest
+ .EnsureRestoredForRid(fixtureLatest.CurrentRid, RepoDirectories.CorehostPackages)
+ .PublishProject(runtime: fixtureLatest.CurrentRid);
+
+ FixtureLatest = fixtureLatest;
+ }
+
+ public void Dispose()
+ {
+ Fixture20.Dispose();
+ Fixture21.Dispose();
+ FixtureLatest.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");
+
+ if (IsRidSupported())
+ {
+ publishFixture
+ .EnsureRestoredForRid(publishFixture.CurrentRid, repoDirectories.CorehostPackages)
+ .PublishProject(runtime: publishFixture.CurrentRid);
+ }
+
+ return publishFixture;
+ }
+ }
}
}
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
{
- public class GivenThatICareAboutLightupAppActivation
+ public class GivenThatICareAboutLightupAppActivation : IClassFixture<GivenThatICareAboutLightupAppActivation.SharedTestState>, IDisposable
{
+ private SharedTestState sharedTestState;
+
private const string SystemCollectionsImmutableFileVersion = "1.2.3.4";
private const string SystemCollectionsImmutableAssemblyVersion = "1.0.1.2";
- private static TestProjectFixture PreviouslyBuiltAndRestoredLightupLibTestProjectFixture { get; set; }
- private static TestProjectFixture PreviouslyPublishedAndRestoredLightupLibTestProjectFixture { get; set; }
-
- private static TestProjectFixture PreviouslyBuiltAndRestoredLightupAppTestProjectFixture { get; set; }
- private static TestProjectFixture PreviouslyPublishedAndRestoredLightupAppTestProjectFixture { get; set; }
-
- private static TestProjectFixture PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture { get; set; }
-
-
- private static RepoDirectoriesProvider RepoDirectories { get; set; }
-
private string _currentWorkingDir;
private string _builtDotnet;
private string _builtSharedFxDir;
private string _fxBaseDir;
private string _uberFxBaseDir;
- static GivenThatICareAboutLightupAppActivation()
- {
- RepoDirectories = new RepoDirectoriesProvider();
-
- PreviouslyBuiltAndRestoredLightupLibTestProjectFixture = new TestProjectFixture("LightupLib", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
+ private TestProjectFixture PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture { get; set; }
- PreviouslyPublishedAndRestoredLightupLibTestProjectFixture = new TestProjectFixture("LightupLib", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .PublishProject();
-
- PreviouslyBuiltAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
-
- PreviouslyPublishedAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .PublishProject();
- }
-
- public GivenThatICareAboutLightupAppActivation()
+ public GivenThatICareAboutLightupAppActivation(GivenThatICareAboutLightupAppActivation.SharedTestState fixture)
{
+ sharedTestState = fixture;
+
// From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
// to locate it because we'll copy its contents into other folders
string artifactsDir = Environment.GetEnvironmentVariable("TEST_ARTIFACTS");
var repoDirectories = new RepoDirectoriesProvider(builtDotnet: _currentWorkingDir);
PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", repoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
+ .EnsureRestored(sharedTestState.RepoDirectories.CorehostPackages)
.BuildProject();
- string greatestVersionSharedFxPath = PreviouslyBuiltAndRestoredLightupLibTestProjectFixture.BuiltDotnet.GreatestVersionSharedFxPath;
+ string greatestVersionSharedFxPath = sharedTestState.PreviouslyBuiltAndRestoredLightupLibTestProjectFixture.BuiltDotnet.GreatestVersionSharedFxPath;
string sharedFxVersion = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;
_builtSharedFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.NETCore.App", sharedFxVersion);
_builtSharedUberFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.UberFramework", sharedFxVersion);
SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);
}
+ public void Dispose()
+ {
+ PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture.Dispose();
+
+ if (!TestProject.PreserveTestRuns())
+ {
+ Directory.Delete(_currentWorkingDir, true);
+ }
+ }
+
// Attempt to run the app with lightup deps.json specified but lightup library missing in the expected
// probe locations.
[Fact]
public void Muxer_activation_of_LightupApp_NoLightupLib_Fails()
{
- var fixtureLib = PreviouslyBuiltAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyBuiltAndRestoredLightupLibTestProjectFixture
.Copy();
- var fixtureApp = PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
+ var fixtureApp = sharedTestState.PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
var dotnet = fixtureApp.BuiltDotnet;
[Fact]
public void Muxer_activation_of_LightupApp_WithLightupLib_Succeeds()
{
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
- var fixtureApp = PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
+ var fixtureApp = sharedTestState.PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
var dotnet = fixtureApp.BuiltDotnet;
[Fact]
public void Muxer_activation_of_LightupApp_WithLightupLib_and_Roll_Backwards_From_Release_To_Release_Succeeds()
{
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
var fixtureApp = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.HaveStdOutContaining("Hello LightupClient")
.And
.HaveStdErrContaining($"Using specified additional deps.json: '{selectedLightupPath}");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "8888.0.5");
}
[Fact]
public void Muxer_activation_of_LightupApp_WithLightupLib_and_Roll_Backwards_From_Prerelease_To_Release_Succeeds()
{
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
var fixtureApp = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.HaveStdOutContaining("Hello LightupClient")
.And
.HaveStdErrContaining($"Using specified additional deps.json: '{selectedLightupPath}");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "8888.0.5-preview2");
}
[Fact]
public void Muxer_activation_of_LightupApp_WithLightupLib_and_Roll_Backwards_Fails()
{
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
var fixtureApp = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.Fail()
.And
.HaveStdErrContaining($"No additional deps directory less than or equal to [8888.0.1] found with same major and minor version.");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "8888.0.1");
}
// Attempt to run the app without lightup deps.json specified but lightup library present in the expected
[Fact]
public void Muxer_activation_of_LightupApp_WithLightupLib_NoLightupDepsJson_Fails()
{
- var fixtureLib = PreviouslyBuiltAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyBuiltAndRestoredLightupLibTestProjectFixture
.Copy();
- var fixtureApp = PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
+ var fixtureApp = sharedTestState.PreviouslyBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
var dotnet = fixtureApp.BuiltDotnet;
var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
CopyLightupLib(fixture, fixtureLib);
.Fail()
.And
.HaveStdErrContaining($"Error initializing the dependency resolver: An error occurred while parsing: {additionalDepsPath}");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "9999.0.0", "additionalDeps");
}
[Fact]
var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
CopyLightupLib(fixture, fixtureLib);
.NotHaveStdErrContaining($"Adding tpa entry: {appAssembly}")
.And
.NotHaveStdErrContaining($"Replacing deps entry");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "9999.0.0", "additionalDeps");
- SharedFramework.DeleteAvailableSharedFxVersions(_uberFxBaseDir, "7777.0.0");
}
[Fact]
var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
.Copy();
- var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+ var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
.Copy();
CopyLightupLib(fixture, fixtureLib);
.HaveStdErrContaining($"Adding tpa entry: {appAssembly}")
.And
.HaveStdErrContaining($"Replacing deps entry [{uberAssembly}, AssemblyVersion:{SystemCollectionsImmutableAssemblyVersion}, FileVersion:{SystemCollectionsImmutableFileVersion}] with [{appAssembly}, AssemblyVersion:99.9.9.9, FileVersion:98.9.9.9]");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "9999.0.0", "additionalDeps");
- SharedFramework.DeleteAvailableSharedFxVersions(_uberFxBaseDir, "7777.0.0");
}
private static void CreateLightupFolder(string customLightupPath, string version, string libDepsJson)
var destNewtonsoftPath = Path.Combine(Path.GetDirectoryName(appDll), "Newtonsoft.Json.dll");
File.Copy(srcNewtonsoftPath, destNewtonsoftPath);
}
+
+ public class SharedTestState : IDisposable
+ {
+ public TestProjectFixture PreviouslyBuiltAndRestoredLightupLibTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredLightupLibTestProjectFixture { get; set; }
+
+ public TestProjectFixture PreviouslyBuiltAndRestoredLightupAppTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredLightupAppTestProjectFixture { get; set; }
+
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ PreviouslyBuiltAndRestoredLightupLibTestProjectFixture = new TestProjectFixture("LightupLib", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+
+ PreviouslyPublishedAndRestoredLightupLibTestProjectFixture = new TestProjectFixture("LightupLib", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .PublishProject();
+
+ PreviouslyBuiltAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+
+ PreviouslyPublishedAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .PublishProject();
+ }
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredLightupLibTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredLightupLibTestProjectFixture.Dispose();
+ PreviouslyBuiltAndRestoredLightupAppTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredLightupAppTestProjectFixture.Dispose();
+ }
+ }
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Threading;
using Microsoft.DotNet.InternalAbstractions;
using Xunit;
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
{
- public class GivenThatICareAboutMultilevelSDKLookup
+ public class GivenThatICareAboutMultilevelSDKLookup : IDisposable
{
- private static readonly Mutex id_mutex = new Mutex();
private static IDictionary<string, string> s_DefaultEnvironment = new Dictionary<string, string>()
{
{"COREHOST_TRACE", "1" },
private string _userSelectedMessage;
private string _exeSelectedMessage;
private string _sdkDir;
+ private string _multilevelDir;
private const string _dotnetSdkDllMessageTerminator = "dotnet.dll]";
// The dotnetMultilevelSDKLookup dir will contain some folders and files that will be
// necessary to perform the tests
string baseMultilevelDir = Path.Combine(artifactsDir, "dotnetMultilevelSDKLookup");
- string multilevelDir = CalculateMultilevelDirectory(baseMultilevelDir);
+ _multilevelDir = SharedFramework.CalculateUniqueTestDirectory(baseMultilevelDir);
// The three tested locations will be the cwd, the user folder and the exe dir. cwd and user are no longer supported.
// All dirs will be placed inside the multilevel folder
- _currentWorkingDir = Path.Combine(multilevelDir, "cwd");
- _userDir = Path.Combine(multilevelDir, "user");
- _executableDir = Path.Combine(multilevelDir, "exe");
+ _currentWorkingDir = Path.Combine(_multilevelDir, "cwd");
+ _userDir = Path.Combine(_multilevelDir, "user");
+ _executableDir = Path.Combine(_multilevelDir, "exe");
// It's necessary to copy the entire publish folder to the exe dir because
// we'll need to build from it. The CopyDirectory method automatically creates the dest dir
- CopyDirectory(builtDotnet, _executableDir);
+ SharedFramework.CopyDirectory(builtDotnet, _executableDir);
RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _executableDir);
// always pick the framework from this to avoid interference with the sharedFxLookup
string exeDirDummyFxVersion = Path.Combine(_executableDir, "shared", "Microsoft.NETCore.App", "9999.0.0");
string builtSharedFxDir = fixture.BuiltDotnet.GreatestVersionSharedFxPath;
- CopyDirectory(builtSharedFxDir, exeDirDummyFxVersion);
+ SharedFramework.CopyDirectory(builtSharedFxDir, exeDirDummyFxVersion);
// The actual SDK version can be obtained from the built fixture. We'll use it to
// locate the sdkDir from which we can get the files contained in the version folder
_userSelectedMessage = $"Using dotnet SDK dll=[{_userSdkBaseDir}";
_exeSelectedMessage = $"Using dotnet SDK dll=[{_exeSdkBaseDir}";
}
-
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture.Dispose();
+
+ if (!TestProject.PreserveTestRuns())
+ {
+ Directory.Delete(_multilevelDir, true);
+ }
+ }
+
[Fact]
public void SdkLookup_Global_Json_Single_Digit_Patch_Rollup()
{
foreach (string version in availableVersions)
{
string newSdkDir = Path.Combine(sdkBaseDir, version);
- CopyDirectory(_sdkDir, newSdkDir);
+ SharedFramework.CopyDirectory(_sdkDir, newSdkDir);
string runtimeConfig = Path.Combine(newSdkDir, "dotnet.runtimeconfig.json");
File.Copy(dummyRuntimeConfig, runtimeConfig, true);
}
}
- // This method removes a list of sdk version folders from the specified sdkBaseDir.
- // Remarks:
- // - If the sdkBaseDir does not exist, then a DirectoryNotFoundException
- // is thrown.
- // - If a specified version folder does not exist, then a DirectoryNotFoundException
- // is thrown.
- private void DeleteAvailableSdkVersions(string sdkBaseDir, params string[] availableVersions)
- {
- DirectoryInfo sdkBaseDirInfo = new DirectoryInfo(sdkBaseDir);
-
- if (!sdkBaseDirInfo.Exists)
- {
- throw new DirectoryNotFoundException();
- }
-
- foreach (string version in availableVersions)
- {
- string sdkDir = Path.Combine(sdkBaseDir, version);
- if (!Directory.Exists(sdkDir))
- {
- throw new DirectoryNotFoundException();
- }
- Directory.Delete(sdkDir, true);
- }
- }
-
- // CopyDirectory recursively copies a directory.
- // Remarks:
- // - If the dest dir does not exist, then it is created.
- // - If the dest dir exists, then it is substituted with the new one
- // (original files and subfolders are deleted).
- // - If the src dir does not exist, then a DirectoryNotFoundException
- // is thrown.
- private void CopyDirectory(string srcDir, string dstDir)
- {
- DirectoryInfo srcDirInfo = new DirectoryInfo(srcDir);
-
- if (!srcDirInfo.Exists)
- {
- throw new DirectoryNotFoundException();
- }
-
- DirectoryInfo dstDirInfo = new DirectoryInfo(dstDir);
-
- if (dstDirInfo.Exists)
- {
- dstDirInfo.Delete(true);
- }
-
- dstDirInfo.Create();
-
- foreach (FileInfo fileInfo in srcDirInfo.GetFiles())
- {
- string newFile = Path.Combine(dstDir, fileInfo.Name);
- fileInfo.CopyTo(newFile);
- }
-
- foreach (DirectoryInfo subdirInfo in srcDirInfo.GetDirectories())
- {
- string newDir = Path.Combine(dstDir, subdirInfo.Name);
- CopyDirectory(subdirInfo.FullName, newDir);
- }
- }
-
// Put a global.json file in the cwd in order to specify a CLI
public void SetGlobalJsonVersion(string globalJsonFileName)
{
File.Copy(srcFile, destFile, true);
}
-
- // MultilevelDirectory is %TEST_ARTIFACTS%\dotnetMultilevelSDKLookup\id.
- // We must locate the first non existing id.
- private string CalculateMultilevelDirectory(string baseMultilevelDir)
- {
- id_mutex.WaitOne();
-
- int count = 0;
- string multilevelDir;
-
- do
- {
- multilevelDir = Path.Combine(baseMultilevelDir, count.ToString());
- count++;
- } while (Directory.Exists(multilevelDir));
-
- id_mutex.ReleaseMutex();
-
- return multilevelDir;
- }
}
}
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLookup
{
- public class GivenThatICareAboutMultilevelSharedFxLookup
+ public class GivenThatICareAboutMultilevelSharedFxLookup : IDisposable
{
private const string SystemCollectionsImmutableFileVersion = "1.2.3.4";
private const string SystemCollectionsImmutableAssemblyVersion = "1.0.1.2";
_globalFoundUberFxMessage = $"Chose FX version [{_globalSharedUberFxBaseDir}";
}
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture.Dispose();
+
+ if (!TestProject.PreserveTestRuns())
+ {
+ Directory.Delete(_multilevelDir, true);
+ }
+ }
+
[Fact]
public void SharedFxLookup_Must_Verify_Folders_in_the_Correct_Order()
{
.Pass()
.And
.HaveStdOutContaining("Microsoft.NETCore.App 9999.0.0");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_cwdSharedFxBaseDir, "9999.0.0");
}
[Fact]
.HaveStdOutContaining("Microsoft.NETCore.App 9999.0.3")
.And
.HaveStdOutContaining("Microsoft.NETCore.App 9999.0.0-dummy3");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0", "9999.0.2", "9999.0.0-dummy2", "9999.0.3", "9999.0.0-dummy3");
}
[Fact]
.HaveStdOutContaining("Microsoft.NETCore.App 10000.1.1")
.And
.HaveStdOutContaining("Microsoft.NETCore.App 10000.1.3");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.1", "10000.1.1", "10000.1.3");
}
[Fact]
.HaveStdOutContaining("Microsoft.NETCore.App 9999.1.1")
.And
.HaveStdOutContaining("Microsoft.NETCore.App 10000.1.1");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.1", "10000.1.1");
}
[Fact]
.HaveStdOutContaining("Microsoft.NETCore.App 9999.2.1-dummy1")
.And
.HaveStdOutContaining("Microsoft.NETCore.App 9999.2.2-dummy1");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.1-dummy1", "9999.2.1", "9999.2.1-dummy1", "9999.2.2-dummy1");
}
[Fact]
.HaveStdOutContaining("9999.0.0")
.And
.HaveStdOutContaining("9999.0.1-dummy1");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0-dummy2", "9999.0.0-dummy3", "9999.0.0", "9999.0.1-dummy1");
}
[Fact]
.HaveStdOutContaining("Microsoft.NETCore.App 9999.0.1")
.And
.HaveStdOutContaining("Microsoft.NETCore.App 9999.1.0");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9998.0.1", "9998.1.0", "9999.0.0", "9999.0.1", "9999.1.0");
}
[Fact]
.HaveStdOutContaining("Microsoft.UberFramework 7777.0.0")
.And
.HaveStdOutContaining("Microsoft.UberFramework 7777.0.1");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0", "9999.0.1");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0", "7777.0.1");
}
[Fact]
.HaveStdErrContaining(Path.Combine(_exeFoundUberFxMessage, "7777.0.0"))
.And
.HaveStdErrContaining("Property TestProperty = AppValue");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0");
}
[Fact]
.Fail()
.And
.HaveStdErrContaining("It was not possible to find any compatible framework version");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0");
}
[Fact]
.Pass()
.And
.HaveStdErrContaining($"Replacing deps entry [{uberFile}, AssemblyVersion:1.0.1.2, FileVersion:{SystemCollectionsImmutableFileVersion}] with [{netCoreAppFile}");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.1.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0");
}
[Fact]
.HaveStdErrContaining(Path.Combine("7777.0.0", "System.Collections.Immutable.dll"))
.And
.NotHaveStdErrContaining(Path.Combine("9999.1.0", "System.Collections.Immutable.dll"));
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.1");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0");
}
[Fact]
.Pass()
.And
.HaveStdErrContaining($"Replacing deps entry [{appAssembly}, AssemblyVersion:{SystemCollectionsImmutableAssemblyVersion}, FileVersion:{SystemCollectionsImmutableFileVersion}] with [{uberAssembly}, AssemblyVersion:{SystemCollectionsImmutableAssemblyVersion}, FileVersion:{SystemCollectionsImmutableFileVersion}]");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.1.0");
}
[Fact]
.NotHaveStdErrContaining($"Adding tpa entry: {netcoreAssembly}, AssemblyVersion: {SystemCollectionsImmutableAssemblyVersion}, FileVersion :{SystemCollectionsImmutableFileVersion}")
.And
.NotHaveStdErrContaining($"Replacing deps entry");
-
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0");
- SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0");
}
static private JObject GetAdditionalFramework(string fxName, string fxVersion, bool? applyPatches, int? rollForwardOnNoCandidateFx)
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHostApis
{
- public class GivenThatICareAboutNativeHostApis
+ public class GivenThatICareAboutNativeHostApis : IClassFixture<GivenThatICareAboutNativeHostApis.SharedTestState>
{
- private static TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
- private static TestProjectFixture PreviouslyPublishedAndRestoredPortableTestProjectFixture { get; set; }
- private static RepoDirectoriesProvider RepoDirectories { get; set; }
+ private SharedTestState sharedTestState;
- static GivenThatICareAboutNativeHostApis()
+ public GivenThatICareAboutNativeHostApis(GivenThatICareAboutNativeHostApis.SharedTestState fixture)
{
- RepoDirectories = new RepoDirectoriesProvider();
-
- PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("HostApiInvokerApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
-
- PreviouslyPublishedAndRestoredPortableTestProjectFixture = new TestProjectFixture("HostApiInvokerApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .PublishProject();
+ sharedTestState = fixture;
}
[Fact]
return;
}
- var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture.Copy();
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture.Copy();
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
.And
.HaveStdOutContaining("hostfxr_get_native_search_directories buffer:[" + dotnet.GreatestVersionSharedFxPath);
}
+
+ public class SharedTestState : IDisposable
+ {
+ public TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredPortableTestProjectFixture { get; set; }
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("HostApiInvokerApp", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+
+ PreviouslyPublishedAndRestoredPortableTestProjectFixture = new TestProjectFixture("HostApiInvokerApp", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .PublishProject();
+ }
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredPortableTestProjectFixture.Dispose();
+ }
+ }
}
}
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
{
- public class GivenThatICareAboutPortableAppActivation
+ public class GivenThatICareAboutPortableAppActivation : IClassFixture<GivenThatICareAboutPortableAppActivation.SharedTestState>
{
- private static TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
- private static TestProjectFixture PreviouslyPublishedAndRestoredPortableTestProjectFixture { get; set; }
- private static RepoDirectoriesProvider RepoDirectories { get; set; }
+ private SharedTestState sharedTestState;
- static GivenThatICareAboutPortableAppActivation()
+ public GivenThatICareAboutPortableAppActivation(GivenThatICareAboutPortableAppActivation.SharedTestState fixture)
{
- RepoDirectories = new RepoDirectoriesProvider();
-
- PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
-
- PreviouslyPublishedAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .PublishProject();
+ sharedTestState = fixture;
}
[Fact]
public void Muxer_activation_of_Build_Output_Portable_DLL_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_activation_of_Build_Output_Portable_DLL_with_DepsJson_having_Assembly_with_Different_File_Extension_Fails()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_activation_of_Apps_with_AltDirectorySeparatorChar()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Local_and_RuntimeConfig_Remote_Without_AdditionalProbingPath_Fails()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
MoveRuntimeConfigToSubdirectory(fixture);
[Fact]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Local_and_RuntimeConfig_Remote_With_AdditionalProbingPath_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
MoveRuntimeConfigToSubdirectory(fixture);
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
var runtimeConfig = fixture.TestProject.RuntimeConfigJson;
- var additionalProbingPath = RepoDirectories.NugetPackages;
+ var additionalProbingPath = sharedTestState.RepoDirectories.NugetPackages;
dotnet.Exec(
"exec",
[Fact]
public void Muxer_Activation_With_Templated_AdditionalProbingPath_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
-
+
var store_path = CreateAStore(fixture);
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
.And
.HaveStdOutContaining("Hello World")
.And
- .HaveStdErrContaining($"Adding tpa entry: {Path.Combine(store_path,fixture.RepoDirProvider.BuildArchitecture, fixture.Framework)}");
+ .HaveStdErrContaining($"Adding tpa entry: {Path.Combine(store_path, fixture.RepoDirProvider.BuildArchitecture, fixture.Framework)}");
}
[Fact]
public void Muxer_Exec_activation_of_Build_Output_Portable_DLL_with_DepsJson_Remote_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
- .Copy();
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
+ .Copy();
MoveDepsJsonToSubdirectory(fixture);
[Fact]
public void Muxer_activation_of_Publish_Output_Portable_DLL_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_Exec_activation_of_Publish_Output_Portable_DLL_with_DepsJson_Local_and_RuntimeConfig_Remote_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture
.Copy();
MoveRuntimeConfigToSubdirectory(fixture);
[Fact]
public void Muxer_Exec_activation_of_Publish_Output_Portable_DLL_with_DepsJson_Remote_and_RuntimeConfig_Local_Fails()
{
- var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture
- .Copy();
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture
+ .Copy();
MoveDepsJsonToSubdirectory(fixture);
[Fact]
public void Framework_Dependent_AppHost_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture
.Copy();
// Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
var appDllName = Path.GetFileName(fixture.TestProject.AppDll);
string hostExeName = $"apphost{Constants.ExeSuffix}";
- string builtAppHost = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);
+ string builtAppHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
string appDir = Path.GetDirectoryName(appExe);
string appDirHostExe = Path.Combine(appDir, hostExeName);
return storeoutputDirectory;
}
+
+ public class SharedTestState : IDisposable
+ {
+ public TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredPortableTestProjectFixture { get; set; }
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+
+ PreviouslyPublishedAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .PublishProject();
+ }
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredPortableTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredPortableTestProjectFixture.Dispose();
+ }
+ }
}
}
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ResourceLookup
{
- public class GivenThatICareAboutResourceLookup
+ public class GivenThatICareAboutResourceLookup : IClassFixture<GivenThatICareAboutResourceLookup.SharedTestState>
{
- private static TestProjectFixture PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture { get; set; }
- private static TestProjectFixture PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture { get; set; }
- private static RepoDirectoriesProvider RepoDirectories { get; set; }
+ private SharedTestState sharedTestState;
- static GivenThatICareAboutResourceLookup()
+ public GivenThatICareAboutResourceLookup(GivenThatICareAboutResourceLookup.SharedTestState fixture)
{
- RepoDirectories = new RepoDirectoriesProvider();
-
- PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture = new TestProjectFixture("ResourceLookup", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .BuildProject();
-
- PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture = new TestProjectFixture("ResourceLookup", RepoDirectories)
- .EnsureRestored(RepoDirectories.CorehostPackages)
- .PublishProject();
+ sharedTestState = fixture;
}
[Fact]
public void Muxer_activation_of_Build_Output_Resource_DLL_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
[Fact]
public void Muxer_activation_of_Publish_Output_ResourceLookup_DLL_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture
.Copy();
var dotnet = fixture.BuiltDotnet;
.And
.HaveStdOutContaining("Hello World");
}
+
+ public class SharedTestState : IDisposable
+ {
+ public TestProjectFixture PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture { get; set; }
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture = new TestProjectFixture("ResourceLookup", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .BuildProject();
+
+ PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture = new TestProjectFixture("ResourceLookup", RepoDirectories)
+ .EnsureRestored(RepoDirectories.CorehostPackages)
+ .PublishProject();
+ }
+
+ public void Dispose()
+ {
+ PreviouslyBuiltAndRestoredResourceLookupTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredResourceLookupTestProjectFixture.Dispose();
+ }
+ }
}
}
namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
{
- public class GivenThatICareAboutStandaloneAppActivation
+ public class GivenThatICareAboutStandaloneAppActivation : IClassFixture<GivenThatICareAboutStandaloneAppActivation.SharedTestState>
{
- public static TestProjectFixture PreviouslyBuiltAndRestoredStandaloneTestProjectFixture { get; private set; }
- public static TestProjectFixture PreviouslyPublishedAndRestoredStandaloneTestProjectFixture { get; private set; }
- private static RepoDirectoriesProvider RepoDirectories { get; set; }
+ private SharedTestState sharedTestState;
- static GivenThatICareAboutStandaloneAppActivation()
+ public GivenThatICareAboutStandaloneAppActivation(GivenThatICareAboutStandaloneAppActivation.SharedTestState fixture)
{
- RepoDirectories = new RepoDirectoriesProvider();
-
- var buildFixture = new TestProjectFixture("StandaloneApp", RepoDirectories);
- buildFixture
- .EnsureRestoredForRid(buildFixture.CurrentRid, RepoDirectories.CorehostPackages)
- .BuildProject(runtime: buildFixture.CurrentRid);
-
- var publishFixture = new TestProjectFixture("StandaloneApp", RepoDirectories);
- publishFixture
- .EnsureRestoredForRid(publishFixture.CurrentRid, RepoDirectories.CorehostPackages)
- .PublishProject(runtime: publishFixture.CurrentRid);
-
- ReplaceTestProjectOutputHostInTestProjectFixture(buildFixture);
-
- PreviouslyBuiltAndRestoredStandaloneTestProjectFixture = buildFixture;
- PreviouslyPublishedAndRestoredStandaloneTestProjectFixture = publishFixture;
+ sharedTestState = fixture;
}
[Fact]
public void Running_Build_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyBuiltAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyBuiltAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
[Fact]
public void Running_Publish_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
[Fact]
public void Running_Publish_Output_Standalone_EXE_with_Unbound_AppHost_Fails()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
string hostExeName = $"apphost{Constants.ExeSuffix}";
- string builtAppHost = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);
+ string builtAppHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
File.Copy(builtAppHost, appExe, true);
int exitCode = Command.Create(appExe)
[Fact]
public void Running_Publish_Output_Standalone_EXE_By_Renaming_dotnet_exe_Fails()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
string hostExeName = $"dotnet{Constants.ExeSuffix}";
- string builtHost = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);
+ string builtHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
File.Copy(builtHost, appExe, true);
int exitCode = Command.Create(appExe)
[Fact]
public void Running_Publish_Output_Standalone_EXE_By_Renaming_apphost_exe_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
[Fact]
public void Running_Publish_Output_Standalone_EXE_With_Relative_Embedded_Path_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
[Fact]
public void Running_Publish_Output_Standalone_EXE_With_DOTNET_ROOT_Fails()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
[Fact]
public void Running_Publish_Output_Standalone_EXE_with_Bound_AppHost_Succeeds()
{
- var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
+ var fixture = sharedTestState.PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
.Copy();
var appExe = fixture.TestProject.AppExe;
string hostExeName = $"apphost{Constants.ExeSuffix}";
- string builtAppHost = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);
+ string builtAppHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
string appName = Path.GetFileNameWithoutExtension(appExe);
string appDll = $"{appName}.dll";
string appDir = Path.GetDirectoryName(appExe);
.HaveStdOutContaining("Hello World");
}
- /*
- * This method is needed to workaround dotnet build not placing the host from the package
- * graph in the build output.
- * https://github.com/dotnet/cli/issues/2343
- */
- private static void ReplaceTestProjectOutputHostInTestProjectFixture(TestProjectFixture testProjectFixture)
+ public class SharedTestState : IDisposable
{
- var dotnet = testProjectFixture.BuiltDotnet;
+ public TestProjectFixture PreviouslyBuiltAndRestoredStandaloneTestProjectFixture { get; set; }
+ public TestProjectFixture PreviouslyPublishedAndRestoredStandaloneTestProjectFixture { get; set; }
+ public RepoDirectoriesProvider RepoDirectories { get; set; }
+
+ public SharedTestState()
+ {
+ RepoDirectories = new RepoDirectoriesProvider();
+
+ var buildFixture = new TestProjectFixture("StandaloneApp", RepoDirectories);
+ buildFixture
+ .EnsureRestoredForRid(buildFixture.CurrentRid, RepoDirectories.CorehostPackages)
+ .BuildProject(runtime: buildFixture.CurrentRid);
+
+ var publishFixture = new TestProjectFixture("StandaloneApp", RepoDirectories);
+ publishFixture
+ .EnsureRestoredForRid(publishFixture.CurrentRid, RepoDirectories.CorehostPackages)
+ .PublishProject(runtime: publishFixture.CurrentRid);
- var testProjectHostPolicy = testProjectFixture.TestProject.HostPolicyDll;
- var testProjectHostFxr = testProjectFixture.TestProject.HostFxrDll;
+ ReplaceTestProjectOutputHostInTestProjectFixture(buildFixture);
- if (!File.Exists(testProjectHostPolicy))
+ PreviouslyBuiltAndRestoredStandaloneTestProjectFixture = buildFixture;
+ PreviouslyPublishedAndRestoredStandaloneTestProjectFixture = publishFixture;
+ }
+
+ public void Dispose()
{
- throw new Exception("host or hostpolicy does not exist in test project output. Is this a standalone app?");
+ PreviouslyBuiltAndRestoredStandaloneTestProjectFixture.Dispose();
+ PreviouslyPublishedAndRestoredStandaloneTestProjectFixture.Dispose();
}
- var dotnetHostPolicy = Path.Combine(dotnet.GreatestVersionSharedFxPath, $"{testProjectFixture.SharedLibraryPrefix}hostpolicy{testProjectFixture.SharedLibraryExtension}");
- var dotnetHostFxr = Path.Combine(dotnet.GreatestVersionHostFxrPath, $"{testProjectFixture.SharedLibraryPrefix}hostfxr{testProjectFixture.SharedLibraryExtension}");
+ /*
+ * This method is needed to workaround dotnet build not placing the host from the package
+ * graph in the build output.
+ * https://github.com/dotnet/cli/issues/2343
+ */
+ private static void ReplaceTestProjectOutputHostInTestProjectFixture(TestProjectFixture testProjectFixture)
+ {
+ var dotnet = testProjectFixture.BuiltDotnet;
- File.Copy(dotnetHostPolicy, testProjectHostPolicy, true);
+ var testProjectHostPolicy = testProjectFixture.TestProject.HostPolicyDll;
+ var testProjectHostFxr = testProjectFixture.TestProject.HostFxrDll;
- if (File.Exists(testProjectHostFxr))
- {
- File.Copy(dotnetHostFxr, testProjectHostFxr, true);
+ if (!File.Exists(testProjectHostPolicy))
+ {
+ throw new Exception("host or hostpolicy does not exist in test project output. Is this a standalone app?");
+ }
+
+ var dotnetHostPolicy = Path.Combine(dotnet.GreatestVersionSharedFxPath, $"{testProjectFixture.SharedLibraryPrefix}hostpolicy{testProjectFixture.SharedLibraryExtension}");
+ var dotnetHostFxr = Path.Combine(dotnet.GreatestVersionHostFxrPath, $"{testProjectFixture.SharedLibraryPrefix}hostfxr{testProjectFixture.SharedLibraryExtension}");
+
+ File.Copy(dotnetHostPolicy, testProjectHostPolicy, true);
+
+ if (File.Exists(testProjectHostFxr))
+ {
+ File.Copy(dotnetHostFxr, testProjectHostFxr, true);
+ }
}
}
}
using Newtonsoft.Json.Linq;
using System;
using System.IO;
+using System.Threading;
namespace Microsoft.DotNet.CoreSetup.Test
{
/// </summary>
internal static class SharedFramework
{
+ private static readonly Mutex id_mutex = new Mutex();
+
// MultilevelDirectory is %TEST_ARTIFACTS%\dotnetMultilevelSharedFxLookup\id.
// We must locate the first non existing id.
public static string CalculateUniqueTestDirectory(string baseDir)
{
+ id_mutex.WaitOne();
+
int count = 0;
string dir;
count++;
} while (Directory.Exists(dir));
+ id_mutex.ReleaseMutex();
+
return dir;
}
}
}
- // This method removes a list of framework version folders from the specified
- // sharedFxBaseDir.
- // Remarks:
- // - If the sharedFxBaseDir does not exist, then a DirectoryNotFoundException
- // is thrown.
- // - If a specified version folder does not exist, then a DirectoryNotFoundException
- // is thrown.
- public static void DeleteAvailableSharedFxVersions(string sharedFxBaseDir, params string[] availableVersions)
- {
- DirectoryInfo sharedFxBaseDirInfo = new DirectoryInfo(sharedFxBaseDir);
-
- if (!sharedFxBaseDirInfo.Exists)
- {
- throw new DirectoryNotFoundException();
- }
-
- foreach (string version in availableVersions)
- {
- string sharedFxDir = Path.Combine(sharedFxBaseDir, version);
- if (!Directory.Exists(sharedFxDir))
- {
- throw new DirectoryNotFoundException();
- }
- Directory.Delete(sharedFxDir, true);
- }
- }
-
// Generated json file:
/*
* {
namespace Microsoft.DotNet.CoreSetup.Test
{
- public class TestProject
+ public class TestProject : IDisposable
{
private string _projectDirectory;
private string _projectName;
}
}
+ public void Dispose()
+ {
+ if (!PreserveTestRuns())
+ {
+ Directory.Delete(_projectDirectory, true);
+ }
+ }
+
public void CopyProjectFiles(string directory)
{
CopyRecursive(_projectDirectory, directory, overwrite: true);
}
}
}
+
+ public static bool PreserveTestRuns()
+ {
+ return Environment.GetEnvironmentVariable("PRESERVE_TEST_RUNS") == "1";
+ }
}
}
* setup of the TestProject, copying test projects for perf on build/restore,
* and building/publishing/restoring test projects where necessary.
*/
- public class TestProjectFixture
+ public class TestProjectFixture : IDisposable
{
private static readonly string s_testArtifactDirectoryEnvironmentVariable = "TEST_ARTIFACTS";
private TestProject _sourceTestProject;
private TestProject _testProject;
+ private List<TestProject> _copiedTestProjects = new List<TestProject>();
public DotNetCli SdkDotnet => _sdkDotnet;
public DotNetCli BuiltDotnet => _builtDotnet;
_sharedLibraryExtension,
_sharedLibraryPrefix,
_assemblyName);
+
+ fixtureToCopy._copiedTestProjects.Add(_testProject);
+ }
+
+ public void Dispose()
+ {
+ if (_testProject != null)
+ {
+ _testProject.Dispose();
+ _testProject = null;
+ }
+
+ foreach (var project in _copiedTestProjects)
+ {
+ project.Dispose();
+ }
+
+ _copiedTestProjects.Clear();
}
private void InitializeTestProject(
EnsureDirectoryBuildProps(testArtifactDirectory);
sourceTestProject.CopyProjectFiles(copiedTestProjectDirectory);
+
return new TestProject(
copiedTestProjectDirectory,
exeExtension,