using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using NUnit.Framework; using Robust.Shared.ContentPack; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Reflection; using Robust.Shared.IoC; namespace Robust.UnitTesting { public enum UnitTestProject { Server, Client } [Parallelizable] public abstract partial class RobustUnitTest { public virtual UnitTestProject Project => UnitTestProject.Server; [OneTimeSetUp] public void BaseSetup() { // Clear state across tests. IoCManager.InitThread(); IoCManager.Clear(); RegisterIoC(); var assemblies = new List(4); switch (Project) { case UnitTestProject.Client: assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Client")); break; case UnitTestProject.Server: assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Server")); break; default: throw new NotSupportedException($"Unknown testing project: {Project}"); } assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared")); assemblies.Add(Assembly.GetExecutingAssembly()); IoCManager.Resolve().LoadAssemblies(assemblies); // Required components for the engine to work var compFactory = IoCManager.Resolve(); if (!compFactory.AllRegisteredTypes.Contains(typeof(MetaDataComponent))) { compFactory.Register(); compFactory.RegisterReference(); } } /// /// Called after all IoC registration has been done, but before the graph has been built. /// This allows one to add new IoC types or overwrite existing ones if needed. /// protected virtual void OverrideIoC() { } } }