using System; using System.Diagnostics.Contracts; using System.Threading; using System.Threading.Tasks; using Robust.Shared.Configuration; using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Network; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Timing; namespace Robust.UnitTesting; public interface IIntegrationInstance : IDisposable { /// /// Whether the instance is still alive. /// "Alive" indicates that it is able to receive and process commands. /// /// /// Thrown if you did not ensure that the instance is idle via first. /// bool IsAlive { get; } Exception? UnhandledException { get; } EntityManager EntMan { get; } IPrototypeManager ProtoMan { get; } IConfigurationManager CfgMan { get; } ISharedPlayerManager PlayerMan { get; } INetManager NetMan { get; } IMapManager MapMan { get; } IGameTiming Timing { get; } ISawmill Log { get; } /// /// Resolve a dependency inside the instance. /// /// /// Thrown if you did not ensure that the instance is idle via first. /// [Pure] T Resolve(); [Pure] T System() where T : IEntitySystem; TransformComponent Transform(EntityUid uid); MetaDataComponent MetaData(EntityUid uid); MetaDataComponent MetaData(NetEntity uid); TransformComponent Transform(NetEntity uid); Task ExecuteCommand(string cmd); /// /// Wait for the instance to go idle, either through finishing all commands or shutting down/crashing. /// /// /// If true, throw an exception if the server dies on an unhandled exception. /// /// /// /// Thrown if is true and the instance shuts down on an unhandled exception. /// Task WaitIdleAsync(bool throwOnUnhandled = true, CancellationToken cancellationToken = default); /// /// Queue for the server to run n ticks. /// /// The amount of ticks to run. void RunTicks(int ticks); /// /// followed by /// Task WaitRunTicks(int ticks); /// /// Queue for a delegate to be ran inside the main loop of the instance. /// /// /// Do not run NUnit assertions inside . Use instead. /// void Post(Action post); /// Task WaitPost(Action post); /// /// Queue for a delegate to be ran inside the main loop of the instance, /// rethrowing any exceptions in . /// /// /// Exceptions raised inside this callback will be rethrown by . /// This makes it ideal for NUnit assertions, /// since rethrowing the NUnit assertion directly provides less noise. /// void Assert(Action assertion); /// Task WaitAssertion(Action assertion); /// /// Post-test cleanup /// Task Cleanup(); } public interface IClientIntegrationInstance : IIntegrationInstance { IClientNetManager CNetMan => (IClientNetManager) NetMan; ICommonSession? Session { get; } NetUserId? User { get; } EntityUid? AttachedEntity { get; } Task Connect(IServerIntegrationInstance target); } public interface IServerIntegrationInstance : IIntegrationInstance;