@@ -22,17 +22,17 @@ public void NullTest()
22
22
// Invalid
23
23
object ? potato = null ;
24
24
var ex1 = Assert . Throws < ArgumentNullException > ( ( ) => Guard . ThrowIfNull ( potato ) ) ;
25
- Assert . Contains ( "Must not be null" , ex1 . Message ) ;
25
+ Assert . Contains ( "Must not be null" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
26
26
Assert . Equal ( "potato" , ex1 . ParamName ) ;
27
27
28
28
object ? @event = null ;
29
29
var ex2 = Assert . Throws < ArgumentNullException > ( ( ) => Guard . ThrowIfNull ( @event ) ) ;
30
- Assert . Contains ( "Must not be null" , ex2 . Message ) ;
30
+ Assert . Contains ( "Must not be null" , ex2 . Message , StringComparison . OrdinalIgnoreCase ) ;
31
31
Assert . Equal ( "@event" , ex2 . ParamName ) ;
32
32
33
33
Thing ? thing = null ;
34
34
var ex3 = Assert . Throws < ArgumentNullException > ( ( ) => Guard . ThrowIfNull ( thing ? . Bar ) ) ;
35
- Assert . Contains ( "Must not be null" , ex3 . Message ) ;
35
+ Assert . Contains ( "Must not be null" , ex3 . Message , StringComparison . OrdinalIgnoreCase ) ;
36
36
Assert . Equal ( "thing?.Bar" , ex3 . ParamName ) ;
37
37
}
38
38
@@ -45,16 +45,16 @@ public void NullOrEmptyTest()
45
45
46
46
// Invalid
47
47
var ex1 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrEmpty ( null ) ) ;
48
- Assert . Contains ( "Must not be null or empty" , ex1 . Message ) ;
48
+ Assert . Contains ( "Must not be null or empty" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
49
49
Assert . Equal ( "null" , ex1 . ParamName ) ;
50
50
51
51
var ex2 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrEmpty ( string . Empty ) ) ;
52
- Assert . Contains ( "Must not be null or empty" , ex2 . Message ) ;
52
+ Assert . Contains ( "Must not be null or empty" , ex2 . Message , StringComparison . OrdinalIgnoreCase ) ;
53
53
Assert . Equal ( "string.Empty" , ex2 . ParamName ) ;
54
54
55
55
var x = string . Empty ;
56
56
var ex3 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrEmpty ( x ) ) ;
57
- Assert . Contains ( "Must not be null or empty" , ex3 . Message ) ;
57
+ Assert . Contains ( "Must not be null or empty" , ex3 . Message , StringComparison . OrdinalIgnoreCase ) ;
58
58
Assert . Equal ( "x" , ex3 . ParamName ) ;
59
59
}
60
60
@@ -66,15 +66,15 @@ public void NullOrWhitespaceTest()
66
66
67
67
// Invalid
68
68
var ex1 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrWhitespace ( null ) ) ;
69
- Assert . Contains ( "Must not be null or whitespace" , ex1 . Message ) ;
69
+ Assert . Contains ( "Must not be null or whitespace" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
70
70
Assert . Equal ( "null" , ex1 . ParamName ) ;
71
71
72
72
var ex2 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrWhitespace ( string . Empty ) ) ;
73
- Assert . Contains ( "Must not be null or whitespace" , ex2 . Message ) ;
73
+ Assert . Contains ( "Must not be null or whitespace" , ex2 . Message , StringComparison . OrdinalIgnoreCase ) ;
74
74
Assert . Equal ( "string.Empty" , ex2 . ParamName ) ;
75
75
76
76
var ex3 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfNullOrWhitespace ( " \t \n \r " ) ) ;
77
- Assert . Contains ( "Must not be null or whitespace" , ex3 . Message ) ;
77
+ Assert . Contains ( "Must not be null or whitespace" , ex3 . Message , StringComparison . OrdinalIgnoreCase ) ;
78
78
Assert . Equal ( "\" \\ t\\ n\\ r\" " , ex3 . ParamName ) ;
79
79
}
80
80
@@ -88,7 +88,7 @@ public void InvalidTimeoutTest()
88
88
89
89
// Invalid
90
90
var ex1 = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => Guard . ThrowIfInvalidTimeout ( - 100 ) ) ;
91
- Assert . Contains ( "Must be non-negative or 'Timeout.Infinite'" , ex1 . Message ) ;
91
+ Assert . Contains ( "Must be non-negative or 'Timeout.Infinite'" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
92
92
Assert . Equal ( "-100" , ex1 . ParamName ) ;
93
93
}
94
94
@@ -104,10 +104,10 @@ public void RangeIntTest()
104
104
105
105
// Invalid
106
106
var ex1 = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => Guard . ThrowIfOutOfRange ( - 1 , min : 0 , max : 100 , minName : "empty" , maxName : "full" ) ) ;
107
- Assert . Contains ( "Must be in the range: [0: empty, 100: full]" , ex1 . Message ) ;
107
+ Assert . Contains ( "Must be in the range: [0: empty, 100: full]" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
108
108
109
109
var ex2 = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => Guard . ThrowIfOutOfRange ( - 1 , min : 0 , max : 100 , message : "error" ) ) ;
110
- Assert . Contains ( "error" , ex2 . Message ) ;
110
+ Assert . Contains ( "error" , ex2 . Message , StringComparison . OrdinalIgnoreCase ) ;
111
111
}
112
112
113
113
[ Fact ]
@@ -120,10 +120,10 @@ public void RangeDoubleTest()
120
120
121
121
// Invalid
122
122
var ex3 = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => Guard . ThrowIfOutOfRange ( - 1.1 , min : 0.1 , max : 99.9 , minName : "empty" , maxName : "full" ) ) ;
123
- Assert . Contains ( "Must be in the range: [0.1: empty, 99.9: full]" , ex3 . Message ) ;
123
+ Assert . Contains ( "Must be in the range: [0.1: empty, 99.9: full]" , ex3 . Message , StringComparison . OrdinalIgnoreCase ) ;
124
124
125
125
var ex4 = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => Guard . ThrowIfOutOfRange ( - 1.1 , min : 0.0 , max : 100.0 ) ) ;
126
- Assert . Contains ( "Must be in the range: [0, 100]" , ex4 . Message ) ;
126
+ Assert . Contains ( "Must be in the range: [0, 100]" , ex4 . Message , StringComparison . OrdinalIgnoreCase ) ;
127
127
}
128
128
129
129
[ Fact ]
@@ -147,41 +147,45 @@ public void ZeroTest()
147
147
148
148
// Invalid
149
149
var ex1 = Assert . Throws < ArgumentException > ( ( ) => Guard . ThrowIfZero ( 0 ) ) ;
150
- Assert . Contains ( "Must not be zero" , ex1 . Message ) ;
150
+ Assert . Contains ( "Must not be zero" , ex1 . Message , StringComparison . OrdinalIgnoreCase ) ;
151
151
Assert . Equal ( "0" , ex1 . ParamName ) ;
152
152
}
153
153
154
- public class Thing
154
+ #pragma warning disable CA1812 // Avoid uninstantiated internal classes
155
+ internal sealed class Thing
156
+ #pragma warning restore CA1812 // Avoid uninstantiated internal classes
155
157
{
156
158
public string ? Bar { get ; set ; }
157
159
}
160
+ }
158
161
159
162
#if ! NET
160
- /// <summary>
161
- /// Borrowed from: <see href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs"/>.
162
- /// </summary>
163
- public class CallerArgumentExpressionAttributeTests
163
+ /// <summary>
164
+ /// Borrowed from: <see href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/CallerArgumentExpressionAttributeTests.cs"/>.
165
+ /// </summary>
166
+ #pragma warning disable SA1402 // File may only contain a single type
167
+ public class CallerArgumentExpressionAttributeTests
168
+ #pragma warning restore SA1402 // File may only contain a single type
169
+ {
170
+ [ Theory ]
171
+ [ InlineData ( null ) ]
172
+ [ InlineData ( "" ) ]
173
+ [ InlineData ( "paramName" ) ]
174
+ public void Ctor_ParameterName_Roundtrip ( string ? value )
164
175
{
165
- [ Theory ]
166
- [ InlineData ( null ) ]
167
- [ InlineData ( "" ) ]
168
- [ InlineData ( "paramName" ) ]
169
- public static void Ctor_ParameterName_Roundtrip ( string ? value )
170
- {
171
- var caea = new CallerArgumentExpressionAttribute ( value ) ;
172
- Assert . Equal ( value , caea . ParameterName ) ;
173
- }
174
-
175
- [ Fact ]
176
- public static void BasicTest ( )
177
- {
178
- Assert . Equal ( "null" , GetValue ( null ) ) ;
179
- Assert . Equal ( "\" hello\" " , GetValue ( "hello" ) ) ;
180
- Assert . Equal ( "3 + 2" , GetValue ( 3 + 2 ) ) ;
181
- Assert . Equal ( "new object()" , GetValue ( new object ( ) ) ) ;
182
- }
183
-
184
- private static string ? GetValue ( object ? argument , [ CallerArgumentExpression ( nameof ( argument ) ) ] string ? expr = null ) => expr ;
176
+ var caea = new CallerArgumentExpressionAttribute ( value ) ;
177
+ Assert . Equal ( value , caea . ParameterName ) ;
185
178
}
186
- #endif
179
+
180
+ [ Fact ]
181
+ public void BasicTest ( )
182
+ {
183
+ Assert . Equal ( "null" , GetValue ( null ) ) ;
184
+ Assert . Equal ( "\" hello\" " , GetValue ( "hello" ) ) ;
185
+ Assert . Equal ( "3 + 2" , GetValue ( 3 + 2 ) ) ;
186
+ Assert . Equal ( "new object()" , GetValue ( new object ( ) ) ) ;
187
+ }
188
+
189
+ private static string ? GetValue ( object ? argument , [ CallerArgumentExpression ( nameof ( argument ) ) ] string ? expr = null ) => expr ;
187
190
}
191
+ #endif
0 commit comments