InvariantCultureFixture.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Globalization;
  5. using System.Threading;
  6. namespace Avalonia.UnitTests
  7. {
  8. /// <summary>
  9. /// Runs tests in the invariant culture.
  10. /// </summary>
  11. /// <remarks>
  12. /// Some tests check exception messages, and those from the .NET framework will be translated.
  13. /// Use this fixture to set the current culture to the invariant culture.
  14. /// </remarks>
  15. public class InvariantCultureFixture : IDisposable
  16. {
  17. private CultureInfo _restore;
  18. public InvariantCultureFixture()
  19. {
  20. _restore = Thread.CurrentThread.CurrentUICulture;
  21. Thread.CurrentThread.CurrentUICulture =
  22. Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  23. }
  24. public void Dispose()
  25. {
  26. Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = _restore;
  27. }
  28. }
  29. }