1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Runtime.InteropServices; 6 using System.Threading.Tasks; 7 using Xunit; 8 9 namespace System.IO.Pipes.Tests 10 { 11 [ActiveIssue(22271, TargetFrameworkMonikers.UapNotUapAot)] 12 public class NamedPipeTest_Read_ServerOut_ClientIn : PipeTest_Read 13 { CreateServerClientPair()14 protected override ServerClientPair CreateServerClientPair() 15 { 16 ServerClientPair ret = new ServerClientPair(); 17 string pipeName = GetUniquePipeName(); 18 var writeablePipe = new NamedPipeServerStream(pipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); 19 var readablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.In, PipeOptions.Asynchronous); 20 21 Task clientConnect = readablePipe.ConnectAsync(); 22 writeablePipe.WaitForConnection(); 23 clientConnect.Wait(); 24 25 ret.readablePipe = readablePipe; 26 ret.writeablePipe = writeablePipe; 27 return ret; 28 } 29 } 30 31 [ActiveIssue(22271, TargetFrameworkMonikers.UapNotUapAot)] 32 public class NamedPipeTest_Read_ServerIn_ClientOut : PipeTest_Read 33 { CreateServerClientPair()34 protected override ServerClientPair CreateServerClientPair() 35 { 36 ServerClientPair ret = new ServerClientPair(); 37 string pipeName = GetUniquePipeName(); 38 var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); 39 var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.Out, PipeOptions.Asynchronous); 40 41 Task clientConnect = writeablePipe.ConnectAsync(); 42 readablePipe.WaitForConnection(); 43 clientConnect.Wait(); 44 45 ret.readablePipe = readablePipe; 46 ret.writeablePipe = writeablePipe; 47 return ret; 48 } 49 } 50 51 [ActiveIssue(22271, TargetFrameworkMonikers.UapNotUapAot)] 52 public class NamedPipeTest_Read_ServerInOut_ClientInOut : PipeTest_Read 53 { CreateServerClientPair()54 protected override ServerClientPair CreateServerClientPair() 55 { 56 ServerClientPair ret = new ServerClientPair(); 57 string pipeName = GetUniquePipeName(); 58 var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); 59 var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); 60 61 Task clientConnect = writeablePipe.ConnectAsync(); 62 readablePipe.WaitForConnection(); 63 clientConnect.Wait(); 64 65 ret.readablePipe = readablePipe; 66 ret.writeablePipe = writeablePipe; 67 return ret; 68 } 69 70 public override bool SupportsBidirectionalReadingWriting => true; 71 } 72 73 [ActiveIssue(22271, TargetFrameworkMonikers.UapNotUapAot)] 74 public class NamedPipeTest_Read_ServerInOut_ClientInOut_APMWaitForConnection : PipeTest_Read 75 { CreateServerClientPair()76 protected override ServerClientPair CreateServerClientPair() 77 { 78 ServerClientPair ret = new ServerClientPair(); 79 string pipeName = GetUniquePipeName(); 80 var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); 81 var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); 82 83 Task serverConnect = Task.Factory.FromAsync(readablePipe.BeginWaitForConnection, readablePipe.EndWaitForConnection, null); 84 writeablePipe.Connect(); 85 serverConnect.Wait(); 86 87 ret.readablePipe = readablePipe; 88 ret.writeablePipe = writeablePipe; 89 return ret; 90 } 91 92 public override bool SupportsBidirectionalReadingWriting => true; 93 } 94 } 95