From 790a101f2331bc6f6704cd09c1d691cc45c0dfbb Mon Sep 17 00:00:00 2001 From: Acentech Dev Date: Thu, 13 Aug 2026 08:50:53 +0300 Subject: [PATCH] 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. --- .../ConfigurationChangePublishingTests.cs | 34 +++++++++++++++++++ .../JsonQueryBuilderTests.cs | 5 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/MUnique.OpenMU.Persistence.Initialization.Tests/ConfigurationChangePublishingTests.cs diff --git a/tests/MUnique.OpenMU.Persistence.Initialization.Tests/ConfigurationChangePublishingTests.cs b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/ConfigurationChangePublishingTests.cs new file mode 100644 index 0000000..cfbb9c3 --- /dev/null +++ b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/ConfigurationChangePublishingTests.cs @@ -0,0 +1,34 @@ +// +// Licensed under the MIT License. See LICENSE file in the project root for full license information. +// + +namespace MUnique.OpenMU.Persistence.Initialization.Tests; + +using MUnique.OpenMU.Persistence.EntityFramework; +using MUnique.OpenMU.Persistence.EntityFramework.Model; + +/// +/// Tests filtering of Entity Framework configuration change notifications. +/// +[TestFixture] +internal class ConfigurationChangePublishingTests +{ + /// + /// Verifies that only configuration entities are published to the configuration change listener. + /// + /// The entity type. + /// Whether changes of this entity type should be published. + [TestCase(typeof(CastleSiegeConfiguration), true)] + [TestCase(typeof(CastleSiegeNpcState), false)] + [TestCase(typeof(Account), false)] + [TestCase(typeof(Guild), false)] + [TestCase(typeof(Friend), false)] + public void OnlyConfigurationEntitiesArePublished(Type entityType, bool shouldPublish) + { + using var context = new EntityDataContext(); + var modelType = context.Model.FindEntityType(entityType); + + Assert.That(modelType, Is.Not.Null); + Assert.That(EntityFrameworkContextBase.PublishesConfigurationChanges(modelType!), Is.EqualTo(shouldPublish)); + } +} diff --git a/tests/MUnique.OpenMU.Persistence.Initialization.Tests/JsonQueryBuilderTests.cs b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/JsonQueryBuilderTests.cs index c320853..5dfdd0f 100644 --- a/tests/MUnique.OpenMU.Persistence.Initialization.Tests/JsonQueryBuilderTests.cs +++ b/tests/MUnique.OpenMU.Persistence.Initialization.Tests/JsonQueryBuilderTests.cs @@ -24,7 +24,10 @@ internal class JsonQueryBuilderTests [OneTimeSetUp] public void Setup() { - ConnectionConfigurator.Initialize(new ConfigFileDatabaseConnectionStringProvider()); + if (!ConnectionConfigurator.IsInitialized) + { + ConnectionConfigurator.Initialize(new ConfigFileDatabaseConnectionStringProvider()); + } } ///