更新
更旧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Internal;
using Xunit.Abstractions;
namespace InteropTests.Helpers
{
public class ClientProcess : IDisposable
{
private readonly Process _process;
private readonly ProcessEx _processEx;
private readonly TaskCompletionSource<object> _startTcs;
public ClientProcess(ITestOutputHelper output, string path, string serverPort, string testCase)
{
_process = new Process();
_process.StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
RedirectStandardError = true,
FileName = "dotnet",
Arguments = @$"{path} --use_tls false --server_port {serverPort} --client_type httpclient --test_case {testCase}"
};
_process.EnableRaisingEvents = true;
_process.OutputDataReceived += Process_OutputDataReceived;
_process.Start();
_processEx = new ProcessEx(output, _process);
_startTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
}
public Task WaitForReady()
{
return _startTcs.Task;
}
public int ExitCode => _process.ExitCode;
public Task Exited => _processEx.Exited;
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
var data = e.Data;
if (data != null)
{
if (data.Contains("Application started."))
{
_startTcs.TrySetResult(null);
}
}
}
public void Dispose()
{
_processEx.Dispose();
}
}
}