|
| 1 | +using System; |
| 2 | +using FluentAssertions; |
| 3 | +using GraphQL.Client.Http; |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace GraphQL.Integration.Tests |
| 7 | +{ |
| 8 | + public class UriExtensionTests |
| 9 | + { |
| 10 | + [Theory] |
| 11 | + [InlineData("http://thats-not-a-websocket-url.net", false)] |
| 12 | + [InlineData("https://thats-not-a-websocket-url.net", false)] |
| 13 | + [InlineData("ftp://thats-not-a-websocket-url.net", false)] |
| 14 | + [InlineData("ws://that-is-a-websocket-url.net", true)] |
| 15 | + [InlineData("wss://that-is-a-websocket-url.net", true)] |
| 16 | + [InlineData("WS://that-is-a-websocket-url.net", true)] |
| 17 | + [InlineData("WSS://that-is-a-websocket-url.net", true)] |
| 18 | + public void HasWebSocketSchemaTest(string url, bool result) |
| 19 | + { |
| 20 | + new Uri(url).HasWebSocketScheme().Should().Be(result); |
| 21 | + } |
| 22 | + |
| 23 | + [Theory] |
| 24 | + [InlineData("http://this-url-can-be-converted.net", true, "ws://this-url-can-be-converted.net")] |
| 25 | + [InlineData("https://this-url-can-be-converted.net", true, "wss://this-url-can-be-converted.net")] |
| 26 | + [InlineData("HTTP://this-url-can-be-converted.net", true, "ws://this-url-can-be-converted.net")] |
| 27 | + [InlineData("HTTPS://this-url-can-be-converted.net", true, "wss://this-url-can-be-converted.net")] |
| 28 | + [InlineData("ws://this-url-can-be-converted.net", true, "ws://this-url-can-be-converted.net")] |
| 29 | + [InlineData("wss://this-url-can-be-converted.net", true, "wss://this-url-can-be-converted.net")] |
| 30 | + [InlineData("https://this-url-can-be-converted.net/and/all/elements/?are#preserved", true, "wss://this-url-can-be-converted.net/and/all/elements/?are#preserved")] |
| 31 | + [InlineData("ftp://this-url-cannot-be-converted.net", false, null)] |
| 32 | + // AppSync example |
| 33 | + [InlineData("wss://example1234567890000.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=123456789ABCDEF&payload=e30=", true, "wss://example1234567890000.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=123456789ABCDEF&payload=e30=")] |
| 34 | + public void GetWebSocketUriTest(string input, bool canConvert, string result) |
| 35 | + { |
| 36 | + var inputUri = new Uri(input); |
| 37 | + if (canConvert) |
| 38 | + { |
| 39 | + inputUri.GetWebSocketUri().Should().BeEquivalentTo(new Uri(result)); |
| 40 | + } |
| 41 | + else |
| 42 | + { |
| 43 | + inputUri.Invoking(uri => uri.GetWebSocketUri()).Should().Throw<NotSupportedException>(); |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments