FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Nancy/src/Nancy.Testing/Asserts.cs at master · include76/Nancy · GitHub
include76
Nancy
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Nancy
/
src
/
Nancy.Testing
/
Asserts.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
155 lines (132 loc) · 4.93 KB
Breadcrumbs
Nancy
/
src
/
Nancy.Testing
/
Asserts.cs
Copy path
File metadata and controls
155 lines (132 loc) · 4.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
145
146
147
148
149
150
151
152
153
154
155
namespace
Nancy
.
Testing
{
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
/// <summary>
/// Contains method for verifying the results of a test.
/// </summary>
public
static
class
Asserts
{
public
static
void
Contains
<
T
>
(
T
expected
,
IEnumerable
<
T
>
actual
,
IEqualityComparer
<
T
>
comparer
=
null
)
{
comparer
=
comparer
??
new
AssertEqualityComparer
<
T
>
(
)
;
Any
(
expected
,
actual
,
value
=>
comparer
.
Equals
(
expected
,
value
)
)
;
}
public
static
void
Any
<
T
>
(
T
expected
,
IEnumerable
<
T
>
actual
,
Func
<
T
,
bool
>
comparer
)
{
if
(
actual
!=
null
)
{
if
(
actual
.
Any
(
comparer
)
)
{
return
;
}
}
throw
new
AssertException
(
"The expected value was not found in the collection."
)
;
}
public
static
void
All
<
T
>
(
T
expected
,
IEnumerable
<
T
>
actual
,
Func
<
T
,
bool
>
comparer
)
{
if
(
actual
!=
null
)
{
if
(
actual
.
All
(
comparer
)
)
{
return
;
}
}
throw
new
AssertException
(
"All elements in the collection did not contain the expected value."
)
;
}
public
static
void
Contains
(
string
expected
,
string
actual
,
StringComparison
comparisonType
=
StringComparison
.
OrdinalIgnoreCase
)
{
if
(
expected
==
null
||
actual
.
IndexOf
(
expected
,
comparisonType
)
<
0
)
{
throw
new
AssertException
(
string
.
Format
(
"The expected value '{0}' was not a sub-string of the actual value '{1}'."
,
expected
,
actual
)
)
;
}
}
public
static
void
Equal
<
T
>
(
T
expected
,
T
actual
)
{
var
comparer
=
new
AssertEqualityComparer
<
T
>
(
)
;
if
(
!
comparer
.
Equals
(
actual
,
expected
)
)
{
throw
new
AssertException
(
string
.
Format
(
"The expected value '{0}' was not equal to the actual value '{1}'."
,
expected
,
actual
)
)
;
}
}
public
static
void
Equal
(
string
expected
,
string
actual
,
StringComparison
comparisonType
=
StringComparison
.
Ordinal
)
{
if
(
!
String
.
Equals
(
expected
,
actual
,
comparisonType
)
)
{
throw
new
AssertException
(
string
.
Format
(
"The expected value '{0}' was not equal to the actual value '{1}'."
,
expected
,
actual
)
)
;
}
}
public
static
void
False
(
bool
condition
)
{
if
(
condition
)
{
throw
new
AssertException
(
"The condition was not false."
)
;
}
}
public
static
void
NotNull
(
object
actual
)
{
if
(
actual
==
null
)
{
throw
new
AssertException
(
"The value was null."
)
;
}
}
public
static
void
Null
(
object
actual
)
{
if
(
actual
!=
null
)
{
throw
new
AssertException
(
"The value was not null."
)
;
}
}
public
static
void
Same
<
T
>
(
T
actual
,
T
expected
)
{
var
isTheSameInstance
=
ReferenceEquals
(
actual
,
expected
)
;
if
(
!
isTheSameInstance
)
{
throw
new
AssertException
(
string
.
Format
(
"The expected value '{0}' was not same to the actual value '{1}'"
,
expected
,
actual
)
)
;
}
}
public
static
T
Single
<
T
>
(
IEnumerable
<
T
>
values
)
{
if
(
values
==
null
)
{
throw
new
AssertException
(
"The collection was null."
)
;
}
if
(
!
values
.
Any
(
)
)
{
throw
new
AssertException
(
"The collection contained no values."
)
;
}
if
(
values
.
Count
(
)
>
1
)
{
throw
new
AssertException
(
"The collection contained more than one value."
)
;
}
return
values
.
First
(
)
;
}
public
static
IEnumerable
<
T
>
Exactly
<
T
>
(
IEnumerable
<
T
>
values
,
int
numberOfOccurrances
)
{
if
(
values
==
null
)
{
throw
new
AssertException
(
"The collection was null."
)
;
}
var
elements
=
values
.
Count
(
)
;
if
(
elements
!=
numberOfOccurrances
)
{
var
message
=
string
.
Format
(
"The collection didn't exactly contain the expected number of occurances.
\n
Actual: {0}
\n
Expected: {1}"
,
elements
,
numberOfOccurrances
)
;
throw
new
AssertException
(
message
)
;
}
return
values
;
}
public
static
void
True
(
bool
condition
)
{
if
(
!
condition
)
{
throw
new
AssertException
(
"The condition was not true"
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL