TestMethodForPlatformAttribute.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. namespace Renci.SshNet.Tests.Common
  5. {
  6. [AttributeUsage(AttributeTargets.Method)]
  7. public sealed class TestMethodForPlatformAttribute : TestMethodAttribute
  8. {
  9. public TestMethodForPlatformAttribute(string platform)
  10. {
  11. Platform = platform;
  12. }
  13. public string Platform { get; }
  14. public override TestResult[] Execute(ITestMethod testMethod)
  15. {
  16. if (RuntimeInformation.IsOSPlatform(OSPlatform.Create(Platform)))
  17. {
  18. return base.Execute(testMethod);
  19. }
  20. var message = $"Test not executed. The test is intended for the '{Platform}' platform only.";
  21. return new[]
  22. {
  23. new TestResult
  24. {
  25. Outcome = UnitTestOutcome.Inconclusive,
  26. TestFailureException = new AssertInconclusiveException(message)
  27. }
  28. };
  29. }
  30. }
  31. }