|
1 | | -using System; |
| 1 | +#nullable enable |
| 2 | +using System; |
2 | 3 | using System.Collections.Generic; |
3 | 4 | using System.Runtime.InteropServices; |
4 | 5 | using Microsoft.Extensions.Configuration; |
@@ -47,31 +48,73 @@ public CIFactAttribute() |
47 | 48 |
|
48 | 49 | public class RuntimeFactAttribute : FactAttribute |
49 | 50 | { |
50 | | - public RuntimeFactAttribute(string? osPlatform = default, Architecture? architecture = default, string? runtimeIdentifier = default) |
| 51 | + /// <summary> |
| 52 | + /// Use <c>nameof(OSPLatform.Windows|Linux|OSX|FreeBSD)</c> |
| 53 | + /// </summary> |
| 54 | + public RuntimeFactAttribute(string osPlatform) |
51 | 55 | { |
52 | 56 | if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform))) |
53 | 57 | Skip = $"Only running on {osPlatform}."; |
| 58 | + } |
54 | 59 |
|
55 | | - if (architecture != null && RuntimeInformation.ProcessArchitecture != architecture.Value) |
| 60 | + public RuntimeFactAttribute(Architecture architecture) |
| 61 | + { |
| 62 | + if (RuntimeInformation.ProcessArchitecture != architecture) |
56 | 63 | Skip = $"Requires {architecture} but was {RuntimeInformation.ProcessArchitecture}."; |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Empty constructor for use in combination with RuntimeIdentifier property. |
| 68 | + /// </summary> |
| 69 | + public RuntimeFactAttribute() { } |
57 | 70 |
|
58 | | - if (runtimeIdentifier != null && RuntimeInformation.RuntimeIdentifier != runtimeIdentifier) |
59 | | - Skip = $"Requires {runtimeIdentifier} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 71 | + /// <summary> |
| 72 | + /// Sets the runtime identifier the test requires to run. |
| 73 | + /// </summary> |
| 74 | + public string? RuntimeIdentifier |
| 75 | + { |
| 76 | + get => RuntimeInformation.RuntimeIdentifier; |
| 77 | + set |
| 78 | + { |
| 79 | + if (value != null && RuntimeInformation.RuntimeIdentifier != value) |
| 80 | + Skip += $"Requires {value} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 81 | + } |
60 | 82 | } |
61 | 83 | } |
62 | 84 |
|
63 | 85 | public class RuntimeTheoryAttribute : TheoryAttribute |
64 | 86 | { |
65 | | - public RuntimeTheoryAttribute(string? osPlatform = default, Architecture? architecture = default, string? runtimeIdentifier = default) |
| 87 | + /// <summary> |
| 88 | + /// Use <c>nameof(OSPLatform.Windows|Linux|OSX|FreeBSD)</c> |
| 89 | + /// </summary> |
| 90 | + public RuntimeTheoryAttribute(string osPlatform) |
66 | 91 | { |
67 | 92 | if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform))) |
68 | 93 | Skip = $"Only running on {osPlatform}."; |
| 94 | + } |
69 | 95 |
|
70 | | - if (architecture != null && RuntimeInformation.ProcessArchitecture != architecture.Value) |
| 96 | + public RuntimeTheoryAttribute(Architecture architecture) |
| 97 | + { |
| 98 | + if (RuntimeInformation.ProcessArchitecture != architecture) |
71 | 99 | Skip = $"Requires {architecture} but was {RuntimeInformation.ProcessArchitecture}."; |
| 100 | + } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Empty constructor for use in combination with RuntimeIdentifier property. |
| 104 | + /// </summary> |
| 105 | + public RuntimeTheoryAttribute() { } |
72 | 106 |
|
73 | | - if (runtimeIdentifier != null && RuntimeInformation.RuntimeIdentifier != runtimeIdentifier) |
74 | | - Skip = $"Requires {runtimeIdentifier} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 107 | + /// <summary> |
| 108 | + /// Sets the runtime identifier the test requires to run. |
| 109 | + /// </summary> |
| 110 | + public string? RuntimeIdentifier |
| 111 | + { |
| 112 | + get => RuntimeInformation.RuntimeIdentifier; |
| 113 | + set |
| 114 | + { |
| 115 | + if (value != null && RuntimeInformation.RuntimeIdentifier != value) |
| 116 | + Skip += $"Requires {value} but was {RuntimeInformation.RuntimeIdentifier}."; |
| 117 | + } |
75 | 118 | } |
76 | 119 | } |
77 | 120 |
|
|
0 commit comments