Exemple #1
0
        public void Running_Publish_Output_Standalone_EXE_with_Unbound_AppHost_Fails()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            string hostExeName  = $"apphost{Constants.ExeSuffix}";
            string builtAppHost = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);

            File.Copy(builtAppHost, appExe, true);

            int exitCode = Command.Create(appExe)
                           .CaptureStdErr()
                           .CaptureStdOut()
                           .Execute(fExpectedToFail: true)
                           .ExitCode;

            if (CurrentPlatform.IsWindows)
            {
                exitCode.Should().Be(-2147450731);
            }
            else
            {
                // Some Unix flavors filter exit code to ubyte.
                (exitCode & 0xFF).Should().Be(0x95);
            }
        }
        public void Running_Publish_Output_Standalone_EXE_By_Renaming_dotnet_exe_Fails()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            string hostExeName = $"dotnet{Constants.ExeSuffix}";
            string builtHost   = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);

            File.Copy(builtHost, appExe, true);

            int exitCode = Command.Create(appExe)
                           .CaptureStdErr()
                           .CaptureStdOut()
                           .Execute(fExpectedToFail: true)
                           .ExitCode;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                exitCode.Should().Be(-2147450748);
            }
            else
            {
                // Some Unix flavors filter exit code to ubyte.
                (exitCode & 0xFF).Should().Be(0x84);
            }
        }
Exemple #3
0
        public void Running_Publish_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
Exemple #4
0
        public void Running_Publish_Output_Standalone_EXE_With_DOTNET_ROOT_Fails()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;
            var appDll = fixture.TestProject.AppDll;

            // Move whole directory to a subdirectory
            string currentOutDir   = fixture.TestProject.OutputDirectory;
            string relativeNewPath = "..";

            relativeNewPath = Path.Combine(relativeNewPath, "newDir2");
            string newOutDir = Path.Combine(currentOutDir, relativeNewPath);

            Directory.Move(currentOutDir, newOutDir);

            // Move the apphost exe and app dll back to original location
            string appExeName       = Path.GetFileName(appExe);
            string sourceAppExePath = Path.Combine(newOutDir, appExeName);

            Directory.CreateDirectory(Path.GetDirectoryName(appExe));
            File.Move(sourceAppExePath, appExe);

            string appDllName       = Path.GetFileName(appDll);
            string sourceAppDllPath = Path.Combine(newOutDir, appDllName);

            File.Move(sourceAppDllPath, appDll);

            // This verifies a self-contained apphost cannot use DOTNET_ROOT to reference a flat
            // self-contained layout since a flat layout of the shared framework is not supported.
            Command.Create(appExe)
            .EnvironmentVariable("COREHOST_TRACE", "1")
            .EnvironmentVariable("DOTNET_ROOT", newOutDir)
            .EnvironmentVariable("DOTNET_ROOT(x86)", newOutDir)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute(fExpectedToFail: true)
            .Should()
            .Fail()
            .And
            .HaveStdErrContaining($"Using environment variable DOTNET_ROOT")                // use the first part avoiding "(x86)" if present
            .And
            .HaveStdErrContaining($"=[{Path.GetFullPath(newOutDir)}] as runtime location.") // use the last part
            .And
            .HaveStdErrContaining("A fatal error occurred");
        }
        public void Running_Publish_Output_Standalone_EXE_By_Renaming_apphost_exe_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe        = fixture.TestProject.AppExe;
            var renamedAppExe = fixture.TestProject.AppExe + $"renamed{Constants.ExeSuffix}";

            File.Copy(appExe, renamedAppExe, true);

            Command.Create(renamedAppExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
Exemple #6
0
        public void Running_Publish_Output_Standalone_EXE_With_Relative_Embedded_Path_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            // Move whole directory to a subdirectory
            string currentOutDir   = fixture.TestProject.OutputDirectory;
            string relativeNewPath = "..";

            relativeNewPath = Path.Combine(relativeNewPath, "newDir");
            string newOutDir = Path.Combine(currentOutDir, relativeNewPath);

            Directory.Move(currentOutDir, newOutDir);

            // Move the apphost exe back to original location
            string appExeName       = Path.GetFileName(appExe);
            string sourceAppExePath = Path.Combine(newOutDir, appExeName);

            Directory.CreateDirectory(Path.GetDirectoryName(appExe));
            File.Move(sourceAppExePath, appExe);

            // Modify the apphost to include relative path
            string appDll          = fixture.TestProject.AppDll;
            string appDllName      = Path.GetFileName(appDll);
            string relativeDllPath = Path.Combine(relativeNewPath, appDllName);

            AppHostExtensions.SearchAndReplace(appExe, Encoding.UTF8.GetBytes(appDllName), Encoding.UTF8.GetBytes(relativeDllPath), true);

            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
        public void Running_Publish_Output_Standalone_EXE_With_Startupconfig_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            // Move whole directory to a subdirectory
            string currentOutDir   = fixture.TestProject.OutputDirectory;
            string relativeNewPath = "..";

            relativeNewPath = Path.Combine(relativeNewPath, "newDir");
            string newOutDir = Path.Combine(currentOutDir, relativeNewPath);

            Directory.Move(currentOutDir, newOutDir);

            // Move the apphost exe back to original location
            string appExeName       = Path.GetFileName(appExe);
            string sourceAppExePath = Path.Combine(newOutDir, appExeName);

            Directory.CreateDirectory(Path.GetDirectoryName(appExe));
            File.Move(sourceAppExePath, appExe);

            // Create the startupConfig.json
            string startupConfigFileName = Path.GetFileNameWithoutExtension(appExe) + ".startupconfig.json";
            string startupConfigPath     = Path.Combine(currentOutDir, startupConfigFileName);

            SetStartupConfigJson(startupConfigPath, relativeNewPath);

            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
        public void Running_Publish_Output_Standalone_EXE_with_DepsJson_and_RuntimeConfig_Local_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            // TODO: Use FS.Chmod when build utility project is converted to csproj.
            // See https://github.com/NuGet/Home/issues/4424
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Command.Create("chmod", "u+x", appExe).Execute().EnsureSuccessful();
            }

            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
Exemple #9
0
        public void Running_Publish_Output_Standalone_EXE_with_Bound_AppHost_Succeeds()
        {
            var fixture = PreviouslyPublishedAndRestoredStandaloneTestProjectFixture
                          .Copy();

            var appExe = fixture.TestProject.AppExe;

            string hostExeName   = $"apphost{Constants.ExeSuffix}";
            string builtAppHost  = Path.Combine(RepoDirectories.HostArtifacts, hostExeName);
            string appName       = Path.GetFileNameWithoutExtension(appExe);
            string appDll        = $"{appName}.dll";
            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();
                AppHostExtensions.SearchAndReplace(appDirHostExe, Encoding.UTF8.GetBytes(hashStr), Encoding.UTF8.GetBytes(appDll), true);
            }
            File.Copy(appDirHostExe, appExe, true);

            Command.Create(appExe)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");
        }
 public void Dispose()
 {
     PreviouslyBuiltAndRestoredStandaloneTestProjectFixture.Dispose();
     PreviouslyPublishedAndRestoredStandaloneTestProjectFixture.Dispose();
 }