// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Tests; using Microsoft.Extensions.Logging.Abstractions; using Moq; using MUnique.OpenMU.DataModel.Entities; using MUnique.OpenMU.GuildServer; using MUnique.OpenMU.Interfaces; using MUnique.OpenMU.Persistence; using MUnique.OpenMU.Persistence.InMemory; /// /// Base class for guild related tests. /// public class GuildTestBase { /// /// The default guild name used in tests. /// protected const string GuildName = "Foobar"; /// /// Gets or sets the first game server. /// protected Mock GameServer0 { get; set; } = null!; /// /// Gets or sets the second game server. /// protected Mock GameServer1 { get; set; } = null!; /// /// Gets or sets the repository provider. /// protected IPersistenceContextProvider PersistenceContextProvider { get; set; } = null!; /// /// Gets or sets the game servers. /// protected IDictionary GameServers { get; set; } = null!; /// /// Gets or sets the guild server. /// protected IGuildServer GuildServer { get; set; } = null!; /// /// Gets or sets the guild master. /// protected Character GuildMaster { get; set; } = null!; /// /// Setups the test objects. /// [SetUp] public virtual async ValueTask SetupAsync() { this.GameServer0 = new Mock(); this.GameServer1 = new Mock(); this.PersistenceContextProvider = new InMemoryPersistenceContextProvider(); this.GuildMaster = this.GetGuildMaster(); this.SetupGameServer(this.GameServer0); this.SetupGameServer(this.GameServer1); this.GameServers = new Dictionary { { 0, this.GameServer0.Object }, { 1, this.GameServer1.Object } }; this.GuildServer = new OpenMU.GuildServer.GuildServer(new GuildChangeToGameServerPublisher(this.GameServers), this.PersistenceContextProvider, new NullLogger()); await this.GuildServer.CreateGuildAsync(GuildName, this.GuildMaster.Name, this.GuildMaster.Id, new byte[16], 0).ConfigureAwait(false); var guildId = await this.GuildServer.GetGuildIdByNameAsync(GuildName).ConfigureAwait(false); await this.GuildServer.GuildMemberLeftGameAsync(guildId, this.GuildMaster.Id, 0).ConfigureAwait(false); } /// /// Sets up the game server. /// /// The game server. protected virtual void SetupGameServer(Mock gameServer) { // can be overwritten. } private Character GetGuildMaster() { var context = this.PersistenceContextProvider.CreateNewContext(); var master = context.CreateNew(); master.Name = "GuildMaster"; return master; } }