Files
crystall-punk-14/Content.IntegrationTests/Tests/GameRules/RuleMaxTimeRestartTest.cs

70 lines
2.5 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
using Content.Server.GameTicking;
2021-06-09 22:19:39 +02:00
using Content.Server.GameTicking.Rules;
using NUnit.Framework;
using Robust.Shared.GameObjects;
2021-12-21 21:23:29 +01:00
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.IntegrationTests.Tests.GameRules
{
[TestFixture]
2021-12-21 21:23:29 +01:00
[TestOf(typeof(MaxTimeRestartRuleSystem))]
public sealed class RuleMaxTimeRestartTest : ContentIntegrationTest
{
[Test]
public async Task RestartTest()
{
var options = new ServerContentIntegrationOption
{
CVarOverrides =
{
2021-12-21 21:23:29 +01:00
["game.lobbyenabled"] = "true",
["game.dummyticker"] = "false",
["game.defaultpreset"] = "", // No preset.
}
};
var server = StartServer(options);
await server.WaitIdleAsync();
var sGameTicker = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<GameTicker>();
2021-12-21 21:23:29 +01:00
var maxTimeMaxTimeRestartRuleSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MaxTimeRestartRuleSystem>();
var sGameTiming = server.ResolveDependency<IGameTiming>();
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
sGameTicker.StartGameRule(IoCManager.Resolve<IPrototypeManager>().Index<GameRulePrototype>(maxTimeMaxTimeRestartRuleSystem.Prototype));
2021-12-21 21:23:29 +01:00
maxTimeMaxTimeRestartRuleSystem.RoundMaxTime = TimeSpan.FromSeconds(3);
sGameTicker.StartRound();
});
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
});
2021-12-21 21:23:29 +01:00
var ticks = sGameTiming.TickRate * (int) Math.Ceiling(maxTimeMaxTimeRestartRuleSystem.RoundMaxTime.TotalSeconds * 1.1f);
await server.WaitRunTicks(ticks);
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PostRound));
});
2021-12-21 21:23:29 +01:00
ticks = sGameTiming.TickRate * (int) Math.Ceiling(maxTimeMaxTimeRestartRuleSystem.RoundEndDelay.TotalSeconds * 1.1f);
await server.WaitRunTicks(ticks);
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
});
}
}
}