Skip to content

Commit adc65b4

Browse files
committed
Add a sample testing framework-dependent deployment.
Closes #12.
1 parent aaa5aa0 commit adc65b4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
sealed class InjectedProgram : IInjectedProgram
2+
{
3+
static readonly TimeSpan _timeout = TimeSpan.FromMinutes(1);
4+
5+
public static async Task<int> RunAsync(InjectedProgramContext context, ReadOnlyMemory<string> args)
6+
{
7+
if (context.InjectorProcessId != null)
8+
return 42;
9+
10+
Console.WriteLine("Starting conhost.exe...");
11+
12+
using var proc = new Process()
13+
{
14+
StartInfo = new()
15+
{
16+
FileName = "conhost.exe",
17+
},
18+
};
19+
20+
_ = proc.Start();
21+
22+
try
23+
{
24+
if (!proc.WaitForInputIdle(_timeout))
25+
throw new TimeoutException();
26+
27+
Console.WriteLine("Started as {0}. Injecting...", proc.Id);
28+
29+
using var target = TargetProcess.Open(proc.Id);
30+
using var injector = new AssemblyInjector(
31+
target,
32+
new AssemblyInjectorOptions(typeof(InjectedProgram).Assembly.Location)
33+
.WithInjectionTimeout(_timeout)
34+
.WithCompletionTimeout(_timeout));
35+
36+
await injector.InjectAssemblyAsync();
37+
38+
Console.WriteLine("Injected.");
39+
40+
var code = await injector.WaitForCompletionAsync();
41+
42+
Console.WriteLine("Returned code {0}.", code);
43+
44+
return code == 42 ? 0 : 1;
45+
}
46+
finally
47+
{
48+
proc.Kill(true);
49+
50+
await proc.WaitForExitAsync();
51+
}
52+
}
53+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<SelfContained>false</SelfContained>
4+
</PropertyGroup>
5+
</Project>

0 commit comments

Comments
 (0)