Improve integration testing
This commit is contained in:
10
Content.Client/ClientModuleTestingCallbacks.cs
Normal file
10
Content.Client/ClientModuleTestingCallbacks.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using Content.Shared;
|
||||
|
||||
namespace Content.Client
|
||||
{
|
||||
public sealed class ClientModuleTestingCallbacks : SharedModuleTestingCallbacks
|
||||
{
|
||||
public Action ClientBeforeIoC { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,12 @@ namespace Content.Client
|
||||
IoCManager.Register<IParallaxManager, ParallaxManager>();
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<IEscapeMenuOwner, EscapeMenuOwner>();
|
||||
if (TestingCallbacks != null)
|
||||
{
|
||||
var cast = (ClientModuleTestingCallbacks) TestingCallbacks;
|
||||
cast.ClientBeforeIoC?.Invoke();
|
||||
}
|
||||
|
||||
IoCManager.BuildGraph();
|
||||
|
||||
IoCManager.Resolve<IParallaxManager>().LoadParallax();
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Client.Interfaces.Parallax;
|
||||
using ICSharpCode.SharpZipLib.Checksum;
|
||||
using Nett;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.Primitives;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Log;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
@@ -16,11 +15,12 @@ using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Parallax
|
||||
{
|
||||
public class ParallaxManager : IParallaxManager
|
||||
internal sealed class ParallaxManager : IParallaxManager, IPostInjectInit
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IResourceCache _resourceCache;
|
||||
[Dependency] private readonly ILogManager _logManager;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private static readonly ResourcePath ParallaxConfigPath = new ResourcePath("/parallax_config.toml");
|
||||
@@ -34,6 +34,11 @@ namespace Content.Client.Parallax
|
||||
|
||||
public async void LoadParallax()
|
||||
{
|
||||
if (!_configurationManager.GetCVar<bool>("parallax.enabled"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MemoryStream configStream = null;
|
||||
string contents;
|
||||
TomlTable table;
|
||||
@@ -99,5 +104,10 @@ namespace Content.Client.Parallax
|
||||
|
||||
OnTextureLoaded?.Invoke(ParallaxTexture);
|
||||
}
|
||||
|
||||
public void PostInject()
|
||||
{
|
||||
_configurationManager.RegisterCVar("parallax.enabled", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
Content.IntegrationTests/ConnectTest.cs
Normal file
57
Content.IntegrationTests/ConnectTest.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.UnitTesting;
|
||||
|
||||
namespace Content.IntegrationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ConnectTest : ContentIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestConnect()
|
||||
{
|
||||
var client = StartClient();
|
||||
var server = StartServer();
|
||||
|
||||
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
|
||||
|
||||
// Connect.
|
||||
|
||||
client.SetConnectTarget(server);
|
||||
|
||||
client.Post(() => IoCManager.Resolve<IClientNetManager>().ClientConnect(null, 0, null));
|
||||
|
||||
// Run some ticks for the handshake to complete and such.
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
server.RunTicks(1);
|
||||
await server.WaitIdleAsync();
|
||||
client.RunTicks(1);
|
||||
await client.WaitIdleAsync();
|
||||
}
|
||||
|
||||
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
|
||||
|
||||
// Basic checks to ensure that they're connected and data got replicated.
|
||||
|
||||
var playerManager = server.ResolveDependency<IPlayerManager>();
|
||||
Assert.That(playerManager.PlayerCount, Is.EqualTo(1));
|
||||
Assert.That(playerManager.GetAllPlayers().First().Status, Is.EqualTo(SessionStatus.InGame));
|
||||
|
||||
var clEntityManager = client.ResolveDependency<IEntityManager>();
|
||||
var svEntityManager = server.ResolveDependency<IEntityManager>();
|
||||
|
||||
var lastSvEntity = svEntityManager.GetEntities().Last();
|
||||
var lastClEntity = clEntityManager.GetEntity(lastSvEntity.Uid);
|
||||
|
||||
Assert.That(lastClEntity.Transform.GridPosition, Is.EqualTo(lastSvEntity.Transform.GridPosition));
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Content.IntegrationTests/ContentIntegrationTest.cs
Normal file
27
Content.IntegrationTests/ContentIntegrationTest.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Content.Client;
|
||||
using Content.Client.Interfaces.Parallax;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.UnitTesting;
|
||||
|
||||
namespace Content.IntegrationTests
|
||||
{
|
||||
public abstract class ContentIntegrationTest : RobustIntegrationTest
|
||||
{
|
||||
protected override ClientIntegrationInstance StartClient(ClientIntegrationOptions options = null)
|
||||
{
|
||||
options = options ?? new ClientIntegrationOptions();
|
||||
options.BeforeStart += () =>
|
||||
{
|
||||
IoCManager.Resolve<IModLoader>().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks
|
||||
{
|
||||
ClientBeforeIoC = () =>
|
||||
{
|
||||
IoCManager.Register<IParallaxManager, DummyParallaxManager>(true);
|
||||
}
|
||||
});
|
||||
};
|
||||
return base.StartClient(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Content.IntegrationTests/DummyParallaxManager.cs
Normal file
25
Content.IntegrationTests/DummyParallaxManager.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Content.Client.Interfaces.Parallax;
|
||||
using Robust.Client.Graphics;
|
||||
|
||||
namespace Content.IntegrationTests
|
||||
{
|
||||
public sealed class DummyParallaxManager : IParallaxManager
|
||||
{
|
||||
public event Action<Texture> OnTextureLoaded
|
||||
{
|
||||
add
|
||||
{
|
||||
}
|
||||
remove
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Texture ParallaxTexture => null;
|
||||
|
||||
public void LoadParallax()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Robust.UnitTesting;
|
||||
namespace Content.IntegrationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class StartTest : RobustIntegrationTest
|
||||
public class StartTest : ContentIntegrationTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Test that the server starts.
|
||||
@@ -15,8 +15,6 @@ namespace Content.IntegrationTests
|
||||
public async Task TestServerStart()
|
||||
{
|
||||
var server = StartServer();
|
||||
await server.WaitIdleAsync();
|
||||
Assert.That(server.IsAlive);
|
||||
server.RunTicks(5);
|
||||
await server.WaitIdleAsync();
|
||||
Assert.That(server.IsAlive);
|
||||
@@ -25,7 +23,6 @@ namespace Content.IntegrationTests
|
||||
server.Stop();
|
||||
await server.WaitIdleAsync();
|
||||
Assert.That(!server.IsAlive);
|
||||
Assert.That(server.UnhandledException, Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
|
||||
@@ -191,6 +191,11 @@ namespace Content.Server
|
||||
IoCManager.Register<IGameTicker, GameTicker>();
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<IMoMMILink, MoMMILink>();
|
||||
if (TestingCallbacks != null)
|
||||
{
|
||||
var cast = (ServerModuleTestingCallbacks) TestingCallbacks;
|
||||
cast.ServerBeforeIoC?.Invoke();
|
||||
}
|
||||
IoCManager.BuildGraph();
|
||||
|
||||
_gameTicker = IoCManager.Resolve<IGameTicker>();
|
||||
|
||||
10
Content.Server/ServerModuleTestingCallbacks.cs
Normal file
10
Content.Server/ServerModuleTestingCallbacks.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using Content.Shared;
|
||||
|
||||
namespace Content.Server
|
||||
{
|
||||
public sealed class ServerModuleTestingCallbacks : SharedModuleTestingCallbacks
|
||||
{
|
||||
public Action ServerBeforeIoC { get; set; }
|
||||
}
|
||||
}
|
||||
10
Content.Shared/SharedModuleTestingCallbacks.cs
Normal file
10
Content.Shared/SharedModuleTestingCallbacks.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using Robust.Shared.ContentPack;
|
||||
|
||||
namespace Content.Shared
|
||||
{
|
||||
public abstract class SharedModuleTestingCallbacks : ModuleTestingCallbacks
|
||||
{
|
||||
public Action SharedBeforeIoC { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user