Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmi Priya Sekar committed Jan 20, 2018
1 parent 70f41f9 commit b12c6b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
53 changes: 18 additions & 35 deletions src/System.Net.HttpListener/tests/HttpListenerWebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace System.Net.Tests
public class HttpListenerWebSocketTests : IDisposable
{
public static bool PartialMessagesSupported => PlatformDetection.ClientWebSocketPartialMessagesSupported;
public static bool IsNotWindows7 { get; } = !PlatformDetection.IsWindows7;
public static bool IsNotWindows7AndIsWindowsImplementation => IsNotWindows7 && Helpers.IsWindowsImplementation;
public static bool WebSocketsSupported { get; } = !PlatformDetection.IsWindows7;

private HttpListenerFactory Factory { get; }
private HttpListener Listener { get; }
Expand All @@ -35,7 +34,7 @@ public void Dispose()
Client.Dispose();
}

[ConditionalTheory(nameof(PartialMessagesSupported), nameof(IsNotWindows7))]
[ConditionalTheory(nameof(PartialMessagesSupported), nameof(WebSocketsSupported))]
[InlineData(WebSocketMessageType.Text, false)]
[InlineData(WebSocketMessageType.Binary, false)]
[InlineData(WebSocketMessageType.Text, true)]
Expand All @@ -60,14 +59,14 @@ public async Task SendAsync_SendWholeBuffer_Success(WebSocketMessageType message
Assert.Equal(Text, Encoding.ASCII.GetString(receivedBytes));
}

[ConditionalFact(nameof(IsNotWindows7))]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task SendAsync_NoInnerBuffer_ThrowsArgumentNullException()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
await AssertExtensions.ThrowsAsync<ArgumentNullException>("buffer.Array", () => context.WebSocket.SendAsync(new ArraySegment<byte>(), WebSocketMessageType.Text, false, new CancellationToken()));
}

[ConditionalTheory(nameof(IsNotWindows7))]
[ConditionalTheory(nameof(WebSocketsSupported))]
[InlineData(WebSocketMessageType.Close)]
[InlineData(WebSocketMessageType.Text - 1)]
[InlineData(WebSocketMessageType.Binary + 1)]
Expand All @@ -77,7 +76,7 @@ public async Task SendAsync_InvalidMessageType_ThrowsArgumentNullException(WebSo
await AssertExtensions.ThrowsAsync<ArgumentException>("messageType", () => context.WebSocket.SendAsync(new ArraySegment<byte>(), messageType, false, new CancellationToken()));
}

[ConditionalFact(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20395, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task SendAsync_Disposed_ThrowsObjectDisposedException()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -87,7 +86,7 @@ public async Task SendAsync_Disposed_ThrowsObjectDisposedException()
}

[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "WebSocket partial send is not supported on UAP. (#22053)")]
[ConditionalTheory(nameof(IsNotWindows7))]
[ConditionalTheory(nameof(WebSocketsSupported))]
[InlineData(WebSocketMessageType.Text, false)]
[InlineData(WebSocketMessageType.Binary, false)]
[InlineData(WebSocketMessageType.Text, true)]
Expand All @@ -112,7 +111,7 @@ public async Task ReceiveAsync_ReadWholeBuffer_Success(WebSocketMessageType mess
Assert.Equal(Text, Encoding.ASCII.GetString(receivedBytes));
}

[ConditionalFact(nameof(IsNotWindows7))]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task ReceiveAsync_NoInnerBuffer_ThrowsArgumentNullException()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -121,7 +120,7 @@ public async Task ReceiveAsync_NoInnerBuffer_ThrowsArgumentNullException()
await AssertExtensions.ThrowsAsync<ArgumentNullException>("buffer.Array", () => context.WebSocket.ReceiveAsync(new ArraySegment<byte>(), new CancellationToken()));
}

[ConditionalFact(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20395, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task ReceiveAsync_Disposed_ThrowsObjectDisposedException()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -133,23 +132,14 @@ public async Task ReceiveAsync_Disposed_ThrowsObjectDisposedException()

public static IEnumerable<object[]> CloseStatus_Valid_TestData()
{
yield return new object[] { (WebSocketCloseStatus)(-1), "Negative", 65535 };
yield return new object[] { WebSocketCloseStatus.Empty, null, WebSocketCloseStatus.Empty };
yield return new object[] { WebSocketCloseStatus.EndpointUnavailable, "", WebSocketCloseStatus.EndpointUnavailable };
yield return new object[] { WebSocketCloseStatus.MandatoryExtension, "StatusDescription", WebSocketCloseStatus.MandatoryExtension };
}

[ConditionalTheory(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20396, TestPlatforms.AnyUnix)]
[ConditionalTheory(nameof(WebSocketsSupported))]
[MemberData(nameof(CloseStatus_Valid_TestData))]
public async Task CloseOutputAsync_HandshakeStartedFromClient_Success(WebSocketCloseStatus status, string statusDescription, WebSocketCloseStatus expectedCloseStatus)
{
// [ActiveIssue(20392, TargetFrameworkMonikers.Netcoreapp)]
string expectedStatusDescription = statusDescription;
if (!PlatformDetection.IsFullFramework && statusDescription == null)
{
expectedStatusDescription = string.Empty;
}

HttpListenerWebSocketContext context = await GetWebSocketContext();
await ClientConnectTask;

Expand All @@ -164,7 +154,7 @@ public async Task CloseOutputAsync_HandshakeStartedFromClient_Success(WebSocketC
Assert.Equal(new byte[10], receivedClientBytes);
Assert.Equal(expectedCloseStatus, clientResult.CloseStatus);

Assert.Equal(expectedStatusDescription, clientResult.CloseStatusDescription);
Assert.Equal(statusDescription, clientResult.CloseStatusDescription);
Assert.Equal(WebSocketMessageType.Close, clientResult.MessageType);
Assert.True(clientResult.EndOfMessage);

Expand All @@ -185,7 +175,7 @@ public async Task CloseOutputAsync_HandshakeStartedFromClient_Success(WebSocketC
WebSocketReceiveResult serverResult = await clientReceiveTask;
Assert.Equal(new byte[10], receivedServerBytes);
Assert.Equal(expectedCloseStatus, serverResult.CloseStatus);
Assert.Equal(expectedStatusDescription, serverResult.CloseStatusDescription);
Assert.Equal(statusDescription, serverResult.CloseStatusDescription);
Assert.Equal(WebSocketMessageType.Close, serverResult.MessageType);
Assert.True(serverResult.EndOfMessage);

Expand All @@ -202,17 +192,10 @@ public async Task CloseOutputAsync_HandshakeStartedFromClient_Success(WebSocketC
await context.WebSocket.CloseOutputAsync(WebSocketCloseStatus.Empty, null, new CancellationToken());
}

[ConditionalTheory(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20396, TestPlatforms.AnyUnix)]
[ConditionalTheory(nameof(WebSocketsSupported))]
[MemberData(nameof(CloseStatus_Valid_TestData))]
public async Task CloseAsync_HandshakeStartedFromClient_Success(WebSocketCloseStatus status, string statusDescription, WebSocketCloseStatus expectedCloseStatus)
{
// [ActiveIssue(20392, TargetFrameworkMonikers.Netcoreapp)]
string expectedStatusDescription = statusDescription;
if (!PlatformDetection.IsFullFramework && statusDescription == null)
{
expectedStatusDescription = string.Empty;
}

HttpListenerWebSocketContext context = await GetWebSocketContext();
await ClientConnectTask;

Expand Down Expand Up @@ -248,7 +231,7 @@ public async Task CloseAsync_HandshakeStartedFromClient_Success(WebSocketCloseSt
WebSocketReceiveResult clientResult = await clientReceiveTask;
Assert.Equal(new byte[10], receivedClientBytes);
Assert.Equal(expectedCloseStatus, clientResult.CloseStatus);
Assert.Equal(expectedStatusDescription, clientResult.CloseStatusDescription);
Assert.Equal(statusDescription, clientResult.CloseStatusDescription);
Assert.Equal(WebSocketMessageType.Close, clientResult.MessageType);
Assert.True(clientResult.EndOfMessage);

Expand All @@ -275,7 +258,7 @@ public static IEnumerable<object[]> CloseStatus_Invalid_TestData()
yield return new object[] { (WebSocketCloseStatus)1015, null, "closeStatus" };
}

[ConditionalTheory(nameof(IsNotWindows7))]
[ConditionalTheory(nameof(WebSocketsSupported))]
[MemberData(nameof(CloseStatus_Invalid_TestData))]
public async Task CloseAsync_InvalidCloseStatus_ThrowsArgumentException(WebSocketCloseStatus status, string statusDescription, string paramName)
{
Expand All @@ -285,7 +268,7 @@ public async Task CloseAsync_InvalidCloseStatus_ThrowsArgumentException(WebSocke
await Assert.ThrowsAsync<ArgumentException>(paramName, () => context.WebSocket.CloseOutputAsync(status, statusDescription, new CancellationToken()));
}

[ConditionalFact(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20394, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task CloseAsync_AfterDisposed_Nop()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -295,7 +278,7 @@ public async Task CloseAsync_AfterDisposed_Nop()
await context.WebSocket.CloseAsync(WebSocketCloseStatus.Empty, null, new CancellationToken());
}

[ConditionalFact(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20394, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task CloseAsync_AfterAborted_Nop()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -305,7 +288,7 @@ public async Task CloseAsync_AfterAborted_Nop()
await context.WebSocket.CloseAsync(WebSocketCloseStatus.Empty, null, new CancellationToken());
}

[ConditionalFact(nameof(IsNotWindows7AndIsWindowsImplementation))] // [ActiveIssue(20397, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task Dispose_CallAfterDisposed_Nop()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand All @@ -319,7 +302,7 @@ public async Task Dispose_CallAfterDisposed_Nop()
Assert.Equal(WebSocketState.Aborted, context.WebSocket.State);
}

[ConditionalFact(nameof(IsNotWindows7))]
[ConditionalFact(nameof(WebSocketsSupported))]
public async Task Abort_CallAfterAborted_Nop()
{
HttpListenerWebSocketContext context = await GetWebSocketContext();
Expand Down
7 changes: 0 additions & 7 deletions src/System.Net.HttpListener/tests/WebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ public WebSocketTests()
[Fact]
public async Task AcceptWebSocketAsync_NullSubProtocol_Succeeds()
{
if (PlatformDetection.IsWindows7)
{
// Websockets in WinHttp 5.1 is only supported from Windows 8+
Assert.Throws<PlatformNotSupportedException>(() => new ClientWebSocket());
return;
}

UriBuilder uriBuilder = new UriBuilder(_factory.ListeningUrl);
uriBuilder.Scheme = "ws";

Expand Down

0 comments on commit b12c6b5

Please sign in to comment.