PlatformFactAttribute.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.InteropServices;
  4. using Xunit;
  5. namespace Avalonia.IntegrationTests.Appium
  6. {
  7. [Flags]
  8. internal enum TestPlatforms
  9. {
  10. Windows = 0x01,
  11. MacOS = 0x02,
  12. All = Windows | MacOS,
  13. }
  14. internal class PlatformFactAttribute : FactAttribute
  15. {
  16. public PlatformFactAttribute(TestPlatforms platforms = TestPlatforms.All) => Platforms = platforms;
  17. public TestPlatforms Platforms { get; }
  18. public override string? Skip
  19. {
  20. get => IsSupported() ? null : $"Ignored on {RuntimeInformation.OSDescription}";
  21. set => throw new NotSupportedException();
  22. }
  23. private bool IsSupported()
  24. {
  25. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  26. return Platforms.HasAnyFlag(TestPlatforms.Windows);
  27. if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  28. return Platforms.HasAnyFlag(TestPlatforms.MacOS);
  29. return false;
  30. }
  31. }
  32. }