-
Notifications
You must be signed in to change notification settings - Fork 83
/
BooleanAsserts.cs
144 lines (133 loc) · 4.49 KB
/
BooleanAsserts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma warning disable CA1052 // Static holder types should be static
#pragma warning disable IDE0161 // Convert to file-scoped namespace
#if XUNIT_NULLABLE
#nullable enable
#else
// In case this is source-imported with global nullable enabled but no XUNIT_NULLABLE
#pragma warning disable CS8625
#endif
using Xunit.Sdk;
#if XUNIT_NULLABLE
using System.Diagnostics.CodeAnalysis;
#endif
namespace Xunit
{
#if XUNIT_VISIBILITY_INTERNAL
internal
#else
public
#endif
partial class Assert
{
/// <summary>
/// Verifies that the condition is false.
/// </summary>
/// <param name="condition">The condition to be tested</param>
/// <exception cref="FalseException">Thrown if the condition is not false</exception>
#if XUNIT_NULLABLE
public static void False([DoesNotReturnIf(parameterValue: true)] bool condition) =>
#else
public static void False(bool condition) =>
#endif
False((bool?)condition, null);
/// <summary>
/// Verifies that the condition is false.
/// </summary>
/// <param name="condition">The condition to be tested</param>
/// <exception cref="FalseException">Thrown if the condition is not false</exception>
#if XUNIT_NULLABLE
public static void False([DoesNotReturnIf(parameterValue: true)] bool? condition) =>
#else
public static void False(bool? condition) =>
#endif
False(condition, null);
/// <summary>
/// Verifies that the condition is false.
/// </summary>
/// <param name="condition">The condition to be tested</param>
/// <param name="userMessage">The message to show when the condition is not false</param>
/// <exception cref="FalseException">Thrown if the condition is not false</exception>
public static void False(
#if XUNIT_NULLABLE
[DoesNotReturnIf(parameterValue: true)] bool condition,
string? userMessage) =>
#else
bool condition,
string userMessage) =>
#endif
False((bool?)condition, userMessage);
/// <summary>
/// Verifies that the condition is false.
/// </summary>
/// <param name="condition">The condition to be tested</param>
/// <param name="userMessage">The message to show when the condition is not false</param>
/// <exception cref="FalseException">Thrown if the condition is not false</exception>
public static void False(
#if XUNIT_NULLABLE
[DoesNotReturnIf(parameterValue: true)] bool? condition,
string? userMessage)
#else
bool? condition,
string userMessage)
#endif
{
if (!condition.HasValue || condition.GetValueOrDefault())
throw FalseException.ForNonFalseValue(userMessage, condition);
}
/// <summary>
/// Verifies that an expression is true.
/// </summary>
/// <param name="condition">The condition to be inspected</param>
/// <exception cref="TrueException">Thrown when the condition is false</exception>
#if XUNIT_NULLABLE
public static void True([DoesNotReturnIf(parameterValue: false)] bool condition) =>
#else
public static void True(bool condition) =>
#endif
True((bool?)condition, null);
/// <summary>
/// Verifies that an expression is true.
/// </summary>
/// <param name="condition">The condition to be inspected</param>
/// <exception cref="TrueException">Thrown when the condition is false</exception>
#if XUNIT_NULLABLE
public static void True([DoesNotReturnIf(parameterValue: false)] bool? condition) =>
#else
public static void True(bool? condition) =>
#endif
True(condition, null);
/// <summary>
/// Verifies that an expression is true.
/// </summary>
/// <param name="condition">The condition to be inspected</param>
/// <param name="userMessage">The message to be shown when the condition is false</param>
/// <exception cref="TrueException">Thrown when the condition is false</exception>
public static void True(
#if XUNIT_NULLABLE
[DoesNotReturnIf(parameterValue: false)] bool condition,
string? userMessage) =>
#else
bool condition,
string userMessage) =>
#endif
True((bool?)condition, userMessage);
/// <summary>
/// Verifies that an expression is true.
/// </summary>
/// <param name="condition">The condition to be inspected</param>
/// <param name="userMessage">The message to be shown when the condition is false</param>
/// <exception cref="TrueException">Thrown when the condition is false</exception>
public static void True(
#if XUNIT_NULLABLE
[DoesNotReturnIf(parameterValue: false)] bool? condition,
string? userMessage)
#else
bool? condition,
string userMessage)
#endif
{
if (!condition.HasValue || !condition.GetValueOrDefault())
throw TrueException.ForNonTrueValue(userMessage, condition);
}
}
}