1
0

PlatformTheoryAttribute.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.InteropServices;
  4. using Xunit;
  5. namespace Avalonia.IntegrationTests.Appium
  6. {
  7. internal class PlatformTheoryAttribute : TheoryAttribute
  8. {
  9. private string? _skip;
  10. public PlatformTheoryAttribute(TestPlatforms platforms = TestPlatforms.All) => Platforms = platforms;
  11. public TestPlatforms Platforms { get; }
  12. public override string? Skip
  13. {
  14. get
  15. {
  16. if (_skip is not null)
  17. return _skip;
  18. return !IsSupported() ? $"Ignored on {RuntimeInformation.OSDescription}" : null;
  19. }
  20. set => _skip = value;
  21. }
  22. private bool IsSupported()
  23. {
  24. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  25. return Platforms.HasFlag(TestPlatforms.Windows);
  26. if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  27. return Platforms.HasFlag(TestPlatforms.MacOS);
  28. return false;
  29. }
  30. }
  31. }