// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Persistence.Initialization.Tests; using System.Diagnostics; using System.IO; using Microsoft.EntityFrameworkCore; using MUnique.OpenMU.Persistence.EntityFramework; using MUnique.OpenMU.Persistence.EntityFramework.Json; using Account = MUnique.OpenMU.Persistence.EntityFramework.Model.Account; using GameConfiguration = MUnique.OpenMU.Persistence.EntityFramework.Model.GameConfiguration; /// /// Tests for the . /// [TestFixture] internal class JsonQueryBuilderTests { /// /// Sets up this instance. /// [OneTimeSetUp] public void Setup() { ConnectionConfigurator.Initialize(new ConfigFileDatabaseConnectionStringProvider()); } /// /// Tests the json query builder for the type. /// [Test] public void JsonQueryBuilderGameConfiguration() { using var installationContext = new ConfigurationContext(); var type = installationContext.Model.GetEntityTypes().FirstOrDefault(t => t.ClrType == typeof(GameConfiguration)); string result; Stopwatch stopwatch = new(); stopwatch.Start(); try { var builder = new GameConfigurationJsonQueryBuilder(); result = builder.BuildJsonQueryForEntity(type!); } finally { stopwatch.Stop(); } result = $"-- Json query created in {stopwatch.ElapsedMilliseconds} ms:{Environment.NewLine}" + result; //// File.WriteAllText(@"C:\temp\json_GameConfiguration.txt", result); } /// /// Tests the json query builder for the type. /// [Test] public void JsonQueryBuilderAccount() { using var installationContext = new ConfigurationContext(); var type = installationContext.Model.GetEntityTypes().FirstOrDefault(t => t.ClrType == typeof(Account)); string result; Stopwatch stopwatch = new(); stopwatch.Start(); try { var builder = new JsonQueryBuilder(); result = builder.BuildJsonQueryForEntity(type!); } finally { stopwatch.Stop(); } result = $"-- Json query created in {stopwatch.ElapsedMilliseconds} ms:{Environment.NewLine}" + result; //// File.WriteAllText(@"C:\temp\json_Account.txt", result); } /// /// Loads the using the and the . /// It always fails, because it reports the taken time. /// [Test] [Ignore("It hits the database.")] public async Task LoadConfigByJsonAsync() { await using var installationContext = new ConfigurationContext(); installationContext.Database.OpenConnection(); var builder = new GameConfigurationJsonObjectLoader(); IEnumerable result; Stopwatch stopwatch = new(); stopwatch.Start(); try { result = await builder.LoadAllObjectsAsync(installationContext).ConfigureAwait(false); result = result.ToList(); } finally { stopwatch.Stop(); } Assert.That(result, Is.Not.Null); Assert.That(result.Count, Is.Not.EqualTo(0)); Assert.That(stopwatch.ElapsedMilliseconds, Is.EqualTo(0)); } }