| 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 Microsoft.Win32.SafeHandles; |
| 6 |
using Xunit; |
| 7 |
|
| 8 |
namespace System.IO.Pipes.Tests |
| 9 |
{ |
| 10 |
/// <summary> |
| 11 |
/// Tests for the constructors of AnonymousPipeClientStream |
| 12 |
/// </summary> |
| 13 |
public class AnonymousPipeTest_CreateClient : AnonymousPipeTestBase |
| 14 |
{ |
| 15 |
[Fact] |
| 16 |
public static void NullParameters_Throws_ArgumentNullException() |
| 17 |
{ |
| 18 |
AssertExtensions.Throws<ArgumentNullException>("pipeHandleAsString", () => new AnonymousPipeClientStream((string)null)); |
| 19 |
AssertExtensions.Throws<ArgumentNullException>("pipeHandleAsString", () => new AnonymousPipeClientStream(PipeDirection.Out, (string)null)); |
| 20 |
AssertExtensions.Throws<ArgumentNullException>("safePipeHandle", () => new AnonymousPipeClientStream(PipeDirection.In, (SafePipeHandle)null)); |
| 21 |
} |
| 22 |
|
| 23 |
[Fact] |
| 24 |
public static void CreateClientStreamFromStringHandle_Valid() |
| 25 |
{ |
| 26 |
using (var server = new AnonymousPipeServerStream(PipeDirection.Out)) |
| 27 |
using (var client = new AnonymousPipeClientStream(server.GetClientHandleAsString())) |
| 28 |
{ |
| 29 |
SuppressClientHandleFinalizationIfNetFramework(server); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
[Theory] |
| 34 |
[InlineData("abc")] |
| 35 |
[InlineData("-1")] |
| 36 |
public static void InvalidStringParameters_Throws_ArgumentException(string handle) |
| 37 |
{ |
| 38 |
// Parameters must be nonnegative numeric characters |
| 39 |
AssertExtensions.Throws<ArgumentException>("pipeHandleAsString", () => new AnonymousPipeClientStream(handle)); |
| 40 |
AssertExtensions.Throws<ArgumentException>("pipeHandleAsString", () => new AnonymousPipeClientStream(PipeDirection.Out, handle)); |
| 41 |
} |
| 42 |
|
| 43 |
[Fact] |
| 44 |
public static void InvalidPipeHandle_Throws_ArgumentException() |
| 45 |
{ |
| 46 |
SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true); |
| 47 |
AssertExtensions.Throws<ArgumentException>("safePipeHandle", () => new AnonymousPipeClientStream(PipeDirection.In, pipeHandle)); |
| 48 |
} |
| 49 |
|
| 50 |
[Fact] |
| 51 |
public static void InOutPipeDirection_Throws_NotSupportedException() |
| 52 |
{ |
| 53 |
// Anonymous pipes can't be made with PipeDirection.InOut |
| 54 |
Assert.Throws<NotSupportedException>(() => new AnonymousPipeClientStream(PipeDirection.InOut, "123")); |
| 55 |
|
| 56 |
SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true); |
| 57 |
Assert.Throws<NotSupportedException>(() => new AnonymousPipeClientStream(PipeDirection.InOut, pipeHandle)); |
| 58 |
} |
| 59 |
} |
| 60 |
} |