diff --git a/test/Common/TestHelpers.cs b/test/Common/TestHelpers.cs new file mode 100644 index 0000000000..ff28a97df8 --- /dev/null +++ b/test/Common/TestHelpers.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.SignalR.Tests.Common +{ + public static class TestHelpers + { + public static bool IsWebSocketsSupported() + { + try + { + new System.Net.WebSockets.ClientWebSocket().Dispose(); + } + catch (PlatformNotSupportedException) + { + return false; + } + + return true; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 3f0d33f1e5..29b57b4acb 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -243,7 +243,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests public static IEnumerable TransportTypes() { - if (WebsocketsSupported()) + if (TestHelpers.IsWebSocketsSupported()) { // TODO: Currently we are always sending Text messages over websockets which does not work // with binary protocols. It is getting fixed separately. @@ -253,20 +253,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests } yield return TransportType.ServerSentEvents; yield return TransportType.LongPolling; - - bool WebsocketsSupported() - { - try - { - new System.Net.WebSockets.ClientWebSocket(); - } - catch (PlatformNotSupportedException) - { - return false; - } - - return true; - } } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj index d14f25bf48..2aaed264ab 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Microsoft.AspNetCore.SignalR.Client.FunctionalTests.csproj @@ -17,6 +17,7 @@ + diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs index fa4920dad2..601f10ac21 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs @@ -3,6 +3,7 @@ using System; using System.Net.Http; +using Microsoft.AspNetCore.SignalR.Tests.Common; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.AspNetCore.Testing.xunit; @@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [InlineData(TransportType.LongPolling, typeof(LongPollingTransport))] public void DefaultTransportFactoryCreatesRequestedTransportIfAvailable_Win7(TransportType requestedTransport, Type expectedTransportType) { - if (!WebsocketsSupported()) + if (!TestHelpers.IsWebSocketsSupported()) { var transportFactory = new DefaultTransportFactory(requestedTransport, loggerFactory: null, httpClient: new HttpClient()); Assert.IsType(expectedTransportType, @@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [InlineData(TransportType.WebSockets)] public void DefaultTransportFactoryThrowsIfItCannotCreateRequestedTransport_Win7(TransportType requestedTransport) { - if (!WebsocketsSupported()) + if (!TestHelpers.IsWebSocketsSupported()) { var transportFactory = new DefaultTransportFactory(requestedTransport, loggerFactory: null, httpClient: new HttpClient()); @@ -95,19 +96,5 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.Equal("No requested transports available on the server.", ex.Message); } } - - private bool WebsocketsSupported() - { - try - { - new System.Net.WebSockets.ClientWebSocket(); - } - catch (PlatformNotSupportedException) - { - return false; - } - - return true; - } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index cf841c9977..c23c7d1160 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -58,7 +58,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task CanStartAndStopConnectionUsingGivenTransport(TransportType transportType) { var url = _serverFixture.BaseUrl + "/echo"; - // When WebSockets is attempted to be used on Windows 7/2008R2 it will instead use ServerSentEvents var connection = new HttpConnection(new Uri(url), transportType); await connection.StartAsync().OrTimeout(); await connection.DisposeAsync().OrTimeout(); @@ -99,7 +98,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] [MemberData(nameof(TransportTypes))] // TODO: transfer types public async Task ConnectionCanSendAndReceiveMessages(TransportType transportType) @@ -189,7 +187,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests var logger = loggerFactory.CreateLogger(); var url = _serverFixture.BaseUrl + "/echo"; - var connection = new HttpConnection(new Uri(url), loggerFactory); + var connection = new HttpConnection(new Uri(url), TransportType.WebSockets, loggerFactory); connection.Features.Set( new TransferModeFeature { TransferMode = TransferMode.Binary }); @@ -294,12 +292,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - public static IEnumerable TransportTypes => - new[] + public static IEnumerable TransportTypes() + { + if (TestHelpers.IsWebSocketsSupported()) { - new object[] { TransportType.WebSockets }, - new object[] { TransportType.ServerSentEvents }, - new object[] { TransportType.LongPolling } - }; + yield return new object[] { TransportType.WebSockets }; + } + yield return new object[] { TransportType.ServerSentEvents }; + yield return new object[] { TransportType.LongPolling }; + } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj index 21923cfe38..07ad81a841 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Microsoft.AspNetCore.SignalR.Tests.csproj @@ -21,6 +21,7 @@ +