mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	Improve branch coverage
This commit is contained in:
		
							parent
							
								
									92e5a5c6e8
								
							
						
					
					
						commit
						aff0aea60f
					
				@ -1,6 +1,5 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using System.Text.Json.Serialization;
 | 
			
		||||
using Jellyfin.Data.Enums;
 | 
			
		||||
using MediaBrowser.Common.Json.Converters;
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ namespace MediaBrowser.Common.Json.Converters
 | 
			
		||||
                return (int?)converter.ConvertFromString(str);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return JsonSerializer.Deserialize<int?>(ref reader, options);
 | 
			
		||||
            return JsonSerializer.Deserialize<int>(ref reader, options);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										27
									
								
								tests/Jellyfin.Api.Tests/TestPluginWithoutPages.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								tests/Jellyfin.Api.Tests/TestPluginWithoutPages.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
#pragma warning disable CS1591
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using MediaBrowser.Common.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Plugins;
 | 
			
		||||
using MediaBrowser.Model.Plugins;
 | 
			
		||||
using MediaBrowser.Model.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace Jellyfin.Api.Tests
 | 
			
		||||
{
 | 
			
		||||
    public class TestPluginWithoutPages : BasePlugin<BasePluginConfiguration>
 | 
			
		||||
    {
 | 
			
		||||
        public TestPluginWithoutPages(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
 | 
			
		||||
            : base(applicationPaths, xmlSerializer)
 | 
			
		||||
        {
 | 
			
		||||
            Instance = this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static TestPluginWithoutPages? Instance { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public override Guid Id => new Guid("ae95cbe6-bd3d-4d73-8596-490db334611e");
 | 
			
		||||
 | 
			
		||||
        public override string Name => nameof(TestPluginWithoutPages);
 | 
			
		||||
 | 
			
		||||
        public override string Description => "Server test Plugin without web pages.";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
using System.Text.Json.Serialization;
 | 
			
		||||
using Jellyfin.Common.Tests.Models;
 | 
			
		||||
using MediaBrowser.Model.Session;
 | 
			
		||||
@ -8,6 +9,27 @@ namespace Jellyfin.Common.Tests.Json
 | 
			
		||||
{
 | 
			
		||||
    public static class JsonCommaDelimitedArrayTests
 | 
			
		||||
    {
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_String_Null_Success()
 | 
			
		||||
        {
 | 
			
		||||
            var options = new JsonSerializerOptions();
 | 
			
		||||
            var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": null }", options);
 | 
			
		||||
            Assert.Null(value?.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_Empty_Success()
 | 
			
		||||
        {
 | 
			
		||||
            var desiredValue = new GenericBodyArrayModel<string>
 | 
			
		||||
            {
 | 
			
		||||
                Value = Array.Empty<string>()
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var options = new JsonSerializerOptions();
 | 
			
		||||
            var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": """" }", options);
 | 
			
		||||
            Assert.Equal(desiredValue.Value, value?.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_String_Valid_Success()
 | 
			
		||||
        {
 | 
			
		||||
@ -48,6 +70,34 @@ namespace Jellyfin.Common.Tests.Json
 | 
			
		||||
            Assert.Equal(desiredValue.Value, value?.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_GenericCommandType_EmptyEntry_Success()
 | 
			
		||||
        {
 | 
			
		||||
            var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
 | 
			
		||||
            {
 | 
			
		||||
                Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var options = new JsonSerializerOptions();
 | 
			
		||||
            options.Converters.Add(new JsonStringEnumConverter());
 | 
			
		||||
            var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", options);
 | 
			
		||||
            Assert.Equal(desiredValue.Value, value?.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_GenericCommandType_Invalid_Success()
 | 
			
		||||
        {
 | 
			
		||||
            var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
 | 
			
		||||
            {
 | 
			
		||||
                Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var options = new JsonSerializerOptions();
 | 
			
		||||
            options.Converters.Add(new JsonStringEnumConverter());
 | 
			
		||||
            var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", options);
 | 
			
		||||
            Assert.Equal(desiredValue.Value, value?.Value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public static void Deserialize_GenericCommandType_Space_Valid_Success()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
@ -38,6 +38,15 @@ namespace Jellyfin.Common.Tests.Json
 | 
			
		||||
            Assert.Null(result);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("\"8\"", 8)]
 | 
			
		||||
        [InlineData("8", 8)]
 | 
			
		||||
        public void Deserialize_NullableInt_Success(string input, int? expected)
 | 
			
		||||
        {
 | 
			
		||||
            var result = JsonSerializer.Deserialize<int?>(input, _options);
 | 
			
		||||
            Assert.Equal(result, expected);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("\"N/A\"")]
 | 
			
		||||
        [InlineData("null")]
 | 
			
		||||
@ -48,21 +57,11 @@ namespace Jellyfin.Common.Tests.Json
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Theory]
 | 
			
		||||
        [InlineData("\"8\"", 8)]
 | 
			
		||||
        [InlineData("8", 8)]
 | 
			
		||||
        public void Deserialize_Int_Success(string input, int expected)
 | 
			
		||||
        [InlineData("\"Jellyfin\"", "Jellyfin")]
 | 
			
		||||
        public void Deserialize_Normal_String_Success(string input, string expected)
 | 
			
		||||
        {
 | 
			
		||||
            var result = JsonSerializer.Deserialize<int>(input, _options);
 | 
			
		||||
            Assert.Equal(result, expected);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void Deserialize_Normal_String_Success()
 | 
			
		||||
        {
 | 
			
		||||
            const string Input = "\"Jellyfin\"";
 | 
			
		||||
            const string Expected = "Jellyfin";
 | 
			
		||||
            var result = JsonSerializer.Deserialize<string>(Input, _options);
 | 
			
		||||
            Assert.Equal(Expected, result);
 | 
			
		||||
            var result = JsonSerializer.Deserialize<string?>(input, _options);
 | 
			
		||||
            Assert.Equal(expected, result);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user