private static async Task PublishAppAsync(string path, string outputPath) { var resolvedPath = Path.GetFullPath(path); Console.WriteLine($"Publishing {resolvedPath}"); var process = new DotNetProcess(); try { process.Start($"publish {resolvedPath} -r {GetRuntimeIdentifier()} -c Release -o {outputPath} --self-contained"); await process.WaitForExitAsync().TimeoutAfter(Timeout); } catch (Exception ex) { throw new Exception("Error while publishing app.", ex); } finally { var exitCode = process.HasExited ? (int?)process.ExitCode : null; process.Dispose(); var output = process.GetOutput(); Console.WriteLine("Publish output:"); Console.WriteLine(output); if (exitCode != null && exitCode.Value != 0) { throw new Exception($"Non-zero exit code returned: {exitCode}"); } } }
public async Task RunWebsiteAndCallWithClient_Success() { var projectDirectory = typeof(LinkerTests).Assembly .GetCustomAttributes <AssemblyMetadataAttribute>() .Single(a => a.Key == "ProjectDirectory") .Value; var tempPath = Path.GetTempPath(); var linkerTestsClientPath = Path.Combine(tempPath, "LinkerTestsClient"); var linkerTestsWebsitePath = Path.Combine(tempPath, "LinkerTestsWebsite"); EnsureDeleted(linkerTestsClientPath); EnsureDeleted(linkerTestsWebsitePath); try { using var websiteProcess = new WebsiteProcess(); using var clientProcess = new DotNetProcess(); try { var publishWebsiteTask = PublishAppAsync(projectDirectory + @"\..\..\testassets\LinkerTestsWebsite\LinkerTestsWebsite.csproj", linkerTestsWebsitePath); var publishClientTask = PublishAppAsync(projectDirectory + @"\..\..\testassets\LinkerTestsClient\LinkerTestsClient.csproj", linkerTestsClientPath); await Task.WhenAll(publishWebsiteTask, publishClientTask).TimeoutAfter(Timeout); websiteProcess.Start(Path.Combine(linkerTestsWebsitePath, "LinkerTestsWebsite.dll")); await websiteProcess.WaitForReadyAsync().TimeoutAfter(Timeout); clientProcess.Start(Path.Combine(linkerTestsClientPath, $"LinkerTestsClient.dll {websiteProcess.ServerPort}")); await clientProcess.WaitForExitAsync().TimeoutAfter(Timeout); Assert.AreEqual(0, clientProcess.ExitCode); } finally { Console.WriteLine("Website output:"); Console.WriteLine(websiteProcess.GetOutput()); Console.WriteLine("Client output:"); Console.WriteLine(clientProcess.GetOutput()); } } finally { EnsureDeleted(linkerTestsClientPath); EnsureDeleted(linkerTestsWebsitePath); } }