public void InteractiveAadLogon_Canceled() { const string protocol = "https"; const string host = "microsoft-git-tools.visualstudio.com"; InitializeTest(); var errorBuffer = new byte[4096]; var outputBuffer = new byte[4096]; var program = new Program(Context); using (var inputStream = new MemoryStream()) using (var outputStream = new MemoryStream(outputBuffer)) using (var errorStream = new MemoryStream(errorBuffer)) using (var writer = new StreamWriter(inputStream, Utf8)) { SetupProgramStandardPipes(program, inputStream, outputStream, errorStream); MimicGitCredential(writer, protocol, host); inputStream.Seek(0, SeekOrigin.Begin); program._exit = (Program p, int exitcode, string message, string path, int line, string name) => { Assert.Same(program, p); Assert.Equal(-1, exitcode); Assert.Equal(Program.LogonFailedMessage, message, Ordinal); Assert.Equal(nameof(Program.Get), name, Ordinal); ConsoleFunctions.Exit(program, exitcode, message, path, line, name); throw new ApplicationException(message); }; // We know this will throw. Assert.Throws <AggregateException>(() => { try { program.Get(); } catch (AggregateException exception) { Assert.NotNull(exception.InnerException); Trace.WriteException(exception); Assert.IsType <ApplicationException>(exception.InnerException); Assert.Equal(Program.LogonFailedMessage, exception.InnerException.Message, Ordinal); throw exception; } }); } // Assert nothing gets written to the output stream. using (var stream = new MemoryStream(outputBuffer)) using (var reader = new StreamReader(stream, Encoding.Unicode)) { string content = reader.ReadToEnd(); Assert.NotNull(content); Assert.NotEmpty(content); Assert.Equal('\0', content[0]); } // Assert the correct error message gets written to the error stream. using (var stream = new MemoryStream(errorBuffer)) using (var reader = new StreamReader(stream, Encoding.Unicode)) { string content = reader.ReadToEnd(); Assert.StartsWith(Program.LogonFailedMessage, content, StringComparison.Ordinal); } }