ScopedTestBase.cs 642 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Threading;
  3. using Avalonia.Controls;
  4. using Avalonia.Threading;
  5. using Xunit;
  6. namespace Avalonia.UnitTests;
  7. [Collection("Scoped Not Parallel")]
  8. public class ScopedTestBase : IDisposable
  9. {
  10. private readonly IDisposable _scope;
  11. public ScopedTestBase()
  12. {
  13. AvaloniaLocator.Current = AvaloniaLocator.CurrentMutable = new AvaloniaLocator();
  14. Dispatcher.ResetBeforeUnitTests();
  15. Control.ResetLoadedQueueForUnitTests();
  16. _scope = AvaloniaLocator.EnterScope();
  17. }
  18. public virtual void Dispose()
  19. {
  20. Dispatcher.ResetForUnitTests();
  21. _scope.Dispose();
  22. }
  23. }