quantum-space-buddies/QSBTests/EventTests.cs
Mister_Nebula 32f931c440 cleanup
2021-02-13 09:07:39 +00:00

42 lines
982 B
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using QSB.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace QSBTests
{
[TestClass]
public class EventTests
{
[TestMethod]
public void CheckUnreferencedEvents()
{
var qsbAssembly = Assembly.Load("QSB");
var allEventTypes = qsbAssembly
.GetTypes()
.Where(x => typeof(IQSBEvent).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
QSBEventManager.Init();
var eventInstances = (List<IQSBEvent>)typeof(QSBEventManager)
.GetField("_eventList", BindingFlags.NonPublic | BindingFlags.Static)
.GetValue(typeof(QSBEventManager));
var failedTypes = new List<Type>();
foreach (var type in allEventTypes)
{
if (!eventInstances.Any(x => x.GetType() == type))
{
failedTypes.Add(type);
}
}
if (failedTypes.Count > 0)
{
Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name)));
}
}
}
}