blob: 3f56c82f4d1ed00a3a12f5dcf965164f19d18e56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Entities;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.BaseItem
{
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 = (MediaBrowser.Controller.Entities.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(MediaBrowser.Controller.Entities.BaseItem)));
foreach (var descendantType in baseItemDescendantTypes)
{
yield return new object?[] { descendantType };
}
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}
|