2
2
using System . Collections . Generic ;
3
3
using System . Globalization ;
4
4
using System . Linq ;
5
+ using System . Text . Json ;
5
6
using System . Threading ;
6
7
using System . Threading . Tasks ;
7
8
using System . Transactions ;
@@ -199,9 +200,9 @@ public void GetJobData_ReturnsResult_WhenJobExists()
199
200
200
201
long jobId = connection . QuerySingle < long > ( arrangeSql ,
201
202
new {
202
- InvocationData = SerializationHelper . Serialize ( InvocationData . SerializeJob ( job ) ) ,
203
+ InvocationData = new JsonParameter ( SerializationHelper . Serialize ( InvocationData . SerializeJob ( job ) ) ) ,
203
204
StateName = "Succeeded" ,
204
- Arguments = "[\" \\ \" Arguments\\ \" \" ]" ,
205
+ Arguments = new JsonParameter ( "[\" \\ \" Arguments\\ \" \" ]" , JsonParameter . ValueType . Array ) ,
205
206
} ) ;
206
207
207
208
JobData result = jobStorageConnection . GetJobData ( jobId . ToString ( CultureInfo . InvariantCulture ) ) ;
@@ -239,7 +240,7 @@ public void GetStateData_ReturnsCorrectData()
239
240
{
240
241
string createJobSql = $@ "
241
242
INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""statename"", ""createdat"")
242
- VALUES ('', '', '', NOW()) RETURNING ""id"";
243
+ VALUES ('{{}} ', '[] ', '', NOW()) RETURNING ""id"";
243
244
" ;
244
245
245
246
string createStateSql = $@ "
@@ -265,7 +266,7 @@ public void GetStateData_ReturnsCorrectData()
265
266
long jobId = connection . QuerySingle < long > ( createJobSql ) ;
266
267
267
268
long stateId = connection . QuerySingle < long > ( createStateSql ,
268
- new { JobId = jobId , Name = "Name" , Reason = "Reason" , Data = SerializationHelper . Serialize ( data ) } ) ;
269
+ new { JobId = jobId , Name = "Name" , Reason = "Reason" , Data = new JsonParameter ( SerializationHelper . Serialize ( data ) ) } ) ;
269
270
270
271
connection . Execute ( updateJobStateSql , new { JobId = jobId , StateId = stateId } ) ;
271
272
@@ -278,29 +279,6 @@ public void GetStateData_ReturnsCorrectData()
278
279
} ) ;
279
280
}
280
281
281
- [ Fact ]
282
- [ CleanDatabase ]
283
- public void GetJobData_ReturnsJobLoadException_IfThereWasADeserializationException ( )
284
- {
285
- string arrangeSql = $@ "
286
- INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""statename"", ""createdat"")
287
- VALUES (@InvocationData, @Arguments, @StateName, NOW()) RETURNING ""id""
288
- " ;
289
-
290
- UseConnections ( ( connection , jobStorageConnection ) => {
291
- long jobId = connection . QuerySingle < long > ( arrangeSql ,
292
- new {
293
- InvocationData = SerializationHelper . Serialize ( new InvocationData ( null , null , null , null ) ) ,
294
- StateName = "Succeeded" ,
295
- Arguments = "['Arguments']" ,
296
- } ) ;
297
-
298
- JobData result = jobStorageConnection . GetJobData ( jobId . ToString ( CultureInfo . InvariantCulture ) ) ;
299
-
300
- Assert . NotNull ( result . LoadException ) ;
301
- } ) ;
302
- }
303
-
304
282
[ Fact ]
305
283
[ CleanDatabase ]
306
284
public void SetParameter_ThrowsAnException_WhenJobIdIsNull ( )
@@ -329,7 +307,7 @@ public void SetParameters_CreatesNewParameter_WhenParameterWithTheGivenNameDoesN
329
307
{
330
308
string arrangeSql = $@ "
331
309
INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""createdat"")
332
- VALUES ('', '', NOW()) RETURNING ""id""
310
+ VALUES ('{{}} ', '[] ', NOW()) RETURNING ""id""
333
311
" ;
334
312
335
313
UseConnections ( ( connection , jobStorageConnection ) => {
@@ -350,7 +328,7 @@ public void SetParameter_UpdatesValue_WhenParameterWithTheGivenName_AlreadyExist
350
328
{
351
329
string arrangeSql = $@ "
352
330
INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""createdat"")
353
- VALUES ('', '', NOW()) RETURNING ""id""
331
+ VALUES ('{{}} ', '[] ', NOW()) RETURNING ""id""
354
332
" ;
355
333
356
334
UseConnections ( ( connection , jobStorageConnection ) => {
@@ -372,7 +350,7 @@ public void SetParameter_CanAcceptNulls_AsValues()
372
350
{
373
351
string arrangeSql = $@ "
374
352
INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""createdat"")
375
- VALUES ('', '', NOW()) RETURNING ""id""
353
+ VALUES ('{{}} ', '[] ', NOW()) RETURNING ""id""
376
354
" ;
377
355
378
356
UseConnections ( ( connection , jobStorageConnection ) => {
@@ -426,7 +404,7 @@ public void GetParameter_ReturnsParameterValue_WhenJobExists()
426
404
string arrangeSql = $@ "
427
405
WITH ""insertedjob"" AS (
428
406
INSERT INTO ""{ GetSchemaName ( ) } "".""job"" (""invocationdata"", ""arguments"", ""createdat"")
429
- VALUES ('', '', NOW()) RETURNING ""id""
407
+ VALUES ('{{}} ', '[] ', NOW()) RETURNING ""id""
430
408
)
431
409
INSERT INTO ""{ GetSchemaName ( ) } "".""jobparameter"" (""jobid"", ""name"", ""value"")
432
410
SELECT ""insertedjob"".""id"", @Name, @Value
@@ -522,15 +500,17 @@ public void AnnounceServer_CreatesOrUpdatesARecord()
522
500
{
523
501
UseConnections ( ( connection , jobStorageConnection ) => {
524
502
ServerContext context1 = new ServerContext {
525
- Queues = new [ ] { "critical" , "default" } ,
526
503
WorkerCount = 4 ,
504
+ Queues = new [ ] { "critical" , "default" } ,
527
505
} ;
528
506
jobStorageConnection . AnnounceServer ( "server" , context1 ) ;
529
507
530
508
dynamic server = connection . Query ( $@ "SELECT * FROM ""{ GetSchemaName ( ) } "".""server""") . Single ( ) ;
531
509
Assert . Equal ( "server" , server . id ) ;
532
- Assert . True ( ( ( string ) server . data ) . StartsWith ( "{\" WorkerCount\" :4,\" Queues\" :[\" critical\" ,\" default\" ],\" StartedAt\" :" ) ,
533
- server . data ) ;
510
+
511
+ ServerContext serverData = JsonSerializer . Deserialize < ServerContext > ( server . data ) ;
512
+ Assert . Equal ( 4 , serverData . WorkerCount ) ;
513
+ Assert . Equal ( context1 . Queues , serverData . Queues ) ;
534
514
Assert . NotNull ( server . lastheartbeat ) ;
535
515
536
516
ServerContext context2 = new ServerContext {
@@ -557,8 +537,8 @@ public void RemoveServer_RemovesAServerRecord()
557
537
{
558
538
string arrangeSql = $@ "
559
539
INSERT INTO ""{ GetSchemaName ( ) } "".""server"" (""id"", ""data"", ""lastheartbeat"")
560
- VALUES ('Server1', '', NOW()),
561
- ('Server2', '', NOW())
540
+ VALUES ('Server1', '{{}} ', NOW()),
541
+ ('Server2', '{{}} ', NOW())
562
542
" ;
563
543
564
544
UseConnections ( ( connection , jobStorageConnection ) => {
@@ -593,7 +573,7 @@ public void Heartbeat_UpdatesLastHeartbeat_OfTheServerWithGivenId()
593
573
{
594
574
string arrangeSql = $@ "
595
575
INSERT INTO ""{ GetSchemaName ( ) } "".""server"" (""id"", ""data"", ""lastheartbeat"")
596
- VALUES ('server1', '', '2012-12-12 12:12:12'), ('server2', '', '2012-12-12 12:12:12')
576
+ VALUES ('server1', '{{}} ', '2012-12-12 12:12:12'), ('server2', '{{}} ', '2012-12-12 12:12:12')
597
577
" ;
598
578
599
579
UseConnections ( ( connection , jobStorageConnection ) => {
@@ -622,7 +602,7 @@ public void RemoveTimedOutServers_DoItsWorkPerfectly()
622
602
{
623
603
string arrangeSql = $@ "
624
604
INSERT INTO ""{ GetSchemaName ( ) } "".""server"" (""id"", ""data"", ""lastheartbeat"")
625
- VALUES (@Id, '', @Heartbeat)
605
+ VALUES (@Id, '{{}} ', @Heartbeat)
626
606
" ;
627
607
628
608
UseConnections ( ( connection , jobStorageConnection ) => {
0 commit comments