mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using MediaBrowser.Controller.Entities;
|
||
|
using Xunit;
|
||
|
|
||
|
namespace Jellyfin.Server.Tests
|
||
|
{
|
||
|
public class BaseItemKindTests
|
||
|
{
|
||
|
[Theory]
|
||
|
[ClassData(typeof(GetBaseItemDescendant))]
|
||
|
public void BaseKindEnumTest(Type baseItemDescendantType)
|
||
|
{
|
||
|
var defaultConstructor = baseItemDescendantType.GetConstructor(Type.EmptyTypes);
|
||
|
|
||
|
Assert.NotNull(defaultConstructor);
|
||
|
if (defaultConstructor != null)
|
||
|
{
|
||
|
var instance = (BaseItem)defaultConstructor.Invoke(null);
|
||
|
var exception = Record.Exception(() => instance.GetBaseItemKind());
|
||
|
Assert.Null(exception);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static bool IsProjectAssemblyName(string? name)
|
||
|
{
|
||
|
if (name == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return name.Contains("Jellyfin", StringComparison.InvariantCulture)
|
||
|
|| name.Contains("Emby", StringComparison.InvariantCulture)
|
||
|
|| name.Contains("MediaBrowser", StringComparison.InvariantCulture)
|
||
|
|| name.Contains("RSSDP", StringComparison.InvariantCulture);
|
||
|
}
|
||
|
|
||
|
private class GetBaseItemDescendant : IEnumerable<object?[]>
|
||
|
{
|
||
|
public IEnumerator<object?[]> GetEnumerator()
|
||
|
{
|
||
|
var projectAssemblies = AppDomain.CurrentDomain.GetAssemblies()
|
||
|
.Where(x => IsProjectAssemblyName(x.FullName));
|
||
|
|
||
|
foreach (var projectAssembly in projectAssemblies)
|
||
|
{
|
||
|
var baseItemDescendantTypes = projectAssembly.GetTypes()
|
||
|
.Where(targetType => targetType.IsClass && !targetType.IsAbstract && targetType.IsSubclassOf(typeof(BaseItem)));
|
||
|
|
||
|
foreach (var descendantType in baseItemDescendantTypes)
|
||
|
{
|
||
|
yield return new object?[] { descendantType };
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||
|
}
|
||
|
}
|
||
|
}
|