aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2022-07-19 21:28:04 +0200
committerShadowghost <Ghost_of_Stone@web.de>2022-07-19 21:28:04 +0200
commit066db8ac7fcece0ab3420b6b6c03e420d22c7306 (patch)
treef23311480feff1053dc990930303ed10fcd01944 /tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs
parentc2902dd1081acd96cf34682ec8a4812ab6146044 (diff)
Migrate NetworkManager and Tests to native .NET IP objects
Diffstat (limited to 'tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs')
-rw-r--r--tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs b/tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs
new file mode 100644
index 000000000..c81fdefe9
--- /dev/null
+++ b/tests/Jellyfin.Networking.Tests/NetworkExtensionsTests.cs
@@ -0,0 +1,53 @@
+using FsCheck;
+using FsCheck.Xunit;
+using MediaBrowser.Common.Net;
+using Xunit;
+
+namespace Jellyfin.Networking.Tests
+{
+ public static class NetworkExtensionsTests
+ {
+ /// <summary>
+ /// Checks IP address formats.
+ /// </summary>
+ /// <param name="address">IP Address.</param>
+ [Theory]
+ [InlineData("127.0.0.1")]
+ [InlineData("127.0.0.1:123")]
+ [InlineData("localhost")]
+ [InlineData("localhost:1345")]
+ [InlineData("www.google.co.uk")]
+ [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517")]
+ [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517/56")]
+ [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517]:124")]
+ [InlineData("fe80::7add:12ff:febb:c67b%16")]
+ [InlineData("[fe80::7add:12ff:febb:c67b%16]:123")]
+ [InlineData("fe80::7add:12ff:febb:c67b%16:123")]
+ [InlineData("[fe80::7add:12ff:febb:c67b%16]")]
+ [InlineData("192.168.1.2/255.255.255.0")]
+ [InlineData("192.168.1.2/24")]
+ public static void TryParse_ValidHostStrings_True(string address)
+ => Assert.True(NetworkExtensions.TryParseHost(address, out _, true, true));
+
+ [Property]
+ public static Property TryParse_IPv4Address_True(IPv4Address address)
+ => NetworkExtensions.TryParseHost(address.Item.ToString(), out _, true, true).ToProperty();
+
+ [Property]
+ public static Property TryParse_IPv6Address_True(IPv6Address address)
+ => NetworkExtensions.TryParseHost(address.Item.ToString(), out _, true, true).ToProperty();
+
+ /// <summary>
+ /// All should be invalid address strings.
+ /// </summary>
+ /// <param name="address">Invalid address strings.</param>
+ [Theory]
+ [InlineData("256.128.0.0.0.1")]
+ [InlineData("127.0.0.1#")]
+ [InlineData("localhost!")]
+ [InlineData("fd23:184f:2029:0:3139:7386:67d7:d517:1231")]
+ [InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517:1231]")]
+ public static void TryParse_InvalidAddressString_False(string address)
+ => Assert.False(NetworkExtensions.TryParseHost(address, out _, true, true));
+ }
+}