Exemplo n.º 1
0
        public async Task <string> CallMethod(string callMethodInfo)
        {
            _ewh.Set();
            var buffer = callMethodInfo.GetBytes();             //Encoding.UTF8.GetBytes(callMethodInfo);

#if NETCOREAPP
            await _pipeWrite.WriteAsync(BitConverter.GetBytes(buffer.Length).AsMemory(0, sizeof(int)), _cancellationToken);

            await _pipeWrite.WriteAsync(buffer.AsMemory(0, buffer.Length), _cancellationToken);
#else
            await _pipeWrite.WriteAsync(BitConverter.GetBytes(buffer.Length), 0, sizeof(int), _cancellationToken);

            await _pipeWrite.WriteAsync(buffer, 0, buffer.Length, _cancellationToken);
#endif

            buffer = await GetByteArrayFromStreamAsync(_pipeRead, sizeof(int));

            int streamSize = BitConverter.ToInt32(buffer, 0);
            if (streamSize == 0)
            {
                return(null);
            }

            buffer = await GetByteArrayFromStreamAsync(_pipeRead, streamSize);

            return(buffer.GetString());            //Encoding.UTF8.GetString(buffer);
        }
Exemplo n.º 2
0
        async public Task TestAsyncOutputStream_CancelOutputRead()
        {
            // This test might have some false negatives due to possible race condition in System.Diagnostics.AsyncStreamReader.ReadBufferAsync
            // There is not way to know if parent process has processed async output from child process

            using (AnonymousPipeServerStream pipeWrite = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                using (AnonymousPipeServerStream pipeRead = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
                {
                    using (Process p = CreateProcess(TestAsyncOutputStream_CancelOutputRead_RemotelyInvokable, $"{pipeWrite.GetClientHandleAsString()} {pipeRead.GetClientHandleAsString()}"))
                    {
                        var dataReceived     = new List <int>();
                        var dataArrivedEvent = new AutoResetEvent(false);

                        p.StartInfo.RedirectStandardOutput = true;
                        p.OutputDataReceived += (s, e) =>
                        {
                            if (e.Data != null)
                            {
                                dataReceived.Add(int.Parse(e.Data));
                            }
                            dataArrivedEvent.Set();
                        };

                        // Start child process
                        p.Start();

                        pipeWrite.DisposeLocalCopyOfClientHandle();
                        pipeRead.DisposeLocalCopyOfClientHandle();

                        // Wait child process start
                        Assert.True(await WaitPipeSignal(pipeRead, WaitInMS), "Child process not started");

                        //Start listening and produce output 1
                        p.BeginOutputReadLine();
                        await pipeWrite.WriteAsync(new byte[1], 0, 1);

                        // Wait child signal produce number 1
                        Assert.True(await WaitPipeSignal(pipeRead, WaitInMS), "Missing child signal for value 1");
                        Assert.True(dataArrivedEvent.WaitOne(WaitInMS), "Value 1 not received");

                        // Stop listening and signal to produce value 2
                        p.CancelOutputRead();
                        await pipeWrite.WriteAsync(new byte[1], 0, 1);

                        // Wait child signal produce number 2
                        Assert.True(await WaitPipeSignal(pipeRead, WaitInMS), "Missing child signal for value 2");

                        // Wait child process close to be sure that output buffer has been flushed
                        Assert.True(p.WaitForExit(WaitInMS), "Child process didn't close");
                        p.WaitForExit(); // wait for event handlers to complete

                        Assert.Equal(1, dataReceived.Count);
                        Assert.Equal(1, dataReceived[0]);
                    }
                }
        }
Exemplo n.º 3
0
        public async static void ServerWriteAsyncNegativeOffsetThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => server.WriteAsync(new byte[5], -1, 1));

                // array is checked first
                await Assert.ThrowsAsync <ArgumentNullException>(() => server.WriteAsync(null, -1, 1));
            }
        }
Exemplo n.º 4
0
        public async Task AnonymousPipeViaFileStream_AllDataCopied(int writeSize, int numWrites)
        {
            long totalLength  = writeSize * numWrites;
            var  expectedData = new byte[totalLength];

            new Random(42).NextBytes(expectedData);

            var results = new MemoryStream();

            using (var server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Task serverTask = Task.Run(async() =>
                {
                    for (int i = 0; i < numWrites; i++)
                    {
                        await server.WriteAsync(expectedData, i * writeSize, writeSize);
                    }
                });

                using (var client = new FileStream(new SafeFileHandle(server.ClientSafePipeHandle.DangerousGetHandle(), false), FileAccess.Read, bufferSize: 3))
                {
                    Task copyTask = client.CopyToAsync(results, writeSize);
                    await await Task.WhenAny(serverTask, copyTask);

                    server.Dispose();
                    await copyTask;
                }
            }

            byte[] actualData = results.ToArray();
            Assert.Equal(expectedData.Length, actualData.Length);
            Assert.Equal <byte>(expectedData, actualData);
        }
Exemplo n.º 5
0
 public async static void ServerWriteAsyncBufferNullThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
     {
         await Assert.ThrowsAsync <ArgumentNullException>(() => server.WriteAsync(null, 0, 1));
     }
 }
Exemplo n.º 6
0
 public async static void ServerReadOnlyAsyncThrows()
 {
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
     {
         await Assert.ThrowsAsync <NotSupportedException>(() => server.WriteAsync(new byte[5], 0, 5));
     }
 }
Exemplo n.º 7
0
 public static void ServerWriteBufferNullThrows()
 {
     // force different constructor path
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None))
     {
         Assert.Throws<ArgumentNullException>(() => server.Write(null, 0, 1));
         Assert.Throws<ArgumentNullException>(() => NotReachable(server.WriteAsync(null, 0, 1)));
     }
 }
Exemplo n.º 8
0
 public static void ServerWriteBufferNullThrows()
 {
     // force different constructor path
     using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None))
     {
         Assert.Throws <ArgumentNullException>(() => server.Write(null, 0, 1));
         Assert.Throws <ArgumentNullException>(() => NotReachable(server.WriteAsync(null, 0, 1)));
     }
 }
Exemplo n.º 9
0
        public static void ServerWriteNegativeCountThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws <ArgumentOutOfRangeException>(() => server.Write(new byte[5], 0, -1));

                // offset is checked before count
                Assert.Throws <ArgumentOutOfRangeException>(() => server.Write(new byte[1], -1, -1));

                // array is checked first
                Assert.Throws <ArgumentNullException>(() => server.Write(null, -1, -1));

                Assert.Throws <ArgumentOutOfRangeException>(() => NotReachable(server.WriteAsync(new byte[5], 0, -1)));

                // offset is checked before count
                Assert.Throws <ArgumentOutOfRangeException>(() => NotReachable(server.WriteAsync(new byte[1], -1, -1)));

                // array is checked first
                Assert.Throws <ArgumentNullException>(() => NotReachable(server.WriteAsync(null, -1, -1)));
            }
        }
Exemplo n.º 10
0
        public static void ServerReadOnlyThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                Assert.Throws <NotSupportedException>(() => server.Write(new byte[5], 0, 5));

                Assert.Throws <NotSupportedException>(() => server.WriteByte(123));

                Assert.Throws <NotSupportedException>(() => server.Flush());

                Assert.Throws <NotSupportedException>(() => server.OutBufferSize);

                Assert.Throws <NotSupportedException>(() => server.WaitForPipeDrain());

                Assert.Throws <NotSupportedException>(() => NotReachable(server.WriteAsync(new byte[5], 0, 5)));
            }
        }
Exemplo n.º 11
0
    public static async Task ServerSendsByteClientReceivesAsync()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Assert.True(server.IsConnected);
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(server.GetClientHandleAsString()))
            {
                Assert.True(server.IsConnected);
                Assert.True(client.IsConnected);

                byte[] sent     = new byte[] { 123 };
                byte[] received = new byte[] { 0 };
                await server.WriteAsync(sent, 0, 1);

                Assert.Equal(1, await client.ReadAsync(received, 0, 1));
                Assert.Equal(sent[0], received[0]);
            }
        }
    }
Exemplo n.º 12
0
    public static void ServerPInvokeChecks()
    {
        // calling every API related to server and client to detect any bad PInvokes
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Task clientTask = Task.Run(() => StartClient(PipeDirection.In, server.ClientSafePipeHandle));

            Assert.False(server.CanRead);
            Assert.False(server.CanSeek);
            Assert.False(server.CanTimeout);
            Assert.True(server.CanWrite);
            Assert.False(string.IsNullOrWhiteSpace(server.GetClientHandleAsString()));
            Assert.False(server.IsAsync);
            Assert.True(server.IsConnected);
            Assert.Equal(0, server.OutBufferSize);
            Assert.Equal(PipeTransmissionMode.Byte, server.ReadMode);
            Assert.NotNull(server.SafePipeHandle);
            Assert.Equal(PipeTransmissionMode.Byte, server.TransmissionMode);

            server.Write(new byte[] { 123 }, 0, 1);
            server.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
            server.Flush();
            server.WaitForPipeDrain();

            clientTask.Wait();
            server.DisposeLocalCopyOfClientHandle();
        }

        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            Task clientTask = Task.Run(() => StartClient(PipeDirection.Out, server.ClientSafePipeHandle));

            Assert.Equal(4096, server.InBufferSize);
            byte[] readData = new byte[] { 0, 1 };
            Assert.Equal(1, server.Read(readData, 0, 1));
            Assert.Equal(1, server.ReadAsync(readData, 1, 1).Result);
            Assert.Equal(123, readData[0]);
            Assert.Equal(124, readData[1]);

            clientTask.Wait();
        }
    }
Exemplo n.º 13
0
        public async Task AnonymousPipeReadViaFileStream(bool asyncReads)
        {
            using (var server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Task serverTask = server.WriteAsync(new byte[] { 0, 1, 2, 3, 4, 5 }, 0, 6);

                using (var client = new FileStream(new SafeFileHandle(server.ClientSafePipeHandle.DangerousGetHandle(), false), FileAccess.Read, bufferSize: 3))
                {
                    var arr = new byte[1];
                    for (int i = 0; i < 6; i++)
                    {
                        Assert.Equal(1, asyncReads ?
                                     await client.ReadAsync(arr, 0, 1) :
                                     client.Read(arr, 0, 1));
                        Assert.Equal(i, arr[0]);
                    }
                }

                await serverTask;
            }
        }
Exemplo n.º 14
0
        public static void ServerWriteArrayOutOfBoundsThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                // offset out of bounds
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[1], 1, 1));

                // offset out of bounds for 0 count read
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[1], 2, 0));

                // offset out of bounds even for 0 length buffer
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[0], 1, 0));

                // combination offset and count out of bounds
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[2], 1, 2));

                // edges
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[0], int.MaxValue, 0));
                Assert.Throws <ArgumentException>(null, () => server.Write(new byte[0], int.MaxValue, int.MaxValue));

                Assert.Throws <ArgumentException>(() => server.Write(new byte[5], 3, 4));

                // offset out of bounds
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[1], 1, 1)));

                // offset out of bounds for 0 count read
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[1], 2, 0)));

                // offset out of bounds even for 0 length buffer
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], 1, 0)));

                // combination offset and count out of bounds
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[2], 1, 2)));

                // edges
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], int.MaxValue, 0)));
                Assert.Throws <ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], int.MaxValue, int.MaxValue)));

                Assert.Throws <ArgumentException>(() => NotReachable(server.WriteAsync(new byte[5], 3, 4)));
            }
        }
Exemplo n.º 15
0
    public static void ServerPInvokeChecks()
    {
        // calling every API related to server and client to detect any bad PInvokes
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Task clientTask = StartClientAsync(PipeDirection.In, server.ClientSafePipeHandle);

            Console.WriteLine("server.CanRead = {0}", server.CanRead);
            Console.WriteLine("server.CanSeek = {0}", server.CanSeek);
            Console.WriteLine("server.CanTimeout = {0}", server.CanTimeout);
            Console.WriteLine("server.CanWrite = {0}", server.CanWrite);
            Console.WriteLine("server.GetClientHandleAsString() = {0}", server.GetClientHandleAsString());
            Console.WriteLine("server.IsAsync = {0}", server.IsAsync);
            Console.WriteLine("server.IsConnected = {0}", server.IsConnected);
            Console.WriteLine("server.OutBufferSize = {0}", server.OutBufferSize);
            Console.WriteLine("server.ReadMode = {0}", server.ReadMode);
            Console.WriteLine("server.SafePipeHandle = {0}", server.SafePipeHandle);
            Console.WriteLine("server.TransmissionMode = {0}", server.TransmissionMode);
            server.Write(new byte[] { 123 }, 0, 1);
            server.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
            server.Flush();
            Console.WriteLine("Waiting for Pipe Drain.");
            server.WaitForPipeDrain();
            clientTask.Wait();
            server.DisposeLocalCopyOfClientHandle();
        }
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            Task clientTask = StartClientAsync(PipeDirection.Out, server.ClientSafePipeHandle);

            Console.WriteLine("server.InBufferSize = {0}", server.InBufferSize);
            byte[] readData = new byte[] { 0, 1 };
            server.Read(readData, 0, 1);
            server.ReadAsync(readData, 1, 1).Wait();
            Assert.Equal(123, readData[0]);
            Assert.Equal(124, readData[1]);
        }
    }
Exemplo n.º 16
0
    public static void ServerSendsByteClientReceivesAsync()
    {
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
        {
            Assert.True(server.IsConnected);
            using (AnonymousPipeClientStream client = new AnonymousPipeClientStream(server.GetClientHandleAsString()))
            {
                Assert.True(server.IsConnected);
                Assert.True(client.IsConnected);

                byte[] sent      = new byte[] { 123 };
                byte[] received  = new byte[] { 0 };
                Task   writeTask = server.WriteAsync(sent, 0, 1);
                writeTask.Wait();

                Task <int> readTask = client.ReadAsync(received, 0, 1);
                readTask.Wait();

                Assert.Equal(1, readTask.Result);
                Assert.Equal(sent[0], received[0]);
            }
        }
    }
Exemplo n.º 17
0
 public async Task WriteAsync(byte[] bytes)
 {
     await pipe.WriteAsync(bytes, 0, bytes.Length);
 }
Exemplo n.º 18
0
        public static void ServerWriteArrayOutOfBoundsThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                // offset out of bounds
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[1], 1, 1));

                // offset out of bounds for 0 count read
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[1], 2, 0));

                // offset out of bounds even for 0 length buffer
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[0], 1, 0));

                // combination offset and count out of bounds
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[2], 1, 2));

                // edges
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[0], int.MaxValue, 0));
                Assert.Throws<ArgumentException>(null, () => server.Write(new byte[0], int.MaxValue, int.MaxValue));

                Assert.Throws<ArgumentException>(() => server.Write(new byte[5], 3, 4));

                // offset out of bounds
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[1], 1, 1)));

                // offset out of bounds for 0 count read
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[1], 2, 0)));

                // offset out of bounds even for 0 length buffer
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], 1, 0)));

                // combination offset and count out of bounds
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[2], 1, 2)));

                // edges
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], int.MaxValue, 0)));
                Assert.Throws<ArgumentException>(null, () => NotReachable(server.WriteAsync(new byte[0], int.MaxValue, int.MaxValue)));

                Assert.Throws<ArgumentException>(() => NotReachable(server.WriteAsync(new byte[5], 3, 4)));
            }
        }
Exemplo n.º 19
0
        public static void ServerReadOnlyThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
            {
                Assert.Throws<NotSupportedException>(() => server.Write(new byte[5], 0, 5));

                Assert.Throws<NotSupportedException>(() => server.WriteByte(123));

                Assert.Throws<NotSupportedException>(() => server.Flush());

                Assert.Throws<NotSupportedException>(() => server.OutBufferSize);

                Assert.Throws<NotSupportedException>(() => server.WaitForPipeDrain());

                Assert.Throws<NotSupportedException>(() => NotReachable(server.WriteAsync(new byte[5], 0, 5)));
            }
        }
Exemplo n.º 20
0
        public static void ServerWriteNegativeCountThrows()
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out))
            {
                Assert.Throws<ArgumentOutOfRangeException>(() => server.Write(new byte[5], 0, -1));

                // offset is checked before count
                Assert.Throws<ArgumentOutOfRangeException>(() => server.Write(new byte[1], -1, -1));

                // array is checked first
                Assert.Throws<ArgumentNullException>(() => server.Write(null, -1, -1));

                Assert.Throws<ArgumentOutOfRangeException>(() => NotReachable(server.WriteAsync(new byte[5], 0, -1)));

                // offset is checked before count
                Assert.Throws<ArgumentOutOfRangeException>(() => NotReachable(server.WriteAsync(new byte[1], -1, -1)));

                // array is checked first
                Assert.Throws<ArgumentNullException>(() => NotReachable(server.WriteAsync(null, -1, -1)));
            }
        }
Exemplo n.º 21
0
        async public Task TestAsyncOutputStream_BeginCancelBeginOutputRead()
        {
            using (AnonymousPipeServerStream pipeWrite = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
                using (AnonymousPipeServerStream pipeRead = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable))
                {
                    using (Process p = CreateProcess(TestAsyncOutputStream_BeginCancelBeinOutputRead_RemotelyInvokable, $"{pipeWrite.GetClientHandleAsString()} {pipeRead.GetClientHandleAsString()}"))
                    {
                        var dataReceived = new BlockingCollection <int>();

                        p.StartInfo.RedirectStandardOutput = true;
                        p.OutputDataReceived += (s, e) =>
                        {
                            if (e.Data != null)
                            {
                                dataReceived.Add(int.Parse(e.Data));
                            }
                        };

                        // Start child process
                        p.Start();

                        pipeWrite.DisposeLocalCopyOfClientHandle();
                        pipeRead.DisposeLocalCopyOfClientHandle();

                        // Wait child process start
                        Assert.True(await WaitPipeSignal(pipeRead, WaitInMS), "Child process not started");

                        //Start listening and signal client to produce 1,2,3
                        p.BeginOutputReadLine();
                        await pipeWrite.WriteAsync(new byte[1], 0, 1);

                        // Wait child signal produce number 1,2,3
                        Assert.True(await WaitPipeSignal(pipeRead, WaitInMS), "Missing child signal for value 1,2,3");
                        using (CancellationTokenSource cts = new CancellationTokenSource(WaitInMS))
                        {
                            try
                            {
                                List <int> expectedValue123 = new List <int>()
                                {
                                    1, 2, 3
                                };
                                foreach (int value in dataReceived.GetConsumingEnumerable(cts.Token))
                                {
                                    expectedValue123.Remove(value);
                                    if (expectedValue123.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            catch (OperationCanceledException)
                            {
                                Assert.False(cts.IsCancellationRequested, "Values 1,2,3 not arrived");
                            }
                        }

                        // Cancel and signal child
                        p.CancelOutputRead();
                        await pipeWrite.WriteAsync(new byte[1], 0, 1);

                        // Re-start listening and signal child
                        p.BeginOutputReadLine();
                        await pipeWrite.WriteAsync(new byte[1], 0, 1);

                        // Wait child process close
                        Assert.True(p.WaitForExit(WaitInMS), "Child process didn't close");
                        p.WaitForExit(); // wait for event handlers to complete

                        // Wait for value 7,8,9
                        using (CancellationTokenSource cts = new CancellationTokenSource(WaitInMS))
                        {
                            try
                            {
                                List <int> expectedValue789 = new List <int>()
                                {
                                    7, 8, 9
                                };
                                foreach (int value in dataReceived.GetConsumingEnumerable(cts.Token))
                                {
                                    expectedValue789.Remove(value);
                                    if (expectedValue789.Count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            catch (OperationCanceledException)
                            {
                                Assert.False(cts.IsCancellationRequested, "Values 7,8,9 not arrived");
                            }
                        }
                    }
                }
        }
Exemplo n.º 22
0
    public static async Task ServerPInvokeChecks()
    {
        // calling every API related to server and client to detect any bad PInvokes
        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.None, 4096))
        {
            Task clientTask = Task.Run(() => StartClient(PipeDirection.In, server.ClientSafePipeHandle));

            Assert.False(server.CanRead);
            Assert.False(server.CanSeek);
            Assert.False(server.CanTimeout);
            Assert.True(server.CanWrite);
            Assert.False(string.IsNullOrWhiteSpace(server.GetClientHandleAsString()));
            Assert.False(server.IsAsync);
            Assert.True(server.IsConnected);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
                RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.True(server.OutBufferSize > 0);
            }
            else
            {
                Assert.Throws <PlatformNotSupportedException>(() => server.OutBufferSize);
            }
            Assert.Equal(PipeTransmissionMode.Byte, server.ReadMode);
            Assert.NotNull(server.SafePipeHandle);
            Assert.Equal(PipeTransmissionMode.Byte, server.TransmissionMode);

            server.Write(new byte[] { 123 }, 0, 1);
            await server.WriteAsync(new byte[] { 124 }, 0, 1);

            server.Flush();
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                server.WaitForPipeDrain();
            }
            else
            {
                Assert.Throws <PlatformNotSupportedException>(() => server.WaitForPipeDrain());
            }

            await clientTask;
            server.DisposeLocalCopyOfClientHandle();
        }

        using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In))
        {
            Task clientTask = Task.Run(() => StartClient(PipeDirection.Out, server.ClientSafePipeHandle));

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.Equal(4096, server.InBufferSize);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.True(server.InBufferSize > 0);
            }
            else
            {
                Assert.Throws <PlatformNotSupportedException>(() => server.InBufferSize);
            }
            byte[] readData = new byte[] { 0, 1 };
            Assert.Equal(1, server.Read(readData, 0, 1));
            Assert.Equal(1, server.ReadAsync(readData, 1, 1).Result);
            Assert.Equal(123, readData[0]);
            Assert.Equal(124, readData[1]);

            await clientTask;
        }
    }