5
5
using RestSharp ;
6
6
using RestSharp . Serializers . NewtonsoftJson ;
7
7
using RichardSzalay . MockHttp ;
8
+ using Shouldly ;
8
9
using System ;
9
10
using System . Collections . Generic ;
10
11
using System . IO ;
@@ -41,7 +42,7 @@ private string loadJson(string filename)
41
42
throw new Exception ( $ "Json Mock { filename } .mock.json not found. Path: { p } ") ;
42
43
}
43
44
44
- private RestClient mockRestClient < TResponse > ( string jsonfile ) where TResponse : class
45
+ private RestClient mockRestClient < TResponse > ( string jsonfile ) where TResponse : class
45
46
{
46
47
string content = this . loadJson ( jsonfile ) ;
47
48
var mockHttp = new MockHttpMessageHandler ( ) ;
@@ -53,11 +54,8 @@ private RestClient mockRestClient<TResponse>(string jsonfile) where TResponse:cl
53
54
{
54
55
ConfigureMessageHandler = _ => mockHttp ,
55
56
BaseUrl = new Uri ( "https://localhost/testapi/" ) ,
56
-
57
-
58
57
} ,
59
58
configureSerialization : s => s . UseNewtonsoftJson ( this . getJsonSettings ( ) ) ) ;
60
-
61
59
}
62
60
63
61
private IServiceProvider ServiceProvider ;
@@ -72,10 +70,8 @@ private JsonSerializerSettings getJsonSettings()
72
70
return settings ;
73
71
}
74
72
75
-
76
- private void mockServices < TResponse > ( string jsonfile ) where TResponse : class
73
+ private void mockServices < TResponse > ( string jsonfile ) where TResponse : class
77
74
{
78
-
79
75
Mock < ITheGamesDBApiWrapperRestClientFactory > mock = new Mock < ITheGamesDBApiWrapperRestClientFactory > ( ) ;
80
76
mock . Setup ( x => x . Create ( It . IsAny < string > ( ) ) ) . Returns ( ( ) => this . mockRestClient < TResponse > ( jsonfile ) ) ;
81
77
@@ -99,10 +95,10 @@ public async Task DeveloperResponseShouldBeParsed()
99
95
ITheGamesDBAPI api = this . ServiceProvider . GetService < ITheGamesDBAPI > ( ) ;
100
96
var response = await api . Developers . All ( ) ;
101
97
102
- Assert . NotNull ( response . Code ) ;
103
- Assert . NotNull ( response . Data ) ;
104
- Assert . NotNull ( response . Data . Developers ) ;
105
- Assert . NotNull ( response . Data . Developers . First ( ) . Value . Name ) ;
98
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
99
+ response . Data . ShouldNotBeNull ( ) ;
100
+ response . Data . Developers . ShouldNotBeNull ( ) ;
101
+ response . Data . Developers . First ( ) . Value . Name . ShouldNotBeNull ( ) ;
106
102
}
107
103
108
104
[ TestCaseSource ( nameof ( GameByIdMocks ) ) ]
@@ -111,35 +107,34 @@ public async Task GameByIdResponseShouldBeParsed(string mockfile)
111
107
this . mockServices < GamesByGameIDResponse > ( mockfile ) ;
112
108
113
109
ITheGamesDBAPI api = this . ServiceProvider . GetService < ITheGamesDBAPI > ( ) ;
114
- var response = await api . Games . ByGameID ( new int [ ] { 1 , 2 , 3 , 4 , 5 } ) ;
110
+ var response = await api . Games . ByGameID ( new int [ ] { 1 , 2 , 3 , 4 , 5 } ) ;
115
111
116
- Assert . NotNull ( response . Code ) ;
117
- Assert . NotNull ( response . Data ) ;
118
- Assert . NotNull ( response . Data . Games ) ;
119
- Assert . NotNull ( response . Data . Games . First ( ) . GameTitle ) ;
112
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
113
+ response . Data . ShouldNotBeNull ( ) ;
114
+ response . Data . Games . ShouldNotBeNull ( ) ;
115
+ response . Data . Games . First ( ) . GameTitle . ShouldNotBeNull ( ) ;
120
116
}
121
117
122
118
public static object [ ] GameByIdMocks = {
123
- new object [ ] { "game-by-id" } ,
124
- new object [ ] { "game-by-id-2" }
125
- } ;
119
+ new object [ ] { "game-by-id" } ,
120
+ new object [ ] { "game-by-id-2" }
121
+ } ;
126
122
127
123
[ Test ]
128
124
public async Task GameImagesResponseShouldBeParsed ( )
129
125
{
130
126
this . mockServices < GamesImagesResponse > ( "game-images" ) ;
131
127
132
128
ITheGamesDBAPI api = this . ServiceProvider . GetService < ITheGamesDBAPI > ( ) ;
133
- var response = await api . Games . Images ( new int [ ] { 1 } ) ;
134
-
135
- Assert . NotNull ( response . Code ) ;
136
- Assert . NotNull ( response . Data ) ;
137
- Assert . NotNull ( response . Data . BaseUrl ) ;
138
- Assert . NotNull ( response . Pages ) ;
139
- Assert . NotNull ( response . Data . Images ) ;
140
- Assert . NotNull ( response . Data . Images . First ( ) . Value . First ( ) . Type ) ;
141
- Assert . AreEqual ( response . Data . Images . First ( ) . Value . First ( ) . Type , GameImageType . Fanart ) ;
142
-
129
+ var response = await api . Games . Images ( new int [ ] { 1 } ) ;
130
+
131
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
132
+ response . Data . ShouldNotBeNull ( ) ;
133
+ response . Data . BaseUrl . ShouldNotBeNull ( ) ;
134
+ response . Pages . ShouldNotBeNull ( ) ;
135
+ response . Data . Images . ShouldNotBeNull ( ) ;
136
+ response . Data . Images . First ( ) . Value . First ( ) . Type . ShouldNotBeNull ( ) ;
137
+ response . Data . Images . First ( ) . Value . First ( ) . Type . ShouldBe ( GameImageType . Fanart ) ;
143
138
}
144
139
145
140
[ Test ]
@@ -151,16 +146,14 @@ public async Task GameUpdateResponseShouldBeParsed()
151
146
152
147
var response = await api . Games . Updates ( 0 ) ;
153
148
154
- Assert . NotNull ( response . Code ) ;
155
- Assert . NotNull ( response . Data ) ;
156
- Assert . NotNull ( response . Data . Updates ) ;
157
- Assert . NotNull ( response . Data . Updates . First ( ) . EditID ) ;
158
- Assert . NotNull ( response . Data . Updates . First ( ) . GameID ) ;
159
- Assert . NotNull ( response . Data . Updates . First ( ) . Timestamp ) ;
160
- Assert . NotNull ( response . Data . Updates . First ( ) . Type ) ;
161
- Assert . NotNull ( response . Data . Updates . First ( ) . Value ) ;
162
-
163
-
149
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
150
+ response . Data . ShouldNotBeNull ( ) ;
151
+ response . Data . Updates . ShouldNotBeNull ( ) ;
152
+ response . Data . Updates . First ( ) . EditID . ShouldNotBeNull ( ) ;
153
+ response . Data . Updates . First ( ) . GameID . ShouldNotBeNull ( ) ;
154
+ response . Data . Updates . First ( ) . Timestamp . ShouldNotBeNull ( ) ;
155
+ response . Data . Updates . First ( ) . Type . ShouldNotBeNull ( ) ;
156
+ response . Data . Updates . First ( ) . Value . ShouldNotBeNull ( ) ;
164
157
}
165
158
166
159
[ Test ]
@@ -172,11 +165,10 @@ public async Task PlatformsResponseShouldBeParsed()
172
165
173
166
var response = await api . Platform . All ( ) ;
174
167
175
- Assert . NotNull ( response . Code ) ;
176
- Assert . NotNull ( response . Data ) ;
177
- Assert . NotNull ( response . Data . Platforms ) ;
178
- Assert . NotNull ( response . Data . Platforms . First ( ) . Value . Name ) ;
179
-
168
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
169
+ response . Data . ShouldNotBeNull ( ) ;
170
+ response . Data . Platforms . ShouldNotBeNull ( ) ;
171
+ response . Data . Platforms . First ( ) . Value . Name . ShouldNotBeNull ( ) ;
180
172
}
181
173
182
174
[ Test ]
@@ -188,11 +180,10 @@ public async Task GenresResponseShouldBeParsed()
188
180
189
181
var response = await api . Genres . All ( ) ;
190
182
191
-
192
- Assert . NotNull ( response . Code ) ;
193
- Assert . NotNull ( response . Data ) ;
194
- Assert . NotNull ( response . Data . Genres ) ;
195
- Assert . NotNull ( response . Data . Genres . First ( ) . Value . Name ) ;
183
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
184
+ response . Data . ShouldNotBeNull ( ) ;
185
+ response . Data . Genres . ShouldNotBeNull ( ) ;
186
+ response . Data . Genres . First ( ) . Value . Name . ShouldNotBeNull ( ) ;
196
187
}
197
188
198
189
[ Test ]
@@ -204,11 +195,10 @@ public async Task PublishersResponseShouldBeParsed()
204
195
205
196
var response = await api . Publishers . All ( ) ;
206
197
207
-
208
- Assert . NotNull ( response . Code ) ;
209
- Assert . NotNull ( response . Data ) ;
210
- Assert . NotNull ( response . Data . Publishers ) ;
211
- Assert . NotNull ( response . Data . Publishers . First ( ) . Value . Name ) ;
198
+ response . Code . ShouldBeGreaterThan ( 0 ) ;
199
+ response . Data . ShouldNotBeNull ( ) ;
200
+ response . Data . Publishers . ShouldNotBeNull ( ) ;
201
+ response . Data . Publishers . First ( ) . Value . Name . ShouldNotBeNull ( ) ;
212
202
}
213
203
214
204
[ Test ]
@@ -221,12 +211,11 @@ public async Task AllowanceShouldBeTracked()
221
211
222
212
IAllowanceTracker tracker = this . ServiceProvider . GetService < IAllowanceTracker > ( ) ;
223
213
224
- Assert . NotNull ( tracker . Current ) ;
225
- Assert . AreEqual ( 2916 , tracker . Current . Remaining ) ;
226
- Assert . AreSame ( api . AllowanceTrack , tracker . Current ) ;
214
+ tracker . Current . ShouldNotBeNull ( ) ;
215
+ tracker . Current . Remaining . ShouldBe ( 2916 ) ;
216
+ api . AllowanceTrack . ShouldBeSameAs ( tracker . Current ) ;
227
217
}
228
218
229
219
#endregion
230
-
231
220
}
232
221
}
0 commit comments