2
0

TestMethodForPlatformAttribute.cs 1.0 KB

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