-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
WebSocketReceiveResultTests.cs
48 lines (42 loc) · 2.22 KB
/
WebSocketReceiveResultTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Net.WebSockets.Tests
{
public sealed class WebSocketReceiveResultTests
{
public static object[][] ConstructorData = {
new object[] { 0, WebSocketMessageType.Text, false, null, null },
new object[] { 1, WebSocketMessageType.Text, true, null, null },
new object[] { 2, WebSocketMessageType.Binary, false, null, null },
new object[] { 3, WebSocketMessageType.Binary, true, null, null },
new object[] { 4, WebSocketMessageType.Close, true, WebSocketCloseStatus.NormalClosure, null },
new object[] { 5, WebSocketMessageType.Close, true, WebSocketCloseStatus.NormalClosure, "normal" },
};
[Theory, MemberData(nameof(ConstructorData))]
public void ConstructorTest_Success(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
WebSocketReceiveResult wsrr;
if (closeStatus == null && closeStatusDescription == null)
{
wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage);
Assert.Equal(count, wsrr.Count);
Assert.Equal(messageType, wsrr.MessageType);
Assert.Equal(endOfMessage, wsrr.EndOfMessage);
Assert.Null(wsrr.CloseStatus);
Assert.Null(wsrr.CloseStatusDescription);
}
wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage, closeStatus, closeStatusDescription);
Assert.Equal(count, wsrr.Count);
Assert.Equal(messageType, wsrr.MessageType);
Assert.Equal(endOfMessage, wsrr.EndOfMessage);
Assert.Equal(closeStatus, wsrr.CloseStatus);
Assert.Equal(closeStatusDescription, wsrr.CloseStatusDescription);
}
[Fact]
public void ConstructorTest_Invalid_ThrowsArgumentException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new WebSocketReceiveResult(-1, WebSocketMessageType.Text, false, null, null));
}
}
}