Files
Acentech Dev 790a101f23 Cover the configuration change publishing filter with its test
The Castle Siege persistence import (#860) brought
EntityFrameworkContextBase.PublishesConfigurationChanges into the tree,
but not the test which pins its behaviour, and not the guard which keeps
the two initialization test fixtures from configuring the connection
twice.

Add both, unchanged from upstream.
2026-08-13 08:50:53 +03:00

111 lines
3.7 KiB
C#

// <copyright file="JsonQueryBuilderTests.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
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;
/// <summary>
/// Tests for the <see cref="JsonQueryBuilder"/>.
/// </summary>
[TestFixture]
internal class JsonQueryBuilderTests
{
/// <summary>
/// Sets up this instance.
/// </summary>
[OneTimeSetUp]
public void Setup()
{
if (!ConnectionConfigurator.IsInitialized)
{
ConnectionConfigurator.Initialize(new ConfigFileDatabaseConnectionStringProvider());
}
}
/// <summary>
/// Tests the json query builder for the <see cref="GameConfiguration"/> type.
/// </summary>
[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);
}
/// <summary>
/// Tests the json query builder for the <see cref="Account"/> type.
/// </summary>
[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);
}
/// <summary>
/// Loads the <see cref="GameConfiguration"/> using the <see cref="JsonQueryBuilder"/> and the <see cref="JsonObjectLoader"/>.
/// It always fails, because it reports the taken time.
/// </summary>
[Test]
[Ignore("It hits the database.")]
public async Task LoadConfigByJsonAsync()
{
await using var installationContext = new ConfigurationContext();
installationContext.Database.OpenConnection();
var builder = new GameConfigurationJsonObjectLoader();
IEnumerable<GameConfiguration> result;
Stopwatch stopwatch = new();
stopwatch.Start();
try
{
result = await builder.LoadAllObjectsAsync<EntityFramework.Model.GameConfiguration>(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));
}
}