diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index c9ef03fa5c..64b25af727 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -724,7 +724,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketOptionsAreApplied() { using (StartLog(out var loggerFactory, $"{nameof(WebSocketOptionsAreApplied)}")) diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/WebSocketsSupportedConditionAttribute.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/WebSocketsSupportedConditionAttribute.cs new file mode 100644 index 0000000000..f7d4d9b896 --- /dev/null +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/WebSocketsSupportedConditionAttribute.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.SignalR.Tests +{ + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] + public class WebSocketsSupportedConditionAttribute : Attribute, ITestCondition + { + public bool IsMet + { + get + { +#if NETCOREAPP2_1 + // .NET Core 2.1 and greater has sockets + return true; +#else + // Non-Windows platforms have sockets + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return true; + } + + // Windows 8 and greater has sockets + if (Environment.Version >= new Version(6, 2)) + { + return true; + } + + return false; +#endif + } + } + + public string SkipReason => "No WebSockets Client for this platform"; + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs index e8a93fd4f6..02c0f7ae27 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/DefaultTransportFactoryTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [InlineData(TransportType.WebSockets, typeof(WebSocketsTransport))] [InlineData(TransportType.ServerSentEvents, typeof(ServerSentEventsTransport))] [InlineData(TransportType.LongPolling, typeof(LongPollingTransport))] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public void DefaultTransportFactoryCreatesRequestedTransportIfAvailable(TransportType requestedTransport, Type expectedTransportType) { var transportFactory = new DefaultTransportFactory(requestedTransport, loggerFactory: null, httpClient: new HttpClient(), httpOptions: null); @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public void DefaultTransportFactoryCreatesWebSocketsTransportIfAvailable() { Assert.IsType( diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index e51ba6489e..92e64fdfe8 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketsTest() { using (StartLog(out var loggerFactory)) @@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task HTTPRequestsNotSentWhenWebSocketsTransportRequested() { using (StartLog(out var loggerFactory)) @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] [MemberData(nameof(MessageSizesData))] public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(string message) { @@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated_WebSocket() { try diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs index fd229fed24..d718ac7c9c 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public void HttpOptionsSetOntoWebSocketOptions() { ClientWebSocketOptions webSocketsOptions = null; @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped() { using (StartLog(out var loggerFactory)) @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact(Skip = "Issue in ClientWebSocket prevents user-agent being set - https://github.com/dotnet/corefx/issues/26627")] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketsTransportSendsUserAgent() { using (StartLog(out var loggerFactory)) @@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketsTransportStopsWhenConnectionChannelClosed() { using (StartLog(out var loggerFactory)) @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] [InlineData(TransferFormat.Text)] [InlineData(TransferFormat.Binary)] public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat) @@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] [InlineData(TransferFormat.Text)] [InlineData(TransferFormat.Binary)] public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat) @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [ConditionalTheory] [InlineData(TransferFormat.Text | TransferFormat.Binary)] // Multiple values not allowed [InlineData((TransferFormat)42)] // Unexpected value - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task WebSocketsTransportThrowsForInvalidTransferFormat(TransferFormat transferFormat) { using (StartLog(out var loggerFactory)) diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs index 7147d126f8..0e27f32aed 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -68,7 +69,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] + [WebSocketsSupportedCondition] public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol() { var host = BuildWebHost("/socket",