Пример #1
0
        public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegisteredLocation)
        {
            var fixture = sharedTestState.PortableAppFixture_Published
                          .Copy();

            // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
            // by creating the executable from apphost.exe
            var appExe = fixture.TestProject.AppExe;

            File.Copy(sharedTestState.BuiltAppHost, appExe, overwrite: true);
            AppHostExtensions.BindAppHost(appExe);

            // Get the framework location that was built
            string builtDotnet = fixture.BuiltDotnet.BinPath;

            using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe))
            {
                string architecture = fixture.CurrentRid.Split('-')[1];
                if (useRegisteredLocation)
                {
                    registeredInstallLocationOverride.SetInstallLocation(builtDotnet, architecture);
                }

                // Verify running with the default working directory
                Command.Create(appExe)
                .CaptureStdErr()
                .CaptureStdOut()
                .MultilevelLookup(false)
                .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
                .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
                .DotNetRoot(null)
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion);

                // Verify running from within the working directory
                Command.Create(appExe)
                .CaptureStdErr()
                .CaptureStdOut()
                .MultilevelLookup(false)
                .WorkingDirectory(fixture.TestProject.OutputDirectory)
                .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
                .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
                .DotNetRoot(null)
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion);
            }
        }
Пример #2
0
        public void SdkMultilevelLookup_RegistryAccess()
        {
            // The purpose of this test is to verify that the product uses correct code to access
            // the registry to extract the path to search for SDKs.
            // Most of our tests rely on a shortcut which is to set _DOTNET_TEST_SDK_SELF_REGISTERED_DIR env variable
            // which will skip the registry reading code in the product and simply use the specified value.
            // This test is different since it actually runs the registry reading code.
            // Normally the reg key the product uses is in HKEY_LOCAL_MACHINE which is only writable as admin
            // so we would require the tests to run as admin to modify that key (and it may introduce races with other code running on the machine).
            // So instead the tests use _DOTENT_TEST_SDK_REGISTRY_PATH env variable to point to the produce to use
            // different registry key, inside the HKEY_CURRENT_USER hive which is writable without admin.
            // Note that the test creates a unique key (based on PID) for every run, to avoid collisions between parallel running tests.

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Multi-level lookup is only supported on Windows.
                return;
            }

            WriteEmptyGlobalJson();

            using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(DotNet.GreatestVersionHostFxrFilePath))
            {
                registeredInstallLocationOverride.SetInstallLocation(_regDir, RepoDirectories.BuildArchitecture);

                // Add SDK versions
                AddAvailableSdkVersions(_regSdkBaseDir, "9999.0.4");

                // Specified SDK version: none
                // Cwd: empty
                // User: empty
                // Exe: empty
                // Reg: 9999.0.4
                // Expected: 9999.0.4 from reg dir
                DotNet.Exec("help")
                .WorkingDirectory(_currentWorkingDir)
                .WithUserProfile(_userDir)
                .Environment(s_DefaultEnvironment)
                .EnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "1")
                .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
                .CaptureStdOut()
                .CaptureStdErr()
                .Execute()
                .Should().Pass()
                .And.HaveStdErrContaining(Path.Combine(_regSelectedMessage, "9999.0.4", _dotnetSdkDllMessageTerminator));
            }
        }
Пример #3
0
        [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows.
        public void SdkMultilevelLookup_RegistryAccess()
        {
            // The purpose of this test is to verify that the product uses correct code to access
            // the registry to extract the path to search for SDKs.
            // Most of our tests rely on a shortcut which is to set _DOTNET_TEST_GLOBALLY_REGISTERED_PATH env variable
            // which will skip the registry reading code in the product and simply use the specified value.
            // This test is different since it actually runs the registry reading code.
            // Normally the reg key the product uses is in HKEY_LOCAL_MACHINE which is only writable as admin
            // so we would require the tests to run as admin to modify that key (and it may introduce races with other code running on the machine).
            // So instead the tests use _DOTENT_TEST_REGISTRY_PATH env variable to point to the produce to use
            // different registry key, inside the HKEY_CURRENT_USER hive which is writable without admin.
            // Note that the test creates a unique key (based on PID) for every run, to avoid collisions between parallel running tests.

            WriteEmptyGlobalJson();

            using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(DotNet.GreatestVersionHostFxrFilePath))
            {
                registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] { (RepoDirectories.BuildArchitecture, _regDir) });
Пример #4
0
        public void AppHost_FrameworkDependent_GlobalLocation_Succeeds(bool useRegisteredLocation)
        {
            var fixture = sharedTestState.PortableAppFixture_Published
                          .Copy();

            // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
            // by creating the executable from apphost.exe
            var appExe = fixture.TestProject.AppExe;

            File.Copy(sharedTestState.BuiltAppHost, appExe, overwrite: true);
            AppHostExtensions.BindAppHost(appExe);

            // Get the framework location that was built
            string builtDotnet = fixture.BuiltDotnet.BinPath;

            using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe))
            {
                string architecture = fixture.RepoDirProvider.BuildArchitecture;
                if (useRegisteredLocation)
                {
                    registeredInstallLocationOverride.SetInstallLocation(new (string, string)[] { (architecture, builtDotnet) });
Пример #5
0
        public static Command ApplyRegisteredInstallLocationOverride(
            this Command command,
            RegisteredInstallLocationOverride registeredInstallLocationOverride)
        {
            if (registeredInstallLocationOverride == null)
            {
                return(command);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(command.EnvironmentVariable(
                           Constants.TestOnlyEnvironmentVariables.RegistryPath,
                           registeredInstallLocationOverride.PathValueOverride));
            }
            else
            {
                return(command.EnvironmentVariable(
                           Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
                           registeredInstallLocationOverride.PathValueOverride));
            }
        }
        public static Command ApplyRegisteredInstallLocationOverride(
            this Command command,
            RegisteredInstallLocationOverride registeredInstallLocationOverride)
        {
            if (registeredInstallLocationOverride == null)
            {
                return(command);
            }

            if (OperatingSystem.IsWindows())
            {
                return(command.EnvironmentVariable(
                           Constants.TestOnlyEnvironmentVariables.RegistryPath,
                           registeredInstallLocationOverride.PathValueOverride));
            }
            else
            {
                return(command.EnvironmentVariable(
                           Constants.TestOnlyEnvironmentVariables.InstallLocationFilePath,
                           registeredInstallLocationOverride.PathValueOverride));
            }
        }
Пример #7
0
        public void Framework_Dependent_AppHost_From_Global_Location_Succeeds(bool useRegisteredLocation)
        {
            var fixture = sharedTestState.PortableAppFixture_Published
                          .Copy();

            // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior
            // by creating the executable from apphost.exe
            var appExe     = fixture.TestProject.AppExe;
            var appDllName = Path.GetFileName(fixture.TestProject.AppDll);

            string hostExeName   = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost");
            string builtAppHost  = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName);
            string appDir        = Path.GetDirectoryName(appExe);
            string appDirHostExe = Path.Combine(appDir, hostExeName);

            // Make a copy of apphost first, replace hash and overwrite app.exe, rather than
            // overwrite app.exe and edit in place, because the file is opened as "write" for
            // the replacement -- the test fails with ETXTBSY (exit code: 26) in Linux when
            // executing a file opened in "write" mode.
            File.Copy(builtAppHost, appDirHostExe, true);
            using (var sha256 = SHA256.Create())
            {
                // Replace the hash with the managed DLL name.
                var hash    = sha256.ComputeHash(Encoding.UTF8.GetBytes("foobar"));
                var hashStr = BitConverter.ToString(hash).Replace("-", "").ToLower();
                BinaryUtils.SearchAndReplace(appDirHostExe, Encoding.UTF8.GetBytes(hashStr), Encoding.UTF8.GetBytes(appDllName));
            }
            File.Copy(appDirHostExe, appExe, true);

            // Get the framework location that was built
            string builtDotnet = fixture.BuiltDotnet.BinPath;

            using (var registeredInstallLocationOverride = new RegisteredInstallLocationOverride(appExe))
            {
                string architecture = fixture.CurrentRid.Split('-')[1];
                if (useRegisteredLocation)
                {
                    registeredInstallLocationOverride.SetInstallLocation(builtDotnet, architecture);
                }

                // Verify running with the default working directory
                Command.Create(appExe)
                .CaptureStdErr()
                .CaptureStdOut()
                .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
                .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");

                // Verify running from within the working directory
                Command.Create(appExe)
                .CaptureStdErr()
                .CaptureStdOut()
                .WorkingDirectory(fixture.TestProject.OutputDirectory)
                .ApplyRegisteredInstallLocationOverride(registeredInstallLocationOverride)
                .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.DefaultInstallPath, useRegisteredLocation ? null : builtDotnet)
                .Execute()
                .Should().Pass()
                .And.HaveStdOutContaining("Hello World")
                .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}");
            }
        }