Clean up test disk space after execution (dotnet/core-setup#4297)
authorSteve Harter <steveharter@users.noreply.github.com>
Mon, 25 Jun 2018 18:09:02 +0000 (13:09 -0500)
committerGitHub <noreply@github.com>
Mon, 25 Jun 2018 18:09:02 +0000 (13:09 -0500)
Commit migrated from https://github.com/dotnet/core-setup/commit/ef0dbddcf672f38ecc830ebbf51febf4c71c1879

13 files changed:
src/installer/test/HostActivationTests/GivenThatICareAboutDotnetArgValidationScenarios.cs
src/installer/test/HostActivationTests/GivenThatICareAboutDotnetTestXunitScenarios.cs
src/installer/test/HostActivationTests/GivenThatICareAboutHostVersionCompatibility.cs
src/installer/test/HostActivationTests/GivenThatICareAboutLightupAppActivation.cs
src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSDKLookup.cs
src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs
src/installer/test/HostActivationTests/GivenThatICareAboutNativeHostApis.cs
src/installer/test/HostActivationTests/GivenThatICareAboutPortableAppActivation.cs
src/installer/test/HostActivationTests/GivenThatICareAboutResourceLookup.cs
src/installer/test/HostActivationTests/GivenThatICareAboutStandaloneAppActivation.cs
src/installer/test/HostActivationTests/SharedFramework.cs
src/installer/test/TestUtils/TestProject.cs
src/installer/test/TestUtils/TestProjectFixture.cs

index 2ff94c7..db521fd 100644 (file)
@@ -11,24 +11,19 @@ using Xunit;
 
 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;
@@ -48,7 +43,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ArgValidation
         [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;
@@ -68,7 +63,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ArgValidation
         [Fact]
         public void Muxer_Exec_With_Bad_Extension_Fails()
         {
-            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+            var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
                 .Copy();
 
             var dotnet = fixture.BuiltDotnet;
@@ -91,7 +86,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ArgValidation
         [Fact]
         public void Detect_Missing_Argument_Value()
         {
-            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+            var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
                 .Copy();
 
             var dotnet = fixture.BuiltDotnet;
@@ -109,7 +104,27 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ArgValidation
         // 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();
+            }
         }
     }
 }
index f7405b2..39d700d 100644 (file)
@@ -22,22 +22,27 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
         [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(
index 76c2177..30a9dd3 100644 (file)
@@ -16,32 +16,28 @@ using Xunit;
 
 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())
             {
@@ -51,8 +47,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
             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)
@@ -71,7 +67,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
             // 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()
@@ -82,13 +78,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
                 .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()
@@ -99,19 +95,29 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
                 .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);
@@ -150,23 +156,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
                 .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;
@@ -178,5 +167,54 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.VersionCompatibility
                 (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;
+            }
+        }
     }
 }
index 26b773c..3b2411f 100644 (file)
@@ -14,22 +14,13 @@ using Microsoft.DotNet.Cli.Build.Framework;
 
 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;
@@ -37,29 +28,12 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
         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");
@@ -75,25 +49,35 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
 
             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;
@@ -119,10 +103,10 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
         [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;
@@ -171,7 +155,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
         [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
@@ -233,14 +217,12 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .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
@@ -298,14 +280,12 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .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
@@ -353,8 +333,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .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 
@@ -362,10 +340,10 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
         [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;
@@ -393,7 +371,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
             var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
                 .Copy();
 
-            var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+            var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
                 .Copy();
 
             CopyLightupLib(fixture, fixtureLib);
@@ -426,8 +404,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .Fail()
                 .And
                 .HaveStdErrContaining($"Error initializing the dependency resolver: An error occurred while parsing: {additionalDepsPath}");
-
-            SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "9999.0.0", "additionalDeps");
         }
 
         [Fact]
@@ -436,7 +412,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
             var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
                 .Copy();
 
-            var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+            var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
                 .Copy();
 
             CopyLightupLib(fixture, fixtureLib);
@@ -487,9 +463,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .NotHaveStdErrContaining($"Adding tpa entry: {appAssembly}")
                 .And
                 .NotHaveStdErrContaining($"Replacing deps entry");
-
-            SharedFramework.DeleteAvailableSharedFxVersions(_fxBaseDir, "9999.0.0", "additionalDeps");
-            SharedFramework.DeleteAvailableSharedFxVersions(_uberFxBaseDir, "7777.0.0");
         }
 
         [Fact]
@@ -498,7 +471,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
             var fixture = PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture
                 .Copy();
 
-            var fixtureLib = PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
+            var fixtureLib = sharedTestState.PreviouslyPublishedAndRestoredLightupLibTestProjectFixture
                 .Copy();
 
             CopyLightupLib(fixture, fixtureLib);
@@ -550,9 +523,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
                 .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)
@@ -601,5 +571,45 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.LightupApp
             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();
+            }
+        }
     }
 }
index 1064c83..e3702b5 100644 (file)
@@ -2,15 +2,13 @@ using System;
 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" },
@@ -32,6 +30,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
         private string _userSelectedMessage;
         private string _exeSelectedMessage;
         private string _sdkDir;
+        private string _multilevelDir;
 
         private const string _dotnetSdkDllMessageTerminator = "dotnet.dll]";
 
@@ -45,18 +44,18 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
             // 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);
 
@@ -80,7 +79,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
             // 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
@@ -101,7 +100,17 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
             _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()
         {
@@ -676,77 +685,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
             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)
         {
@@ -756,25 +701,5 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSDKLookup
 
             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;
-        }
     }
 }
index e123247..8205cfb 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 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";
@@ -119,6 +119,16 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
             _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()
         {
@@ -200,9 +210,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .Pass()
                 .And
                 .HaveStdOutContaining("Microsoft.NETCore.App 9999.0.0");
-
-            SharedFramework.DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.0");
-            SharedFramework.DeleteAvailableSharedFxVersions(_cwdSharedFxBaseDir, "9999.0.0");
         }
 
         [Fact]
@@ -264,8 +271,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -332,8 +337,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -412,8 +415,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -516,8 +517,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -582,8 +581,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -633,8 +630,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -711,9 +706,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -801,9 +793,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -892,9 +881,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -933,9 +919,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -974,9 +957,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -1026,9 +1006,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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]
@@ -1082,9 +1059,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .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)
index c51ebf6..2e9061e 100644 (file)
@@ -10,23 +10,13 @@ using Microsoft.DotNet.CoreSetup.Test;
 
 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]
@@ -39,7 +29,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHostApis
                 return;
             }
 
-            var fixture = PreviouslyPublishedAndRestoredPortableTestProjectFixture.Copy();
+            var fixture = sharedTestState.PreviouslyPublishedAndRestoredPortableTestProjectFixture.Copy();
             var dotnet = fixture.BuiltDotnet;
             var appDll = fixture.TestProject.AppDll;
 
@@ -61,5 +51,31 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHostApis
                 .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();
+            }
+        }
     }
 }
index c03fab5..41cb262 100644 (file)
@@ -15,29 +15,19 @@ using Xunit;
 
 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;
@@ -65,7 +55,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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;
@@ -88,7 +78,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [Fact]
         public void Muxer_activation_of_Apps_with_AltDirectorySeparatorChar()
         {
-            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+            var fixture = sharedTestState.PreviouslyBuiltAndRestoredPortableTestProjectFixture
                 .Copy();
 
             var dotnet = fixture.BuiltDotnet;
@@ -106,7 +96,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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);
@@ -126,7 +116,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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);
@@ -134,7 +124,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
             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",
@@ -153,9 +143,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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;
@@ -182,14 +172,14 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
                 .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);
 
@@ -211,7 +201,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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;
@@ -240,7 +230,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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);
@@ -262,8 +252,8 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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);
 
@@ -282,7 +272,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
         [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
@@ -291,7 +281,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
             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);
 
@@ -388,5 +378,31 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.PortableApp
             
             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();
+            }
+        }
     }
 }
index e29d648..9b37454 100644 (file)
@@ -12,29 +12,19 @@ using Microsoft.DotNet.CoreSetup.Test;
 
 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;
@@ -62,7 +52,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ResourceLookup
         [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;
@@ -86,5 +76,31 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.ResourceLookup
                 .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();
+            }
+        }
     }
 }
index 1b397ac..075f326 100644 (file)
@@ -17,36 +17,19 @@ using Microsoft.DotNet.InternalAbstractions;
 
 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;
@@ -64,7 +47,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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;
@@ -82,13 +65,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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)
@@ -111,13 +94,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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)
@@ -140,7 +123,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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;
@@ -161,7 +144,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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;
@@ -198,7 +181,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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;
@@ -243,13 +226,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
         [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);
@@ -279,31 +262,64 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.StandaloneApp
                 .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);
+                }
             }
         }
     }
index ae8bd34..0f7d033 100644 (file)
@@ -4,6 +4,7 @@
 using Newtonsoft.Json.Linq;
 using System;
 using System.IO;
+using System.Threading;
 
 namespace Microsoft.DotNet.CoreSetup.Test
 {
@@ -12,10 +13,14 @@ 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;
 
@@ -25,6 +30,8 @@ namespace Microsoft.DotNet.CoreSetup.Test
                 count++;
             } while (Directory.Exists(dir));
 
+            id_mutex.ReleaseMutex();
+
             return dir;
         }
 
@@ -73,33 +80,6 @@ namespace Microsoft.DotNet.CoreSetup.Test
             }
         }
 
-        // 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:
         /*
          * {
index 8cac8e2..2e31cbf 100644 (file)
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace Microsoft.DotNet.CoreSetup.Test
 {
-    public class TestProject
+    public class TestProject : IDisposable
     {
         private string _projectDirectory;
         private string _projectName;
@@ -66,6 +66,14 @@ namespace Microsoft.DotNet.CoreSetup.Test
             }
         }
 
+        public void Dispose()
+        {
+            if (!PreserveTestRuns())
+            {
+                Directory.Delete(_projectDirectory, true);
+            }
+        }
+
         public void CopyProjectFiles(string directory)
         {
             CopyRecursive(_projectDirectory, directory, overwrite: true);
@@ -115,5 +123,10 @@ namespace Microsoft.DotNet.CoreSetup.Test
                 }
             }
         }
+
+        public static bool PreserveTestRuns()
+        {
+            return Environment.GetEnvironmentVariable("PRESERVE_TEST_RUNS") == "1";
+        }
     }
 }
index 690d9bc..f3d3ba9 100644 (file)
@@ -11,7 +11,7 @@ namespace Microsoft.DotNet.CoreSetup.Test
      * 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";
 
@@ -32,6 +32,7 @@ namespace Microsoft.DotNet.CoreSetup.Test
 
         private TestProject _sourceTestProject;
         private TestProject _testProject;
+        private List<TestProject> _copiedTestProjects = new List<TestProject>();
 
         public DotNetCli SdkDotnet => _sdkDotnet;
         public DotNetCli BuiltDotnet => _builtDotnet;
@@ -116,6 +117,24 @@ namespace Microsoft.DotNet.CoreSetup.Test
                 _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(
@@ -159,6 +178,7 @@ namespace Microsoft.DotNet.CoreSetup.Test
             EnsureDirectoryBuildProps(testArtifactDirectory);
 
             sourceTestProject.CopyProjectFiles(copiedTestProjectDirectory);
+
             return new TestProject(
                 copiedTestProjectDirectory,
                 exeExtension,