@@ -375,10 +375,89 @@ await Should.ThrowAsync<StreamLockedException>(async () =>
375
375
}
376
376
377
377
378
+ [ Fact ]
379
+ public async Task fetch_existing_stream_for_writing_Guid_identifier_with_expected_version_using_identity_map ( )
380
+ {
381
+ StoreOptions (
382
+ opts =>
383
+ {
384
+ opts . Events . UseIdentityMapForAggregates = true ;
385
+ opts . Projections . Snapshot < SimpleAggregate > ( SnapshotLifecycle . Inline ) ;
386
+ } ) ;
378
387
388
+ var streamId = Guid . NewGuid ( ) ;
379
389
390
+ theSession . Events . StartStream < SimpleAggregate > ( streamId , new AEvent ( ) , new BEvent ( ) , new BEvent ( ) , new BEvent ( ) ,
391
+ new CEvent ( ) , new CEvent ( ) ) ;
392
+ await theSession . SaveChangesAsync ( ) ;
380
393
394
+ var stream = await theSession . Events . FetchForWriting < SimpleAggregate > ( streamId , 6 ) ;
395
+ stream . Aggregate . ShouldNotBeNull ( ) ;
396
+ stream . CurrentVersion . ShouldBe ( 6 ) ;
397
+
398
+ stream . AppendOne ( new EEvent ( ) ) ;
399
+ await theSession . SaveChangesAsync ( ) ;
381
400
401
+ var latest = await theSession . Events . FetchLatest < SimpleAggregate > ( streamId ) ;
402
+ latest . Version . ShouldBe ( 7 ) ;
403
+ }
404
+ [ Fact ]
405
+ public async Task fetch_existing_stream_for_writing_Guid_identifier_with_expected_version_using_identity_map_immediate_sad_path ( )
406
+ {
407
+ StoreOptions (
408
+ opts =>
409
+ {
410
+ opts . Events . UseIdentityMapForAggregates = true ;
411
+ opts . Projections . Snapshot < SimpleAggregate > ( SnapshotLifecycle . Inline ) ;
412
+ } ) ;
413
+
414
+
415
+ var streamId = Guid . NewGuid ( ) ;
416
+
417
+ theSession . Events . StartStream < SimpleAggregate > ( streamId , new AEvent ( ) , new BEvent ( ) , new BEvent ( ) , new BEvent ( ) ,
418
+ new CEvent ( ) , new CEvent ( ) ) ;
419
+ await theSession . SaveChangesAsync ( ) ;
420
+
421
+ await Should . ThrowAsync < ConcurrencyException > ( async ( ) =>
422
+ {
423
+ var stream = await theSession . Events . FetchForWriting < SimpleAggregate > ( streamId , 5 ) ;
424
+ } ) ;
425
+ }
426
+
427
+ [ Fact ]
428
+ public async Task fetch_existing_stream_for_writing_Guid_identifier_with_expected_version_using_identity_map_sad_path_on_save_changes ( )
429
+ {
430
+ StoreOptions (
431
+ opts =>
432
+ {
433
+ opts . Events . UseIdentityMapForAggregates = true ;
434
+ opts . Projections . Snapshot < SimpleAggregate > ( SnapshotLifecycle . Inline ) ;
435
+ } ) ;
436
+
437
+
438
+ var streamId = Guid . NewGuid ( ) ;
439
+
440
+ theSession . Events . StartStream < SimpleAggregate > ( streamId , new AEvent ( ) , new BEvent ( ) , new BEvent ( ) , new BEvent ( ) ,
441
+ new CEvent ( ) , new CEvent ( ) ) ;
442
+ await theSession . SaveChangesAsync ( ) ;
443
+
444
+ // This should be fine
445
+ var stream = await theSession . Events . FetchForWriting < SimpleAggregate > ( streamId , 6 ) ;
446
+ stream . AppendOne ( new EEvent ( ) ) ;
447
+
448
+ // Get in between and run other events in a different session
449
+ await using ( var otherSession = theStore . LightweightSession ( ) )
450
+ {
451
+ otherSession . Events . Append ( streamId , new EEvent ( ) ) ;
452
+ await otherSession . SaveChangesAsync ( ) ;
453
+ }
454
+
455
+ // The version is now off
456
+ await Should . ThrowAsync < ConcurrencyException > ( async ( ) =>
457
+ {
458
+ await theSession . SaveChangesAsync ( ) ;
459
+ } ) ;
460
+ }
382
461
383
462
[ Fact ]
384
463
public async Task fetch_existing_stream_for_writing_Guid_identifier_with_expected_version ( )
0 commit comments