Improve integration testing
This commit is contained in:
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,19 @@
|
||||
<Platforms>x86;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.12.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Content.Client\Content.Client.csproj"/>
|
||||
<ProjectReference Include="..\Content.Server\Content.Server.csproj"/>
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj"/>
|
||||
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj"/>
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj"/>
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj"/>
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj"/>
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj"/>
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj"/>
|
||||
<ProjectReference Include="..\Content.Client\Content.Client.csproj" />
|
||||
<ProjectReference Include="..\Content.Server\Content.Server.csproj" />
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
|
||||
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user