Skip to content

Commit 4091497

Browse files
committed
Fix wrong ctor types for RuntimeFact/Theory
1 parent 48d3cee commit 4091497

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

Xunit/Attributes.cs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Collections.Generic;
34
using System.Runtime.InteropServices;
45
using Microsoft.Extensions.Configuration;
@@ -47,31 +48,73 @@ public CIFactAttribute()
4748

4849
public class RuntimeFactAttribute : FactAttribute
4950
{
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)
5155
{
5256
if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform)))
5357
Skip = $"Only running on {osPlatform}.";
58+
}
5459

55-
if (architecture != null && RuntimeInformation.ProcessArchitecture != architecture.Value)
60+
public RuntimeFactAttribute(Architecture architecture)
61+
{
62+
if (RuntimeInformation.ProcessArchitecture != architecture)
5663
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() { }
5770

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+
}
6082
}
6183
}
6284

6385
public class RuntimeTheoryAttribute : TheoryAttribute
6486
{
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)
6691
{
6792
if (osPlatform != null && !RuntimeInformation.IsOSPlatform(OSPlatform.Create(osPlatform)))
6893
Skip = $"Only running on {osPlatform}.";
94+
}
6995

70-
if (architecture != null && RuntimeInformation.ProcessArchitecture != architecture.Value)
96+
public RuntimeTheoryAttribute(Architecture architecture)
97+
{
98+
if (RuntimeInformation.ProcessArchitecture != architecture)
7199
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() { }
72106

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+
}
75118
}
76119
}
77120

0 commit comments

Comments
 (0)