2020-04-26 22:12:49 -04:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using IW4MAdmin;
|
|
|
|
|
using FakeItEasy;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ApplicationTests.Fixtures;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using ApplicationTests.Mocks;
|
2020-05-16 12:54:01 -04:00
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using static SharedLibraryCore.Database.Models.EFClient;
|
2020-04-26 22:12:49 -04:00
|
|
|
|
|
|
|
|
|
namespace ApplicationTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class CommandTests
|
|
|
|
|
{
|
|
|
|
|
ILogger logger;
|
|
|
|
|
private IServiceProvider serviceProvider;
|
|
|
|
|
private ITranslationLookup transLookup;
|
|
|
|
|
private CommandConfiguration cmdConfig;
|
2020-05-16 12:54:01 -04:00
|
|
|
|
private ApplicationConfiguration appConfig;
|
|
|
|
|
private EventHandlerMock mockEventHandler;
|
|
|
|
|
private ClientService clientService;
|
|
|
|
|
private IManager manager;
|
2020-04-26 22:12:49 -04:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
logger = A.Fake<ILogger>();
|
|
|
|
|
cmdConfig = new CommandConfiguration();
|
|
|
|
|
|
|
|
|
|
serviceProvider = new ServiceCollection()
|
2020-05-16 12:54:01 -04:00
|
|
|
|
.BuildBase(new EventHandlerMock(true))
|
2020-05-24 22:22:26 -04:00
|
|
|
|
.AddSingleton(A.Fake<ClientService>())
|
2020-05-16 12:54:01 -04:00
|
|
|
|
.BuildServiceProvider()
|
|
|
|
|
.SetupTestHooks();
|
2020-04-26 22:12:49 -04:00
|
|
|
|
|
2020-05-16 12:54:01 -04:00
|
|
|
|
mockEventHandler = serviceProvider.GetRequiredService<EventHandlerMock>();
|
|
|
|
|
manager = serviceProvider.GetRequiredService<IManager>();
|
2020-04-26 22:12:49 -04:00
|
|
|
|
transLookup = serviceProvider.GetRequiredService<ITranslationLookup>();
|
2020-05-16 12:54:01 -04:00
|
|
|
|
clientService = serviceProvider.GetRequiredService<ClientService>();
|
|
|
|
|
appConfig = serviceProvider.GetRequiredService<ApplicationConfiguration>();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => manager.GetClientService())
|
|
|
|
|
.Returns(clientService);
|
2020-04-26 22:12:49 -04:00
|
|
|
|
|
2020-05-16 12:54:01 -04:00
|
|
|
|
A.CallTo(() => clientService.UpdateLevel(A<Permission>.Ignored, A<EFClient>.Ignored, A<EFClient>.Ignored))
|
|
|
|
|
.Returns(Task.CompletedTask);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => manager.GetCommands())
|
2020-04-26 22:12:49 -04:00
|
|
|
|
.Returns(new Command[]
|
|
|
|
|
{
|
|
|
|
|
new ImpersonatableCommand(cmdConfig, transLookup),
|
2020-07-31 21:40:03 -04:00
|
|
|
|
new NonImpersonatableCommand(cmdConfig, transLookup),
|
|
|
|
|
new MockCommand(cmdConfig, transLookup)
|
2020-04-26 22:12:49 -04:00
|
|
|
|
});
|
|
|
|
|
|
2020-05-16 12:54:01 -04:00
|
|
|
|
A.CallTo(() => manager.AddEvent(A<GameEvent>.Ignored))
|
|
|
|
|
.Invokes((fakeCall) => mockEventHandler.HandleEvent(manager, fakeCall.Arguments[0] as GameEvent));
|
2020-04-26 22:12:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region RUNAS
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_RunAsFailsOnSelf()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new RunAsCommand(cmdConfig, transLookup);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = target
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Command));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_RunAsFailsOnHigherPrivilege()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new RunAsCommand(cmdConfig, transLookup);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = EFClient.Permission.Administrator;
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.NetworkId = 100;
|
|
|
|
|
origin.Level = EFClient.Permission.Moderator;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Command));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_RunAsFailsOnSamePrivilege()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new RunAsCommand(cmdConfig, transLookup);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = EFClient.Permission.Administrator;
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.NetworkId = 100;
|
|
|
|
|
origin.Level = EFClient.Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Command));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_RunAsFailsOnDisallowedCommand()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new RunAsCommand(cmdConfig, transLookup);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = EFClient.Permission.Moderator;
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.NetworkId = 100;
|
|
|
|
|
origin.Level = EFClient.Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Owner = server,
|
|
|
|
|
Data = nameof(NonImpersonatableCommand)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
// failed when validating the command
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Command && _event.FailReason == GameEvent.EventFailReason.Invalid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_RunAsQueuesEventAndResponse()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new RunAsCommand(cmdConfig, transLookup);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = EFClient.Permission.Moderator;
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.NetworkId = 100;
|
|
|
|
|
origin.Level = EFClient.Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = nameof(ImpersonatableCommand),
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell /*&& _event.Target == origin todo: fake the command result*/ ));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Command && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2020-05-16 12:54:01 -04:00
|
|
|
|
|
|
|
|
|
#region SETLEVEL
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailOnSelf()
|
|
|
|
|
{
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.Owner;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = target,
|
|
|
|
|
Data = "Administrator",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Owner, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailWithSourcePrivilegeTooLow()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Moderator;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Administrator",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Administrator, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailWithExistingOwner_AndOnlyOneOwnerAllowed()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Owner",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.User, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailWithStepPrivilegesDisabled_AndNonOwner()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.SeniorAdmin;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.Moderator;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Administrator",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Moderator, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailWithStepPrivilegesEnabled_ButNewPermissionTooHigh()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Moderator;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
appConfig.EnableSteppedHierarchy = true;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Moderator",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.User, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelFailInvalidGroup()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Banned",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.User, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelSucceedWithNoExistingOwner_AndOnlyOneOwnerAllowed()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(0));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Owner",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Owner, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelOwnerSucceedWithMultiOwnerAllowed()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
appConfig.EnableMultipleOwners = true;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Owner",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Owner, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelOwnerSucceedWithMultiOwnerAllowed_AndSteppedPrivileges()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
appConfig.EnableMultipleOwners = true;
|
|
|
|
|
appConfig.EnableSteppedHierarchy = true;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Owner",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Owner, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelSucceedWithSteppedPrivileges()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Moderator;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
appConfig.EnableSteppedHierarchy = true;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Trusted",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Trusted, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelSucceed()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Level = Permission.User;
|
|
|
|
|
appConfig.EnableSteppedHierarchy = true;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = target,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "Trusted",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.Trusted, target.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_SetLevelSucceed_AndFindsIngameClient()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var cmd = new SetLevelCommand(cmdConfig, transLookup, logger);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
origin.Level = Permission.Owner;
|
|
|
|
|
var databaseTarget = ClientGenerators.CreateDatabaseClient();
|
|
|
|
|
databaseTarget.Level = Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
var ingameTarget = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
ingameTarget.Level = Permission.Administrator;
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => manager.GetActiveClients())
|
|
|
|
|
.Returns(new[] { ingameTarget });
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => clientService.GetOwnerCount())
|
|
|
|
|
.Returns(Task.FromResult(1));
|
|
|
|
|
|
|
|
|
|
var gameEvent = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Target = databaseTarget,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Data = "User",
|
|
|
|
|
Owner = server,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await cmd.ExecuteAsync(gameEvent);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Permission.User, ingameTarget.Level);
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.Tell));
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events.Where(_event => _event.Type == GameEvent.EventType.ChangePermission && !_event.Failed));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
|
|
|
|
#region PREFIX_PROCESSING
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_CommandProcessing_IsBroadcastCommand()
|
|
|
|
|
{
|
|
|
|
|
string broadcastPrefix = "@@";
|
|
|
|
|
var config = ConfigurationGenerators.CreateApplicationConfiguration();
|
|
|
|
|
config.BroadcastCommandPrefix = broadcastPrefix;
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
|
|
|
|
|
var cmd = EventGenerators.GenerateEvent(GameEvent.EventType.Command, $"{broadcastPrefix}{nameof(MockCommand)}", server);
|
|
|
|
|
|
|
|
|
|
var result = await CommandProcessing.ValidateCommand(cmd, config);
|
|
|
|
|
Assert.AreEqual(nameof(MockCommand), result.Name);
|
|
|
|
|
Assert.IsTrue(result.IsBroadcast);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2020-04-26 22:12:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|