mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Enhance BaseItemKindTests
This commit is contained in:
parent
790b284184
commit
ac76519081
@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MediaBrowser.Controller.Entities;
|
using System.Reflection;
|
||||||
|
using Jellyfin.Data.Enums;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Sdk;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Implementations.Tests.BaseItem
|
namespace Jellyfin.Server.Implementations.Tests.BaseItem
|
||||||
{
|
{
|
||||||
@ -11,7 +14,15 @@ namespace Jellyfin.Server.Implementations.Tests.BaseItem
|
|||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[ClassData(typeof(GetBaseItemDescendant))]
|
[ClassData(typeof(GetBaseItemDescendant))]
|
||||||
public void BaseKindEnumTest(Type baseItemDescendantType)
|
public void BaseItemKindEnumTest(Type baseItemType)
|
||||||
|
{
|
||||||
|
var enumValue = Enum.Parse<BaseItemKind>(baseItemType.Name);
|
||||||
|
Assert.True(Enum.IsDefined(typeof(BaseItemKind), enumValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[ClassData(typeof(GetBaseItemDescendant))]
|
||||||
|
public void GetBaseKindEnumTest(Type baseItemDescendantType)
|
||||||
{
|
{
|
||||||
var defaultConstructor = baseItemDescendantType.GetConstructor(Type.EmptyTypes);
|
var defaultConstructor = baseItemDescendantType.GetConstructor(Type.EmptyTypes);
|
||||||
|
|
||||||
@ -24,6 +35,8 @@ namespace Jellyfin.Server.Implementations.Tests.BaseItem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class GetBaseItemDescendant : IEnumerable<object?[]>
|
||||||
|
{
|
||||||
private static bool IsProjectAssemblyName(string? name)
|
private static bool IsProjectAssemblyName(string? name)
|
||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
@ -31,27 +44,49 @@ namespace Jellyfin.Server.Implementations.Tests.BaseItem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return name.Contains("Jellyfin", StringComparison.InvariantCulture)
|
return name.StartsWith("Jellyfin", StringComparison.OrdinalIgnoreCase)
|
||||||
|| name.Contains("Emby", StringComparison.InvariantCulture)
|
|| name.StartsWith("Emby", StringComparison.OrdinalIgnoreCase)
|
||||||
|| name.Contains("MediaBrowser", StringComparison.InvariantCulture)
|
|| name.StartsWith("MediaBrowser", StringComparison.OrdinalIgnoreCase)
|
||||||
|| name.Contains("RSSDP", StringComparison.InvariantCulture);
|
|| name.StartsWith("RSSDP", StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GetBaseItemDescendant : IEnumerable<object?[]>
|
|
||||||
{
|
|
||||||
public IEnumerator<object?[]> GetEnumerator()
|
public IEnumerator<object?[]> GetEnumerator()
|
||||||
{
|
{
|
||||||
var projectAssemblies = AppDomain.CurrentDomain.GetAssemblies()
|
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
.Where(x => IsProjectAssemblyName(x.FullName));
|
foreach (var assembly in loadedAssemblies)
|
||||||
|
|
||||||
foreach (var projectAssembly in projectAssemblies)
|
|
||||||
{
|
{
|
||||||
var baseItemDescendantTypes = projectAssembly.GetTypes()
|
if (IsProjectAssemblyName(assembly.FullName))
|
||||||
.Where(targetType => targetType.IsClass && !targetType.IsAbstract && targetType.IsSubclassOf(typeof(MediaBrowser.Controller.Entities.BaseItem)));
|
|
||||||
|
|
||||||
foreach (var descendantType in baseItemDescendantTypes)
|
|
||||||
{
|
{
|
||||||
yield return new object?[] { descendantType };
|
var baseItemTypes = assembly.GetTypes()
|
||||||
|
.Where(targetType => targetType.IsClass
|
||||||
|
&& !targetType.IsAbstract
|
||||||
|
&& targetType.IsSubclassOf(typeof(MediaBrowser.Controller.Entities.BaseItem)));
|
||||||
|
foreach (var baseItemType in baseItemTypes)
|
||||||
|
{
|
||||||
|
yield return new object?[] { baseItemType };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
if (path == null)
|
||||||
|
{
|
||||||
|
throw new NullException("Assembly location is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string dll in Directory.GetFiles(path, "*.dll"))
|
||||||
|
{
|
||||||
|
var assembly = Assembly.LoadFile(dll);
|
||||||
|
if (IsProjectAssemblyName(assembly.FullName))
|
||||||
|
{
|
||||||
|
var baseItemTypes = assembly.GetTypes()
|
||||||
|
.Where(targetType => targetType.IsClass
|
||||||
|
&& !targetType.IsAbstract
|
||||||
|
&& targetType.IsSubclassOf(typeof(MediaBrowser.Controller.Entities.BaseItem)));
|
||||||
|
foreach (var baseItemType in baseItemTypes)
|
||||||
|
{
|
||||||
|
yield return new object?[] { baseItemType };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user