فهرست منبع

Updated tests to .Net5

Greenback 4 سال پیش
والد
کامیت
979de240cb

+ 0 - 3
Emby.Dlna/Main/DlnaEntryPoint.cs

@@ -259,8 +259,6 @@ namespace Emby.Dlna.Main
 
 
         private void RegisterServerEndpoints()
         private void RegisterServerEndpoints()
         {
         {
-            var addresses = await _appHost.GetLocalIpAddresses().ConfigureAwait(false);
-
             var udn = CreateUuid(_appHost.SystemId);
             var udn = CreateUuid(_appHost.SystemId);
             var descriptorUri = "/dlna/" + udn + "/description.xml";
             var descriptorUri = "/dlna/" + udn + "/description.xml";
 
 
@@ -292,7 +290,6 @@ namespace Emby.Dlna.Main
 
 
                 _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);
                 _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);
 
 
-                var descriptorUri = "/dlna/" + udn + "/description.xml";
                 var uri = new Uri(_appHost.GetSmartApiUrl(address.Address) + descriptorUri);
                 var uri = new Uri(_appHost.GetSmartApiUrl(address.Address) + descriptorUri);
 
 
                 var device = new SsdpRootDevice
                 var device = new SsdpRootDevice

+ 1 - 1
Jellyfin.Networking/Jellyfin.Networking.csproj

@@ -1,6 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
   <PropertyGroup>
-    <TargetFramework>netstandard2.1</TargetFramework>
+    <TargetFramework>net5.0</TargetFramework>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>

+ 16 - 5
tests/Jellyfin.Networking.Tests/NetworkTesting/Jellyfin.Networking.Tests.csproj

@@ -6,23 +6,34 @@
   </PropertyGroup>
   </PropertyGroup>
 
 
   <PropertyGroup>
   <PropertyGroup>
-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>net5.0</TargetFramework>
     <IsPackable>false</IsPackable>
     <IsPackable>false</IsPackable>
-    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <Nullable>enable</Nullable>
     <Nullable>enable</Nullable>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit" Version="2.4.1" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
-    <PackageReference Include="coverlet.collector" Version="1.2.1" />
+    <PackageReference Include="coverlet.collector" Version="1.3.0" />
     <PackageReference Include="Moq" Version="4.14.5" />
     <PackageReference Include="Moq" Version="4.14.5" />
   </ItemGroup>
   </ItemGroup>
 
 
+  <!-- Code Analyzers-->
+  <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" />
+    <PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
+    <PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
+  </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
     <ProjectReference Include="..\..\..\Emby.Server.Implementations\Emby.Server.Implementations.csproj" />
     <ProjectReference Include="..\..\..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
     <ProjectReference Include="..\..\..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
   </ItemGroup>
   </ItemGroup>
-
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <CodeAnalysisRuleSet>../../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DefineConstants>DEBUG</DefineConstants>
+  </PropertyGroup>
 </Project>
 </Project>

+ 76 - 16
tests/Jellyfin.Networking.Tests/NetworkTesting/UnitTesting.cs

@@ -43,8 +43,7 @@ namespace NetworkTesting
             return false;
             return false;
         }
         }
 
 
-
-        private IConfigurationManager GetMockConfig(NetworkConfiguration conf)
+        private static IConfigurationManager GetMockConfig(NetworkConfiguration conf)
         {
         {
             var configManager = new Mock<IConfigurationManager>
             var configManager = new Mock<IConfigurationManager>
             {
             {
@@ -64,11 +63,11 @@ namespace NetworkTesting
             {
             {
                 EnableIPV6 = true,
                 EnableIPV6 = true,
                 EnableIPV4 = true,
                 EnableIPV4 = true,
-                LocalNetworkSubnets = lan.Split(';')
+                LocalNetworkSubnets = lan?.Split(';') ?? throw new ArgumentNullException(nameof(lan))
             };
             };
 
 
             NetworkManager.MockNetworkSettings = interfaces;
             NetworkManager.MockNetworkSettings = interfaces;
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
             NetworkManager.MockNetworkSettings = string.Empty;
             NetworkManager.MockNetworkSettings = string.Empty;
 
 
             Assert.True(string.Equals(nm.GetInternalBindAddresses().AsString(), value, StringComparison.Ordinal));
             Assert.True(string.Equals(nm.GetInternalBindAddresses().AsString(), value, StringComparison.Ordinal));
@@ -78,6 +77,11 @@ namespace NetworkTesting
         [InlineData("192.168.10.0/24, !192.168.10.60/32", "192.168.10.60")]
         [InlineData("192.168.10.0/24, !192.168.10.60/32", "192.168.10.60")]
         public void TextIsInNetwork(string network, string value)
         public void TextIsInNetwork(string network, string value)
         {
         {
+            if (network == null)
+            {
+                throw new ArgumentNullException(nameof(network));
+            }
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 EnableIPV6 = true,
                 EnableIPV6 = true,
@@ -85,7 +89,7 @@ namespace NetworkTesting
                 LocalNetworkSubnets = network.Split(',')
                 LocalNetworkSubnets = network.Split(',')
             };
             };
 
 
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
 
 
             Assert.True(!nm.IsInLocalNetwork(value));
             Assert.True(!nm.IsInLocalNetwork(value));
         }
         }
@@ -153,16 +157,21 @@ namespace NetworkTesting
             "[192.158.0.0/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]")]
             "[192.158.0.0/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]")]
         public void TestCollections(string settings, string result1, string result2, string result3, string result4, string result5)
         public void TestCollections(string settings, string result1, string result2, string result3, string result4, string result5)
         {
         {
+            if (settings == null)
+            {
+                throw new ArgumentNullException(nameof(settings));
+            }
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 EnableIPV6 = true,
                 EnableIPV6 = true,
                 EnableIPV4 = true,
                 EnableIPV4 = true,
             };           
             };           
 
 
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
 
 
             // Test included, IP6.
             // Test included, IP6.
-            NetCollection nc = nm.CreateIPCollection(settings.Split(","), false);
+            NetCollection nc = nm.CreateIPCollection(settings.Split(","), false); 
             Assert.True(string.Equals(nc?.AsString(), result1, System.StringComparison.OrdinalIgnoreCase));
             Assert.True(string.Equals(nc?.AsString(), result1, System.StringComparison.OrdinalIgnoreCase));
 
 
             // Text excluded, non IP6.
             // Text excluded, non IP6.
@@ -194,13 +203,29 @@ namespace NetworkTesting
         [InlineData("127.0.0.1", "127.0.0.1/8", "[127.0.0.1/32]")]
         [InlineData("127.0.0.1", "127.0.0.1/8", "[127.0.0.1/32]")]
         public void UnionCheck(string settings, string compare, string result)
         public void UnionCheck(string settings, string compare, string result)
         {
         {
+            if (settings == null)
+            {
+                throw new ArgumentNullException(nameof(settings));
+            }
+
+            if (compare == null)
+            {
+                throw new ArgumentNullException(nameof(compare));
+            }
+
+            if (result == null)
+            {
+                throw new ArgumentNullException(nameof(result));
+            }
+
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 EnableIPV6 = true,
                 EnableIPV6 = true,
                 EnableIPV4 = true,
                 EnableIPV4 = true,
             };
             };
 
 
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
 
 
             NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false);
             NetCollection nc1 = nm.CreateIPCollection(settings.Split(","), false);
             NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false);
             NetCollection nc2 = nm.CreateIPCollection(compare.Split(","), false);
@@ -276,12 +301,7 @@ namespace NetworkTesting
         {
         {
             Assert.True(TryParse(network, out IPObject? networkObj));
             Assert.True(TryParse(network, out IPObject? networkObj));
             Assert.True(TryParse(ip, out IPObject? ipObj));
             Assert.True(TryParse(ip, out IPObject? ipObj));
-
-#pragma warning disable CS8602 // Dereference of a possibly null reference.
-#pragma warning disable CS8604 // Possible null reference argument.
             Assert.True(networkObj.Contains(ipObj));
             Assert.True(networkObj.Contains(ipObj));
-#pragma warning restore CS8604 // Possible null reference argument.
-#pragma warning restore CS8602 // Dereference of a possibly null reference.
         }
         }
 
 
         [Theory]
         [Theory]
@@ -293,13 +313,28 @@ namespace NetworkTesting
 
 
         public void TestMatches(string source, string dest, string result)
         public void TestMatches(string source, string dest, string result)
         {
         {
+            if (source == null)
+            {
+                throw new ArgumentNullException(nameof(source));
+            }
+
+            if (dest == null)
+            {
+                throw new ArgumentNullException(nameof(dest));
+            }
+
+            if (result == null)
+            {
+                throw new ArgumentNullException(nameof(result));
+            }
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 EnableIPV6 = true,
                 EnableIPV6 = true,
                 EnableIPV4 = true
                 EnableIPV4 = true
             };
             };
 
 
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
 
 
             // Test included, IP6.
             // Test included, IP6.
             NetCollection ncSource = nm.CreateIPCollection(source.Split(","));
             NetCollection ncSource = nm.CreateIPCollection(source.Split(","));
@@ -343,6 +378,21 @@ namespace NetworkTesting
         [InlineData("", "", false, "eth16")]
         [InlineData("", "", false, "eth16")]
         public void TestBindInterfaces(string source, string bindAddresses, bool ipv6enabled, string result)
         public void TestBindInterfaces(string source, string bindAddresses, bool ipv6enabled, string result)
         {
         {
+            if (source == null)
+            {
+                throw new ArgumentNullException(nameof(source));
+            }
+
+            if (bindAddresses == null)
+            {
+                throw new ArgumentNullException(nameof(bindAddresses));
+            }
+
+            if (result == null)
+            {
+                throw new ArgumentNullException(nameof(result));
+            }
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 LocalNetworkAddresses = bindAddresses.Split(','),
                 LocalNetworkAddresses = bindAddresses.Split(','),
@@ -351,7 +401,7 @@ namespace NetworkTesting
             };
             };
 
 
             NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16:200.200.200.200/24,11,eth11";
             NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16:200.200.200.200/24,11,eth11";
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
             NetworkManager.MockNetworkSettings = string.Empty;
             NetworkManager.MockNetworkSettings = string.Empty;
 
 
             _ = nm.TryParseInterface(result, out NetCollection? resultObj);
             _ = nm.TryParseInterface(result, out NetCollection? resultObj);
@@ -398,6 +448,16 @@ namespace NetworkTesting
 
 
         public void TestBindInterfaceOverrides(string source, string lan, string bindAddresses, bool ipv6enabled, string publishedServers, string result)
         public void TestBindInterfaceOverrides(string source, string lan, string bindAddresses, bool ipv6enabled, string publishedServers, string result)
         {
         {
+            if (lan == null)
+            {
+                throw new ArgumentNullException(nameof(lan));
+            }
+
+            if (bindAddresses == null)
+            {
+                throw new ArgumentNullException(nameof(bindAddresses));
+            }
+
             var conf = new NetworkConfiguration()
             var conf = new NetworkConfiguration()
             {
             {
                 LocalNetworkSubnets = lan.Split(','),
                 LocalNetworkSubnets = lan.Split(','),
@@ -408,7 +468,7 @@ namespace NetworkTesting
             };
             };
 
 
             NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16:200.200.200.200/24,11,eth11";
             NetworkManager.MockNetworkSettings = "192.168.1.208/24,-16,eth16:200.200.200.200/24,11,eth11";
-            var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
+            using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
             NetworkManager.MockNetworkSettings = string.Empty;
             NetworkManager.MockNetworkSettings = string.Empty;
 
 
             if (nm.TryParseInterface(result, out NetCollection? resultObj) && resultObj != null)
             if (nm.TryParseInterface(result, out NetCollection? resultObj) && resultObj != null)