Add additional TPA version tests (dotnet/core-setup#4557)
authorSteve Harter <steveharter@users.noreply.github.com>
Thu, 13 Sep 2018 14:56:30 +0000 (09:56 -0500)
committerGitHub <noreply@github.com>
Thu, 13 Sep 2018 14:56:30 +0000 (09:56 -0500)
Commit migrated from https://github.com/dotnet/core-setup/commit/3d5a97ae62c259c4f8886dd72ac35689385ad817

src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.DepsVersion.cs [new file with mode: 0644]
src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs

diff --git a/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.DepsVersion.cs b/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.DepsVersion.cs
new file mode 100644 (file)
index 0000000..cc4b4ba
--- /dev/null
@@ -0,0 +1,143 @@
+using Microsoft.DotNet.InternalAbstractions;
+using Microsoft.DotNet.Cli.Build.Framework;
+using Newtonsoft.Json.Linq;
+using System;
+using System.IO;
+using Xunit;
+
+namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLookup
+{
+    public partial class GivenThatICareAboutMultilevelSharedFxLookup
+    {
+        [Fact]
+        public void TPA_Version_Check_App_Wins()
+        {
+            string appAssembly;
+            string uberAssembly;
+            string netcoreAssembly;
+
+            // Apps wins, 9999.0.0.1 vs Uber (existing version) and NetCore (also existing version)
+            var fixture = ConfigureAppAndFrameworks("99.0.0.1", null, "7777.0.0", out appAssembly, out uberAssembly, out netcoreAssembly);
+            var dotnet = fixture.BuiltDotnet;
+            var appDll = fixture.TestProject.AppDll;
+
+            dotnet.Exec(appDll)
+                .WorkingDirectory(_currentWorkingDir)
+                .EnvironmentVariable("COREHOST_TRACE", "1")
+                .CaptureStdOut()
+                .CaptureStdErr()
+                .Execute()
+                .Should()
+                .Pass()
+                .And
+                // Verify final selection in TRUSTED_PLATFORM_ASSEMBLIES
+                .HaveStdErrContaining($"{appAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{netcoreAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{uberAssembly}{Path.PathSeparator}");
+        }
+
+        [Theory]
+        [InlineData("0.0.0.1", "", "7777.0.0")]          // Uber wins, existing assembly version vs app (0.0.0.1) and NetCore (also existing version)
+        [InlineData("99.0.0.1", "99.0.0.1", "7777.0.0")] // Tie case, no roll forward
+        [InlineData("99.0.0.1", "99.0.0.1", "7777.0.1")] // Tie case, patch roll forward
+        [InlineData("99.0.0.1", "99.0.0.1", "7777.1.0")] // Tie case, minor roll forward
+        [InlineData("99.0.0.1", "99.0.0.1", "7778.0.0")] // Tie case, major roll forward
+        public void TPA_Version_Check_UberFx_Wins(string appAssemblyVersion, string uberFxAssemblyVersion, string uberProductVersion)
+        {
+            string appAssembly;
+            string uberAssembly;
+            string netcoreAssembly;
+
+            var fixture = ConfigureAppAndFrameworks(appAssemblyVersion, uberFxAssemblyVersion, uberProductVersion, out appAssembly, out uberAssembly, out netcoreAssembly);
+            var dotnet = fixture.BuiltDotnet;
+            var appDll = fixture.TestProject.AppDll;
+
+            dotnet.Exec(appDll)
+                .WorkingDirectory(_currentWorkingDir)
+                .EnvironmentVariable("COREHOST_TRACE", "1")
+                .EnvironmentVariable("DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX", "2") // Allow major roll forward
+                .CaptureStdOut()
+                .CaptureStdErr()
+                .Execute()
+                .Should()
+                .Pass()
+                .And
+                .HaveStdErrContaining(Path.Combine(_exeFoundUberFxMessage, uberProductVersion))
+                .And
+                // Verify final selection in TRUSTED_PLATFORM_ASSEMBLIES
+                .HaveStdErrContaining($"{uberAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{netcoreAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{appAssembly}{Path.PathSeparator}");
+        }
+
+        [Fact]
+        public void TPA_Version_Check_NetCore_Wins()
+        {
+            string appAssembly;
+            string uberAssembly;
+            string netcoreAssembly;
+
+            // NetCore wins, existing assembly version vs app (0.0.0.1) and Uber (0.0.0.2)
+            var fixture = ConfigureAppAndFrameworks("0.0.0.1", "0.0.0.2", "7777.0.0", out appAssembly, out uberAssembly, out netcoreAssembly);
+            var dotnet = fixture.BuiltDotnet;
+            var appDll = fixture.TestProject.AppDll;
+
+            dotnet.Exec(appDll)
+                .WorkingDirectory(_currentWorkingDir)
+                .EnvironmentVariable("COREHOST_TRACE", "1")
+                .CaptureStdOut()
+                .CaptureStdErr()
+                .Execute()
+                .Should()
+                .Pass()
+                .And
+                // Verify final selection in TRUSTED_PLATFORM_ASSEMBLIES
+                .HaveStdErrContaining($"{netcoreAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{appAssembly}{Path.PathSeparator}")
+                .And
+                .NotHaveStdErrContaining($"{uberAssembly}{Path.PathSeparator}");
+        }
+
+        private TestProjectFixture ConfigureAppAndFrameworks(string appAssemblyVersion, string uberFxAssemblyVersion, string uberFxProductVersion, out string appAssembly, out string uberAssembly, out string netcoreAssembly)
+        {
+            const string fileVersion = "0.0.0.9";
+            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
+                .Copy();
+
+            if (!string.IsNullOrEmpty(uberFxAssemblyVersion))
+            {
+                // Modify Uber Fx's deps.json
+                SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, uberFxAssemblyVersion, fileVersion);
+            }
+
+            // Set desired version = 7777.0.0
+            string runtimeConfig = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.runtimeconfig.json");
+            SharedFramework.SetRuntimeConfigJson(runtimeConfig, "7777.0.0", null, useUberFramework: true);
+
+            // Add versions in the exe folder
+            SharedFramework.AddAvailableSharedFxVersions(_builtSharedFxDir, _exeSharedFxBaseDir, "9999.0.0");
+            SharedFramework.AddAvailableSharedUberFxVersions(_builtSharedUberFxDir, _exeSharedUberFxBaseDir, "9999.0.0", null, uberFxProductVersion);
+
+            // Copy NetCoreApp's copy of the assembly to the app location
+            netcoreAssembly = Path.Combine(_exeSharedFxBaseDir, "9999.0.0", "System.Collections.Immutable.dll");
+            appAssembly = Path.Combine(fixture.TestProject.OutputDirectory, "System.Collections.Immutable.dll");
+            File.Copy(netcoreAssembly, appAssembly);
+
+            // Modify the app's deps.json to add System.Collections.Immmutable
+            string appDepsJson = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.deps.json");
+            JObject versionInfo = new JObject();
+            versionInfo.Add(new JProperty("assemblyVersion", appAssemblyVersion));
+            versionInfo.Add(new JProperty("fileVersion", fileVersion));
+            SharedFramework.AddReferenceToDepsJson(appDepsJson, "SharedFxLookupPortableApp/1.0.0", "System.Collections.Immutable", "1.0.0", versionInfo);
+
+            uberAssembly = Path.Combine(_exeSharedUberFxBaseDir, uberFxProductVersion, "System.Collections.Immutable.dll");
+
+            return fixture;
+        }
+    }
+}
index e58c9b8..9fe33c2 100644 (file)
@@ -7,11 +7,8 @@ using Xunit;
 
 namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLookup
 {
-    public class GivenThatICareAboutMultilevelSharedFxLookup : IDisposable
+    public partial class GivenThatICareAboutMultilevelSharedFxLookup : IDisposable
     {
-        private const string SystemCollectionsImmutableFileVersion = "88.2.3.4";
-        private const string SystemCollectionsImmutableAssemblyVersion = "88.0.1.2";
-
         private RepoDirectoriesProvider RepoDirectories;
         private TestProjectFixture PreviouslyBuiltAndRestoredPortableTestProjectFixture;
 
@@ -103,11 +100,9 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
             _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);
-
-            _hostPolicyDllName = Path.GetFileName(fixture.TestProject.HostPolicyDll);
 
             // Trace messages used to identify from which folder the framework was picked
+            _hostPolicyDllName = Path.GetFileName(fixture.TestProject.HostPolicyDll);
             _cwdSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_cwdSharedFxBaseDir}";
             _userSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_userSharedFxBaseDir}";
             _exeSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_exeSharedFxBaseDir}";
@@ -899,119 +894,6 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku
                 .HaveStdErrContaining("It was not possible to find any compatible framework version");
         }
 
-        [Fact]
-        public void SharedFx_Wins_Against_App_On_RollForward_And_Version_Tie()
-        {
-            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
-                .Copy();
-
-            var dotnet = fixture.BuiltDotnet;
-            var appDll = fixture.TestProject.AppDll;
-
-            // Set desired version = 7777.0.0
-            string runtimeConfig = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.runtimeconfig.json");
-            SharedFramework.SetRuntimeConfigJson(runtimeConfig, "7777.0.0", null, useUberFramework: true);
-
-            // Add versions in the exe folder
-            SharedFramework.AddAvailableSharedFxVersions(_builtSharedFxDir, _exeSharedFxBaseDir, "9999.0.0");
-            SharedFramework.AddAvailableSharedUberFxVersions(_builtSharedUberFxDir, _exeSharedUberFxBaseDir, "9999.0.0", null, "7777.1.0");
-
-            // Copy NetCoreApp's copy of the assembly to the app location
-            string netcoreAssembly = Path.Combine(_exeSharedFxBaseDir, "9999.0.0", "System.Collections.Immutable.dll");
-            string appAssembly = Path.Combine(fixture.TestProject.OutputDirectory, "System.Collections.Immutable.dll");
-            File.Copy(netcoreAssembly, appAssembly);
-
-            // Modify the app's deps.json to add System.Collections.Immmutable
-            string appDepsJson = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.deps.json");
-            JObject versionInfo = new JObject();
-            versionInfo.Add(new JProperty("assemblyVersion", SystemCollectionsImmutableAssemblyVersion));
-            versionInfo.Add(new JProperty("fileVersion", SystemCollectionsImmutableFileVersion));
-            SharedFramework.AddReferenceToDepsJson(appDepsJson, "SharedFxLookupPortableApp/1.0.0", "System.Collections.Immutable", "1.0.0", versionInfo);
-
-            // Version: NetCoreApp 9999.0.0
-            //          UberFramework 7777.0.0
-            // Exe: NetCoreApp 9999.0.0
-            //      UberFramework 7777.1.0
-            // Expected: 9999.0.0
-            //           7777.1.0
-            // Expected: the framework's version of System.Collections.Immutable is used
-            string uberAssembly = Path.Combine(_exeSharedUberFxBaseDir, "7777.1.0", "System.Collections.Immutable.dll");
-            dotnet.Exec(appDll)
-                .WorkingDirectory(_currentWorkingDir)
-                .EnvironmentVariable("COREHOST_TRACE", "1")
-                .CaptureStdOut()
-                .CaptureStdErr()
-                .Execute()
-                .Should()
-                .Pass()
-                .And
-                .HaveStdErrContaining($"Replacing deps entry [{appAssembly}, AssemblyVersion:{SystemCollectionsImmutableAssemblyVersion}, FileVersion:{SystemCollectionsImmutableFileVersion}] with [{uberAssembly}, AssemblyVersion:{SystemCollectionsImmutableAssemblyVersion}, FileVersion:{SystemCollectionsImmutableFileVersion}]")
-                .And
-                // Verify final selection in TRUSTED_PLATFORM_ASSEMBLIES
-                .HaveStdErrContaining($"{uberAssembly}{Path.PathSeparator}")
-                .And
-                .NotHaveStdErrContaining($"{netcoreAssembly}{Path.PathSeparator}")
-                .And
-                .NotHaveStdErrContaining($"{appAssembly}{Path.PathSeparator}");
-        }
-
-        [Fact]
-        public void SharedFx_With_Higher_Version_Wins_Against_App_On_NoRollForward()
-        {
-            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
-                .Copy();
-
-            var dotnet = fixture.BuiltDotnet;
-            var appDll = fixture.TestProject.AppDll;
-
-            // Set desired version = 7777.0.0
-            string runtimeConfig = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.runtimeconfig.json");
-            SharedFramework.SetRuntimeConfigJson(runtimeConfig, "7777.0.0", null, useUberFramework: true);
-
-            // Add versions in the exe folder
-            SharedFramework.AddAvailableSharedFxVersions(_builtSharedFxDir, _exeSharedFxBaseDir, "9999.0.0");
-            SharedFramework.AddAvailableSharedUberFxVersions(_builtSharedUberFxDir, _exeSharedUberFxBaseDir, "9999.0.0", null, "7777.0.0");
-
-            // Copy NetCoreApp's copy of the assembly to the app location
-            string netcoreAssembly = Path.Combine(_exeSharedFxBaseDir, "9999.0.0", "System.Collections.Immutable.dll");
-            string appAssembly = Path.Combine(fixture.TestProject.OutputDirectory, "System.Collections.Immutable.dll");
-            File.Copy(netcoreAssembly, appAssembly);
-
-            // Modify the app's deps.json to add System.Collections.Immmutable
-            string appDepsJson = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.deps.json");
-            // Use lower numbers for the app
-            JObject versionInfo = new JObject();
-            versionInfo.Add(new JProperty("assemblyVersion", "0.0.0.1"));
-            versionInfo.Add(new JProperty("fileVersion", "0.0.0.2"));
-            SharedFramework.AddReferenceToDepsJson(appDepsJson, "SharedFxLookupPortableApp/1.0.0", "System.Collections.Immutable", "1.0.0", versionInfo);
-
-            // Version: NetCoreApp 9999.0.0
-            //          UberFramework 7777.0.0
-            // Exe: NetCoreApp 9999.0.0
-            //      UberFramework 7777.0.0
-            // Expected: 9999.0.0
-            //           7777.0.0
-            // Expected: the framework's version of System.Collections.Immutable is used
-            string uberAssembly = Path.Combine(_exeSharedUberFxBaseDir, "7777.0.0", "System.Collections.Immutable.dll");
-            dotnet.Exec(appDll)
-                .WorkingDirectory(_currentWorkingDir)
-                .EnvironmentVariable("COREHOST_TRACE", "1")
-                .CaptureStdOut()
-                .CaptureStdErr()
-                .Execute()
-                .Should()
-                .Pass()
-                .And
-                .HaveStdErrContaining($"Adding tpa entry: {uberAssembly}, AssemblyVersion: {SystemCollectionsImmutableAssemblyVersion}, FileVersion: {SystemCollectionsImmutableFileVersion}")
-                .And
-                // Verify final selection in TRUSTED_PLATFORM_ASSEMBLIES
-                .HaveStdErrContaining($"{uberAssembly}{Path.PathSeparator}")
-                .And
-                .NotHaveStdErrContaining($"{netcoreAssembly}{Path.PathSeparator}")
-                .And
-                .NotHaveStdErrContaining($"{appAssembly}{Path.PathSeparator}");
-        }
-
         static private JObject GetAdditionalFramework(string fxName, string fxVersion, bool? applyPatches, int? rollForwardOnNoCandidateFx)
         {
             var jobject = new JObject(new JProperty("name", fxName));