mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
more rcon tweaks, and starting on unit tests for commands bleh
This commit is contained in:
@ -1,13 +1,26 @@
|
||||
using SharedLibraryCore.Objects;
|
||||
using IW4MAdmin.Application;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Objects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
[Collection("ManagerCollection")]
|
||||
public class ClientTests
|
||||
{
|
||||
readonly ApplicationManager Manager;
|
||||
const int TestTimeout = 5000;
|
||||
|
||||
public ClientTests(ManagerFixture fixture)
|
||||
{
|
||||
Manager = fixture.Manager;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetAdditionalPropertyShouldSucceed()
|
||||
{
|
||||
@ -25,5 +38,68 @@ namespace Tests
|
||||
|
||||
Assert.True(client.GetAdditionalProperty<int>("NewProp") == 5, "added property does not match retrieved property");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WarnPlayerShouldSucceed()
|
||||
{
|
||||
while (!Manager.IsInitialized)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
var client = Manager.Servers.First().GetPlayersAsList().FirstOrDefault();
|
||||
|
||||
Assert.False(client == null, "no client found to warn");
|
||||
|
||||
var warnEvent = client.Warn("test warn", new Player() { ClientId = 1, Level = Player.Permission.Console });
|
||||
warnEvent.OnProcessed.Wait(TestTimeout);
|
||||
|
||||
Assert.True(client.Warnings == 1 ||
|
||||
warnEvent.Failed, "warning did not get applied");
|
||||
|
||||
warnEvent = client.Warn("test warn", new Player() { ClientId = 1, Level = Player.Permission.Banned });
|
||||
warnEvent.OnProcessed.Wait(TestTimeout);
|
||||
|
||||
Assert.True(warnEvent.FailReason == GameEvent.EventFailReason.Permission &&
|
||||
client.Warnings == 1, "warning was applied without proper permissions");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReportPlayerShouldSucceed()
|
||||
{
|
||||
while (!Manager.IsInitialized)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
var client = Manager.Servers.First().GetPlayersAsList().FirstOrDefault();
|
||||
|
||||
Assert.False(client == null, "no client found to report");
|
||||
|
||||
// succeed
|
||||
var reportEvent = client.Report("test report", new Player() { ClientId = 1, Level = Player.Permission.Console });
|
||||
reportEvent.OnProcessed.Wait(TestTimeout);
|
||||
|
||||
Assert.True(!reportEvent.Failed &&
|
||||
client.CurrentServer.Reports.Count(r => r.Target.NetworkId == client.NetworkId) == 1, $"report was not applied [{reportEvent.FailReason.ToString()}]");
|
||||
|
||||
// fail
|
||||
reportEvent = client.Report("test report", new Player() { ClientId = 2, Level = Player.Permission.Banned });
|
||||
|
||||
Assert.True(reportEvent.FailReason == GameEvent.EventFailReason.Permission &&
|
||||
client.CurrentServer.Reports.Count(r => r.Target.NetworkId == client.NetworkId) == 1, $"report was applied without proper permission");
|
||||
|
||||
// fail
|
||||
reportEvent = client.Report("test report", client);
|
||||
|
||||
Assert.True(reportEvent.FailReason == GameEvent.EventFailReason.Invalid &&
|
||||
client.CurrentServer.Reports.Count(r => r.Target.NetworkId == client.NetworkId) == 1, $"report was applied to self");
|
||||
|
||||
// fail
|
||||
reportEvent = client.Report("test report", new Player() { ClientId = 1, Level = Player.Permission.Console});
|
||||
|
||||
Assert.True(reportEvent.FailReason == GameEvent.EventFailReason.Exception &&
|
||||
client.CurrentServer.Reports.Count(r => r.Target.NetworkId == client.NetworkId) == 1, $"duplicate report was applied");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ namespace Tests
|
||||
|
||||
public ManagerFixture()
|
||||
{
|
||||
|
||||
File.WriteAllText("test_mp.log", "TEST_LOG_FILE");
|
||||
|
||||
Manager = Program.ServerManager;
|
||||
@ -32,7 +31,7 @@ namespace Tests
|
||||
Password = "test",
|
||||
Port = 28963,
|
||||
Rules = new List<string>(),
|
||||
ManualLogPath = "https://raidmax.org/IW4MAdmin/getlog.php"
|
||||
ManualLogPath = "http://google.com"
|
||||
}
|
||||
},
|
||||
AutoMessages = new List<string>(),
|
||||
|
Reference in New Issue
Block a user