Skip to content

Commit

Permalink
Fix LocalizationManager Dispose
Browse files Browse the repository at this point in the history
This has been a mare! I've put the dispose pattern in and also fixed how it cleans up cultures
  • Loading branch information
Axemasta committed Mar 4, 2025
1 parent e47c099 commit 5c38ea8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/Mocale.UnitTests/Managers/LocalizationManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Mocale.UnitTests.Managers;

[Collection(CollectionNames.ThreadCultureTests)]
public class LocalizationManagerTests : FixtureBase<ILocalizationManager>
public class LocalizationManagerTests : FixtureBase<ILocalizationManager>, IDisposable
{
#region Setup

Expand All @@ -33,12 +33,24 @@ public LocalizationManagerTests()

~LocalizationManagerTests()
{
Thread.CurrentThread.CurrentCulture = null!;
Thread.CurrentThread.CurrentUICulture = null!;
CultureInfo.CurrentCulture = null!;
CultureInfo.CurrentUICulture = null!;
ReleaseUnmanagedResources();
}

private static void ReleaseUnmanagedResources()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = null;
CultureInfo.DefaultThreadCurrentUICulture = null;

}

public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}

public override ILocalizationManager CreateSystemUnderTest()
Expand Down

0 comments on commit 5c38ea8

Please sign in to comment.