public async Task WriteAsync_ThrowsOnInvalidMessage_Async() { await using MemoryStream stream = new MemoryStream(); await using var protocol = new AdbProtocol(stream, ownsStream: true, NullLogger <AdbProtocol> .Instance); await Assert.ThrowsAsync <ArgumentNullException>(async() => await protocol.WriteAsync(string.Empty, default).ConfigureAwait(false)); await Assert.ThrowsAsync <ArgumentNullException>(async() => await protocol.WriteAsync((string)null, default).ConfigureAwait(false));
public async Task WriteAsync_SendData_Async(string input, string output) { await using MemoryStream stream = new MemoryStream(); await using var protocol = new AdbProtocol(stream, ownsStream: true, NullLogger <AdbProtocol> .Instance); await protocol.WriteAsync(input, default).ConfigureAwait(false); stream.Position = 0; using var reader = new StreamReader(stream); Assert.Equal(output, await reader.ReadToEndAsync().ConfigureAwait(false)); }
public async Task DisposeAsync_DisposesStreamIfNeeded_Async(bool ownsStream) { var stream = new Mock <Stream>(MockBehavior.Strict); if (ownsStream) { stream.Setup(s => s.DisposeAsync()).Returns(ValueTask.CompletedTask).Verifiable(); } var protocol = new AdbProtocol(stream.Object, ownsStream, NullLogger <AdbProtocol> .Instance); await protocol.DisposeAsync(); stream.Verify(); }
public async Task GetShellStream_ReturnsShellStreamAsync() { using (var stream = new MemoryStream(new byte[] { 1, 2, 3 })) await using (var protocol = new AdbProtocol(stream, false, NullLogger <AdbProtocol> .Instance)) using (var shellStream = protocol.GetShellStream()) { var bytes = new byte[3]; await shellStream.ReadAsync(bytes).ConfigureAwait(false); Assert.Equal(new byte[] { 1, 2, 3 }, bytes); } Assert.True(true); }
public async Task WriteAsync_SendDataStream_Async() { await using MemoryStream inputStream = new MemoryStream(); using var writer = new StreamWriter(inputStream); await writer.WriteAsync("Tester").ConfigureAwait(false); await writer.FlushAsync().ConfigureAwait(false); inputStream.Position = 0; await using MemoryStream stream = new MemoryStream(); await using var protocol = new AdbProtocol(stream, ownsStream: true, NullLogger <AdbProtocol> .Instance); await protocol.WriteAsync(inputStream, default).ConfigureAwait(false); stream.Position = 0; using var reader = new StreamReader(stream); Assert.Equal("Tester", await reader.ReadToEndAsync().ConfigureAwait(false)); }
public async Task WriteSyncDataAsync_ValidatesArguments_Async() { await using MemoryStream stream = new MemoryStream(); await using var protocol = new AdbProtocol(stream, ownsStream: true, NullLogger <AdbProtocol> .Instance); await Assert.ThrowsAsync <ArgumentNullException>(async() => await protocol.WriteSyncDataAsync((Stream)null, default).ConfigureAwait(false));