From 3e62557959b1233311ab5d4e8f578f84438580d9 Mon Sep 17 00:00:00 2001 From: Greenback Date: Wed, 4 Nov 2020 20:29:55 +0000 Subject: [PATCH] amended testing unit. --- Jellyfin.Networking/Manager/NetworkManager.cs | 14 ++++++++------ MediaBrowser.Common/Net/NetworkExtensions.cs | 2 +- .../NetworkTesting/UnitTesting.cs | 14 +++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.cs index 2ec2a0ba52..289b1dc720 100644 --- a/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/Jellyfin.Networking/Manager/NetworkManager.cs @@ -19,6 +19,8 @@ namespace Jellyfin.Networking.Manager { /// /// Class to take care of network interface management. + /// + /// Note: The normal collection methods and properties will not work with NetCollection. . /// public class NetworkManager : INetworkManager, IDisposable { @@ -925,8 +927,8 @@ namespace Jellyfin.Networking.Manager // Read and parse bind addresses and exclusions, removing ones that don't exist. _bindAddresses = CreateIPCollection(lanAddresses).Union(_interfaceAddresses); _bindExclusions = CreateIPCollection(lanAddresses, true).Union(_interfaceAddresses); - _logger.LogInformation("Using bind addresses: {0}", _bindAddresses); - _logger.LogInformation("Using bind exclusions: {0}", _bindExclusions); + _logger.LogInformation("Using bind addresses: {0}", _bindAddresses.AsString()); + _logger.LogInformation("Using bind exclusions: {0}", _bindExclusions.AsString()); } private void InitialiseRemote(NetworkConfiguration config) @@ -997,9 +999,9 @@ namespace Jellyfin.Networking.Manager _internalInterfaces = CreateCollection(_interfaceAddresses.Where(i => IsInLocalNetwork(i))); } - _logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets); - _logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets); - _logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks()); + _logger.LogInformation("Defined LAN addresses : {0}", _lanSubnets.AsString()); + _logger.LogInformation("Defined LAN exclusions : {0}", _excludedSubnets.AsString()); + _logger.LogInformation("Using LAN addresses: {0}", _lanSubnets.Exclude(_excludedSubnets).AsNetworks().AsString()); } } @@ -1090,7 +1092,7 @@ namespace Jellyfin.Networking.Manager } _logger.LogDebug("Discovered {0} interfaces.", _interfaceAddresses.Count); - _logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses); + _logger.LogDebug("Interfaces addresses : {0}", _interfaceAddresses.AsString()); // If for some reason we don't have an interface info, resolve our DNS name. if (_interfaceAddresses.Count == 0) diff --git a/MediaBrowser.Common/Net/NetworkExtensions.cs b/MediaBrowser.Common/Net/NetworkExtensions.cs index 39499460ea..e801de5eb8 100644 --- a/MediaBrowser.Common/Net/NetworkExtensions.cs +++ b/MediaBrowser.Common/Net/NetworkExtensions.cs @@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Net /// /// The . /// Returns a string representation of this object. - public static string Readable(this NetCollection source) + public static string AsString(this NetCollection source) { var sb = new StringBuilder(); string output = "["; diff --git a/tests/Jellyfin.Networking.Tests/NetworkTesting/UnitTesting.cs b/tests/Jellyfin.Networking.Tests/NetworkTesting/UnitTesting.cs index fe64d1cfce..c96c7defd7 100644 --- a/tests/Jellyfin.Networking.Tests/NetworkTesting/UnitTesting.cs +++ b/tests/Jellyfin.Networking.Tests/NetworkTesting/UnitTesting.cs @@ -71,7 +71,7 @@ namespace NetworkTesting var nm = new NetworkManager(GetMockConfig(conf), new NullLogger()); NetworkManager.MockNetworkSettings = string.Empty; - Assert.True(string.Equals(nm.GetInternalBindAddresses().Readable(), value, StringComparison.Ordinal)); + Assert.True(string.Equals(nm.GetInternalBindAddresses().AsString(), value, StringComparison.Ordinal)); } [Theory] @@ -163,22 +163,22 @@ namespace NetworkTesting // Test included, IP6. NetCollection nc = nm.CreateIPCollection(settings.Split(","), false); - Assert.True(string.Equals(nc.Readable(), result1, System.StringComparison.OrdinalIgnoreCase)); + Assert.True(string.Equals(nc?.AsString(), result1, System.StringComparison.OrdinalIgnoreCase)); // Text excluded, non IP6. nc = nm.CreateIPCollection(settings.Split(","), true); - Assert.True(string.Equals(nc?.Readable(), result3, System.StringComparison.OrdinalIgnoreCase)); + Assert.True(string.Equals(nc?.AsString(), result3, System.StringComparison.OrdinalIgnoreCase)); conf.EnableIPV6 = false; nm.UpdateSettings(conf); // Test included, non IP6. nc = nm.CreateIPCollection(settings.Split(","), false); - Assert.True(string.Equals(nc.Readable(), result2, System.StringComparison.OrdinalIgnoreCase)); + Assert.True(string.Equals(nc?.AsString(), result2, System.StringComparison.OrdinalIgnoreCase)); // Test excluded, including IPv6. nc = nm.CreateIPCollection(settings.Split(","), true); - Assert.True(string.Equals(nc.Readable(), result4, System.StringComparison.OrdinalIgnoreCase)); + Assert.True(string.Equals(nc?.AsString(), result4, System.StringComparison.OrdinalIgnoreCase)); conf.EnableIPV6 = true; nm.UpdateSettings(conf); @@ -186,7 +186,7 @@ namespace NetworkTesting // Test network addresses of collection. nc = nm.CreateIPCollection(settings.Split(","), false); nc = nc.AsNetworks(); - Assert.True(string.Equals(nc.Readable(), result5, System.StringComparison.OrdinalIgnoreCase)); + Assert.True(string.Equals(nc?.AsString(), result5, System.StringComparison.OrdinalIgnoreCase)); } [Theory] @@ -205,7 +205,7 @@ namespace NetworkTesting NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false); NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false); - Assert.True(nc1.Union(nc2).Readable() == result); + Assert.True(nc1.Union(nc2).AsString() == result); } [Theory]