22using EntityDb . Abstractions . Leases ;
33using EntityDb . Abstractions . Loggers ;
44using EntityDb . Abstractions . Queries ;
5- using EntityDb . Abstractions . Strategies ;
65using EntityDb . Abstractions . Tags ;
76using EntityDb . Abstractions . Transactions ;
87using EntityDb . Common . Entities ;
1716using EntityDb . TestImplementations . Entities ;
1817using EntityDb . TestImplementations . Leases ;
1918using EntityDb . TestImplementations . Queries ;
19+ using EntityDb . TestImplementations . Seeders ;
2020using EntityDb . TestImplementations . Source ;
2121using EntityDb . TestImplementations . Tags ;
2222using Microsoft . Extensions . DependencyInjection ;
@@ -411,24 +411,7 @@ public async Task GivenReadOnlyMode_WhenPuttingTransaction_ThenThrow()
411411 {
412412 // ARRANGE
413413
414- var transaction = new Transaction < TransactionEntity >
415- {
416- Id = Guid . NewGuid ( ) ,
417- TimeStamp = DateTime . UtcNow ,
418- Source = new NoSource ( ) ,
419- Commands = new [ ]
420- {
421- new TransactionCommand < TransactionEntity >
422- {
423- NextEntitySnapshot = default ! ,
424- EntityId = Guid . NewGuid ( ) ,
425- NextEntityVersionNumber = 1 ,
426- Command = new DoNothing ( ) ,
427- Leases = new TransactionMetaData < ILease > ( ) ,
428- Tags = new TransactionMetaData < ITag > ( )
429- }
430- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
431- } ;
414+ var transaction = TransactionSeeder . Create ( 1 , 1 ) ;
432415
433416 await using var transactionRepository = await CreateRepository ( true ) ;
434417
@@ -445,34 +428,15 @@ public async Task GivenNonUniqueTransactionIds_WhenPuttingTransactions_ThenSecon
445428
446429 var transactionId = Guid . NewGuid ( ) ;
447430
448- static ITransaction < TransactionEntity > NewTransaction ( Guid transactionId )
449- {
450- return new Transaction < TransactionEntity >
451- {
452- Id = transactionId ,
453- TimeStamp = DateTime . UtcNow ,
454- Source = new NoSource ( ) ,
455- Commands = new [ ]
456- {
457- new TransactionCommand < TransactionEntity >
458- {
459- NextEntitySnapshot = default ! ,
460- EntityId = Guid . NewGuid ( ) ,
461- NextEntityVersionNumber = 1 ,
462- Command = new DoNothing ( ) ,
463- Leases = new TransactionMetaData < ILease > ( ) ,
464- Tags = new TransactionMetaData < ITag > ( )
465- }
466- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
467- } ;
468- }
431+ var firstTransaction = TransactionSeeder . Create ( 1 , 1 , transactionId : transactionId ) ;
432+ var secondTransaction = TransactionSeeder . Create ( 1 , 1 , transactionId : transactionId ) ;
469433
470434 await using var transactionRepository = await CreateRepository ( ) ;
471435
472436 // ACT
473437
474- var firstTransactionInserted = await transactionRepository . PutTransaction ( NewTransaction ( transactionId ) ) ;
475- var secondTransactionInserted = await transactionRepository . PutTransaction ( NewTransaction ( transactionId ) ) ;
438+ var firstTransactionInserted = await transactionRepository . PutTransaction ( firstTransaction ) ;
439+ var secondTransactionInserted = await transactionRepository . PutTransaction ( secondTransaction ) ;
476440
477441 // ASSERT
478442
@@ -485,36 +449,7 @@ public async Task GivenNonUniqueVersionNumbers_WhenInsertingCommands_ThenReturnF
485449 {
486450 // ARRANGE
487451
488- var entityId = Guid . NewGuid ( ) ;
489- const ulong entityVersionNumber = 1 ;
490-
491- var transaction = new Transaction < TransactionEntity >
492- {
493- Id = Guid . NewGuid ( ) ,
494- TimeStamp = DateTime . UtcNow ,
495- Source = new NoSource ( ) ,
496- Commands = new [ ]
497- {
498- new TransactionCommand < TransactionEntity >
499- {
500- NextEntitySnapshot = default ! ,
501- EntityId = entityId ,
502- NextEntityVersionNumber = entityVersionNumber ,
503- Command = new DoNothing ( ) ,
504- Leases = new TransactionMetaData < ILease > ( ) ,
505- Tags = new TransactionMetaData < ITag > ( )
506- } ,
507- new TransactionCommand < TransactionEntity >
508- {
509- NextEntitySnapshot = default ! ,
510- EntityId = entityId ,
511- NextEntityVersionNumber = entityVersionNumber ,
512- Command = new DoNothing ( ) ,
513- Leases = new TransactionMetaData < ILease > ( ) ,
514- Tags = new TransactionMetaData < ITag > ( )
515- }
516- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
517- } ;
452+ var transaction = TransactionSeeder . Create ( 1 , 2 ) ;
518453
519454 await using var transactionRepository = await CreateRepository ( ) ;
520455
@@ -533,34 +468,13 @@ public async Task
533468 {
534469 // ARRANGE
535470
536- const ulong entityVersionNumber = 0 ;
537-
538- var entityId = Guid . NewGuid ( ) ;
539-
540471 var loggerMock = new Mock < ILogger > ( MockBehavior . Strict ) ;
541472
542473 loggerMock
543474 . Setup ( logger => logger . LogError ( It . IsAny < VersionZeroReservedException > ( ) , It . IsAny < string > ( ) ) )
544475 . Verifiable ( ) ;
545476
546- var transaction = new Transaction < TransactionEntity >
547- {
548- Id = Guid . NewGuid ( ) ,
549- TimeStamp = DateTime . UtcNow ,
550- Source = new NoSource ( ) ,
551- Commands = new [ ]
552- {
553- new TransactionCommand < TransactionEntity >
554- {
555- NextEntitySnapshot = default ! ,
556- EntityId = entityId ,
557- NextEntityVersionNumber = entityVersionNumber ,
558- Command = new DoNothing ( ) ,
559- Leases = new TransactionMetaData < ILease > ( ) ,
560- Tags = new TransactionMetaData < ITag > ( )
561- }
562- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
563- } ;
477+ var transaction = TransactionSeeder . Create ( 1 , 1 , wellBehavedNextEntityVersionNumber : false ) ;
564478
565479 await using var transactionRepository = await CreateRepository ( loggerOverride : loggerMock . Object ) ;
566480
@@ -582,31 +496,10 @@ public async Task
582496 {
583497 // ARRANGE
584498
585- const ulong entityVersionNumber = 1 ;
586-
587499 var entityId = Guid . NewGuid ( ) ;
588500
589- static ITransaction < TransactionEntity > NewTransaction ( Guid entityId , ulong entityVersionNumber )
590- {
591- return new Transaction < TransactionEntity >
592- {
593- Id = Guid . NewGuid ( ) ,
594- TimeStamp = DateTime . UtcNow ,
595- Source = new NoSource ( ) ,
596- Commands = new [ ]
597- {
598- new TransactionCommand < TransactionEntity >
599- {
600- NextEntitySnapshot = default ! ,
601- EntityId = entityId ,
602- NextEntityVersionNumber = entityVersionNumber ,
603- Command = new DoNothing ( ) ,
604- Leases = new TransactionMetaData < ILease > ( ) ,
605- Tags = new TransactionMetaData < ITag > ( )
606- }
607- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
608- } ;
609- }
501+ var firstTransaction = TransactionSeeder . Create ( 1 , 1 , entityId : entityId ) ;
502+ var secondTransaction = TransactionSeeder . Create ( 1 , 1 , entityId : entityId ) ;
610503
611504 var loggerMock = new Mock < ILogger > ( MockBehavior . Strict ) ;
612505
@@ -619,11 +512,17 @@ static ITransaction<TransactionEntity> NewTransaction(Guid entityId, ulong entit
619512 // ACT
620513
621514 var firstTransactionInserted =
622- await transactionRepository . PutTransaction ( NewTransaction ( entityId , entityVersionNumber ) ) ;
515+ await transactionRepository . PutTransaction ( firstTransaction ) ;
623516 var secondTransactionInserted =
624- await transactionRepository . PutTransaction ( NewTransaction ( entityId , entityVersionNumber ) ) ;
517+ await transactionRepository . PutTransaction ( secondTransaction ) ;
625518
626519 // ASSERT
520+
521+ firstTransaction . Commands . Length . ShouldBe ( 1 ) ;
522+ secondTransaction . Commands . Length . ShouldBe ( 1 ) ;
523+
524+ firstTransaction . Commands [ 0 ] . EntityId . ShouldBe ( secondTransaction . Commands [ 0 ] . EntityId ) ;
525+ firstTransaction . Commands [ 0 ] . NextEntityVersionNumber . ShouldBe ( secondTransaction . Commands [ 0 ] . NextEntityVersionNumber ) ;
627526
628527 firstTransactionInserted . ShouldBeTrue ( ) ;
629528 secondTransactionInserted . ShouldBeFalse ( ) ;
@@ -636,41 +535,7 @@ public async Task GivenNonUniqueTags_WhenInsertingTagDocuments_ThenReturnTrue()
636535 {
637536 // ARRANGE
638537
639- var tag = new Tag ( "Foo" , "Bar" ) ;
640-
641- var transaction = new Transaction < TransactionEntity >
642- {
643- Id = Guid . NewGuid ( ) ,
644- TimeStamp = DateTime . UtcNow ,
645- Source = new NoSource ( ) ,
646- Commands = new [ ]
647- {
648- new TransactionCommand < TransactionEntity >
649- {
650- NextEntitySnapshot = default ! ,
651- EntityId = Guid . NewGuid ( ) ,
652- NextEntityVersionNumber = 1 ,
653- Command = new DoNothing ( ) ,
654- Leases = new TransactionMetaData < ILease > ( ) ,
655- Tags = new TransactionMetaData < ITag >
656- {
657- Insert = new [ ] { tag } . ToImmutableArray < ITag > ( )
658- }
659- } ,
660- new TransactionCommand < TransactionEntity >
661- {
662- NextEntitySnapshot = default ! ,
663- EntityId = Guid . NewGuid ( ) ,
664- NextEntityVersionNumber = 1 ,
665- Command = new DoNothing ( ) ,
666- Leases = new TransactionMetaData < ILease > ( ) ,
667- Tags = new TransactionMetaData < ITag >
668- {
669- Insert = new [ ] { tag } . ToImmutableArray < ITag > ( )
670- }
671- }
672- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
673- } ;
538+ var transaction = TransactionSeeder . Create ( 2 , 1 , insertTag : true ) ;
674539
675540 await using var transactionRepository = await CreateRepository ( ) ;
676541
@@ -688,41 +553,7 @@ public async Task GivenNonUniqueLeases_WhenInsertingLeaseDocuments_ThenReturnFal
688553 {
689554 // ARRANGE
690555
691- var lease = new Lease ( "Foo" , "Bar" , "Baz" ) ;
692-
693- var transaction = new Transaction < TransactionEntity >
694- {
695- Id = Guid . NewGuid ( ) ,
696- TimeStamp = DateTime . UtcNow ,
697- Source = new NoSource ( ) ,
698- Commands = new [ ]
699- {
700- new TransactionCommand < TransactionEntity >
701- {
702- NextEntitySnapshot = default ! ,
703- EntityId = Guid . NewGuid ( ) ,
704- NextEntityVersionNumber = 1 ,
705- Command = new DoNothing ( ) ,
706- Leases = new TransactionMetaData < ILease >
707- {
708- Insert = new [ ] { lease } . ToImmutableArray < ILease > ( )
709- } ,
710- Tags = new TransactionMetaData < ITag > ( )
711- } ,
712- new TransactionCommand < TransactionEntity >
713- {
714- NextEntitySnapshot = default ! ,
715- EntityId = Guid . NewGuid ( ) ,
716- NextEntityVersionNumber = 1 ,
717- Command = new DoNothing ( ) ,
718- Leases = new TransactionMetaData < ILease >
719- {
720- Insert = new [ ] { lease } . ToImmutableArray < ILease > ( )
721- } ,
722- Tags = new TransactionMetaData < ITag > ( )
723- }
724- } . ToImmutableArray < ITransactionCommand < TransactionEntity > > ( )
725- } ;
556+ var transaction = TransactionSeeder . Create ( 2 , 1 , insertLease : true ) ;
726557
727558 await using var transactionRepository = await CreateRepository ( ) ;
728559
0 commit comments