diff --git a/Content.Client/ClientModuleTestingCallbacks.cs b/Content.Client/ClientModuleTestingCallbacks.cs new file mode 100644 index 0000000000..8b3d85a49c --- /dev/null +++ b/Content.Client/ClientModuleTestingCallbacks.cs @@ -0,0 +1,10 @@ +using System; +using Content.Shared; + +namespace Content.Client +{ + public sealed class ClientModuleTestingCallbacks : SharedModuleTestingCallbacks + { + public Action ClientBeforeIoC { get; set; } + } +} diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index f33b70116f..dc45979778 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -139,6 +139,12 @@ namespace Content.Client IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + if (TestingCallbacks != null) + { + var cast = (ClientModuleTestingCallbacks) TestingCallbacks; + cast.ClientBeforeIoC?.Invoke(); + } + IoCManager.BuildGraph(); IoCManager.Resolve().LoadParallax(); diff --git a/Content.Client/Parallax/ParallaxManager.cs b/Content.Client/Parallax/ParallaxManager.cs index 0c33a5b2bd..74d18d0f47 100644 --- a/Content.Client/Parallax/ParallaxManager.cs +++ b/Content.Client/Parallax/ParallaxManager.cs @@ -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("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); + } } } diff --git a/Content.IntegrationTests/ConnectTest.cs b/Content.IntegrationTests/ConnectTest.cs new file mode 100644 index 0000000000..5a71a03339 --- /dev/null +++ b/Content.IntegrationTests/ConnectTest.cs @@ -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().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(); + Assert.That(playerManager.PlayerCount, Is.EqualTo(1)); + Assert.That(playerManager.GetAllPlayers().First().Status, Is.EqualTo(SessionStatus.InGame)); + + var clEntityManager = client.ResolveDependency(); + var svEntityManager = server.ResolveDependency(); + + var lastSvEntity = svEntityManager.GetEntities().Last(); + var lastClEntity = clEntityManager.GetEntity(lastSvEntity.Uid); + + Assert.That(lastClEntity.Transform.GridPosition, Is.EqualTo(lastSvEntity.Transform.GridPosition)); + } + } +} diff --git a/Content.IntegrationTests/Content.IntegrationTests.csproj b/Content.IntegrationTests/Content.IntegrationTests.csproj index 39bfabf0c3..f5bdd9eca7 100644 --- a/Content.IntegrationTests/Content.IntegrationTests.csproj +++ b/Content.IntegrationTests/Content.IntegrationTests.csproj @@ -7,19 +7,19 @@ x86;x64 - - - + + + - - - - - - - - - + + + + + + + + + diff --git a/Content.IntegrationTests/ContentIntegrationTest.cs b/Content.IntegrationTests/ContentIntegrationTest.cs new file mode 100644 index 0000000000..e4ed5ee117 --- /dev/null +++ b/Content.IntegrationTests/ContentIntegrationTest.cs @@ -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().SetModuleBaseCallbacks(new ClientModuleTestingCallbacks + { + ClientBeforeIoC = () => + { + IoCManager.Register(true); + } + }); + }; + return base.StartClient(options); + } + } +} diff --git a/Content.IntegrationTests/DummyParallaxManager.cs b/Content.IntegrationTests/DummyParallaxManager.cs new file mode 100644 index 0000000000..3c4275deab --- /dev/null +++ b/Content.IntegrationTests/DummyParallaxManager.cs @@ -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 OnTextureLoaded + { + add + { + } + remove + { + } + } + + public Texture ParallaxTexture => null; + + public void LoadParallax() + { + } + } +} diff --git a/Content.IntegrationTests/StartTest.cs b/Content.IntegrationTests/StartTest.cs index 2906099bfa..68de733ae8 100644 --- a/Content.IntegrationTests/StartTest.cs +++ b/Content.IntegrationTests/StartTest.cs @@ -6,7 +6,7 @@ using Robust.UnitTesting; namespace Content.IntegrationTests { [TestFixture] - public class StartTest : RobustIntegrationTest + public class StartTest : ContentIntegrationTest { /// /// 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); } /// diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index 25ef19f08a..bef98d239a 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -1,4 +1,4 @@ - + net472 diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 4b8c401f2d..1b930d76fe 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -191,6 +191,11 @@ namespace Content.Server IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + if (TestingCallbacks != null) + { + var cast = (ServerModuleTestingCallbacks) TestingCallbacks; + cast.ServerBeforeIoC?.Invoke(); + } IoCManager.BuildGraph(); _gameTicker = IoCManager.Resolve(); diff --git a/Content.Server/ServerModuleTestingCallbacks.cs b/Content.Server/ServerModuleTestingCallbacks.cs new file mode 100644 index 0000000000..4777389700 --- /dev/null +++ b/Content.Server/ServerModuleTestingCallbacks.cs @@ -0,0 +1,10 @@ +using System; +using Content.Shared; + +namespace Content.Server +{ + public sealed class ServerModuleTestingCallbacks : SharedModuleTestingCallbacks + { + public Action ServerBeforeIoC { get; set; } + } +} diff --git a/Content.Shared/SharedModuleTestingCallbacks.cs b/Content.Shared/SharedModuleTestingCallbacks.cs new file mode 100644 index 0000000000..d47b65544c --- /dev/null +++ b/Content.Shared/SharedModuleTestingCallbacks.cs @@ -0,0 +1,10 @@ +using System; +using Robust.Shared.ContentPack; + +namespace Content.Shared +{ + public abstract class SharedModuleTestingCallbacks : ModuleTestingCallbacks + { + public Action SharedBeforeIoC { get; set; } + } +}