Skip to content

Commit

Permalink
Add a sample testing framework-dependent deployment.
Browse files Browse the repository at this point in the history
Closes #12.
  • Loading branch information
alexrp committed Jul 6, 2022
1 parent aaa5aa0 commit adc65b4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/samples/dependent/InjectedProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
sealed class InjectedProgram : IInjectedProgram
{
static readonly TimeSpan _timeout = TimeSpan.FromMinutes(1);

public static async Task<int> RunAsync(InjectedProgramContext context, ReadOnlyMemory<string> args)
{
if (context.InjectorProcessId != null)
return 42;

Console.WriteLine("Starting conhost.exe...");

using var proc = new Process()
{
StartInfo = new()
{
FileName = "conhost.exe",
},
};

_ = proc.Start();

try
{
if (!proc.WaitForInputIdle(_timeout))
throw new TimeoutException();

Console.WriteLine("Started as {0}. Injecting...", proc.Id);

using var target = TargetProcess.Open(proc.Id);
using var injector = new AssemblyInjector(
target,
new AssemblyInjectorOptions(typeof(InjectedProgram).Assembly.Location)
.WithInjectionTimeout(_timeout)
.WithCompletionTimeout(_timeout));

await injector.InjectAssemblyAsync();

Console.WriteLine("Injected.");

var code = await injector.WaitForCompletionAsync();

Console.WriteLine("Returned code {0}.", code);

return code == 42 ? 0 : 1;
}
finally
{
proc.Kill(true);

await proc.WaitForExitAsync();
}
}
}
5 changes: 5 additions & 0 deletions src/samples/dependent/dependent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>

0 comments on commit adc65b4

Please sign in to comment.