public async Task TestWriteHost() { using (var client = new PSClient()) { await client.OpenAsync(PSConnectionInfo.CreateLocalConnection()); string v = string.Empty; client.HostUI.WriteCallback = (s, fg, bg, c) => { if (s == PSOutputStream.Default) { v += c; } }; await client.InvokeScriptAsync("Write-Host \"Hello World\";"); Assert.AreEqual("Hello World", v.Trim()); Assert.IsTrue(v.EndsWith("\n")); // Also test multi-close await client.CloseAsync(); await client.CloseAsync(); await client.CloseAsync(); } }