66 using Shouldly ;
77 using SqlStreamStore . Streams ;
88 using Xunit ;
9+ using System . Linq ;
910
1011 public partial class AcceptanceTests
1112 {
@@ -28,7 +29,7 @@ await Store.AppendToStream(
2829
2930 [ Fact , Trait ( "Category" , "AppendStream" ) ]
3031 public async Task
31- When_append_stream_second_time_with_no_stream_expected_and_same_messages_then_should_then_should_be_idempotent ( )
32+ When_append_stream_second_time_with_no_stream_expected_and_same_messages_then_should_be_idempotent ( )
3233 {
3334 // Idempotency
3435 const string streamId = "stream-1" ;
@@ -42,7 +43,7 @@ await Store
4243 }
4344
4445 [ Fact , Trait ( "Category" , "AppendStream" ) ]
45- public async Task When_append_stream_second_time_with_no_stream_expected_and_same_messages_then_should_then_should_have_expected_result ( )
46+ public async Task When_append_stream_second_time_with_no_stream_expected_and_same_messages_then_should_have_expected_result ( )
4647 {
4748 // Idempotency
4849 const string streamId = "stream-1" ;
@@ -665,7 +666,7 @@ await Store
665666 exception . ShouldBeOfType < WrongExpectedVersionException > (
666667 ErrorMessages . AppendFailedWrongExpectedVersion ( streamId , 10 ) ) ;
667668 }
668-
669+
669670 [ Theory , Trait ( "Category" , "AppendStream" ) ]
670671 [ InlineData ( "stream/id" ) ]
671672 [ InlineData ( "stream%id" ) ]
@@ -676,7 +677,7 @@ public async Task When_append_to_stream_with_url_encodable_characters_and_expect
676677 result . CurrentVersion . ShouldBe ( 2 ) ;
677678 result . CurrentPosition . ShouldBeGreaterThanOrEqualTo ( Fixture . MinPosition + 2L ) ;
678679 }
679-
680+
680681 [ Theory , Trait ( "Category" , "AppendStream" ) ]
681682 [ InlineData ( "stream/id" ) ]
682683 [ InlineData ( "stream%id" ) ]
@@ -699,7 +700,7 @@ public async Task When_append_to_stream_with_url_encodable_characters_and_expect
699700 result . CurrentVersion . ShouldBe ( 2 ) ;
700701 result . CurrentPosition . ShouldBeGreaterThanOrEqualTo ( Fixture . MinPosition + 2L ) ;
701702 }
702-
703+
703704 [ Theory , Trait ( "Category" , "AppendStream" ) ]
704705 [ InlineData ( "stream/id" ) ]
705706 [ InlineData ( "stream%id" ) ]
@@ -713,40 +714,56 @@ public async Task When_append_to_stream_with_url_encodable_characters_and_expect
713714 }
714715
715716 [ Fact , Trait ( "Category" , "AppendStream" ) ]
716- public async Task When_append_stream_concurrently_with_no_stream_expected_and_same_messages_then_should_then_should_have_expected_result ( )
717+ public async Task When_append_stream_concurrently_with_no_stream_expected_and_same_messages_then_should_have_expected_result ( )
717718 {
718719 // Idempotency
719720 const string streamId = "stream-1" ;
720-
721+
721722 var messages = CreateNewStreamMessages ( 1 , 2 ) ;
722723 var tasks = new List < Task < AppendResult > > ( ) ;
723- for ( var index = 0 ; index < 10 ; index ++ )
724+ for ( var index = 0 ; index < 10 ; index ++ )
724725 {
725726 tasks . Add ( Store . AppendToStream ( streamId , ExpectedVersion . NoStream , messages ) ) ;
726727 }
727-
728+
728729 var results = await Task . WhenAll ( tasks ) ;
729730
730731 Assert . All ( results , result => result . CurrentVersion . ShouldBe ( 1 ) ) ;
731732 Assert . All ( results , result => result . CurrentPosition . ShouldBe ( results [ 0 ] . CurrentPosition ) ) ;
732733 }
733-
734+
734735 [ Fact , Trait ( "Category" , "AppendStream" ) ]
735- public async Task When_append_to_different_streams_concurrently_with_no_stream_expected_and_same_messages_then_should_then_should_have_expected_result ( )
736+ public async Task When_append_to_different_streams_concurrently_with_no_stream_expected_and_same_messages_then_should_have_expected_result ( )
736737 {
737738 // Idempotency
738739 const string streamPrefix = "stream-" ;
739-
740+
740741 var messages = CreateNewStreamMessages ( 1 , 2 ) ;
741742 var tasks = new List < Task < AppendResult > > ( ) ;
742- for ( var index = 0 ; index < 10 ; index ++ )
743+ for ( var index = 0 ; index < 10 ; index ++ )
743744 {
744745 tasks . Add ( Store . AppendToStream ( streamPrefix + index , ExpectedVersion . NoStream , messages ) ) ;
745746 }
746-
747+
747748 var results = await Task . WhenAll ( tasks ) ;
748749
749750 Assert . All ( results , result => result . CurrentVersion . ShouldBe ( 1 ) ) ;
750751 }
752+
753+ [ Fact , Trait ( "Category" , "AppendStream" ) ]
754+ public async Task When_append_to_same_stream_concurrently_with_expected_version_any_and_different_messages_then_should_not_throw ( )
755+ {
756+ const string streamName = "stream" ;
757+
758+ var messages = CreateNewStreamMessages ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) ;
759+ var tasks = new List < Task < AppendResult > > ( ) ;
760+ foreach ( var message in messages )
761+ {
762+ tasks . Add ( Store . AppendToStream ( streamName , ExpectedVersion . Any , new [ ] { message } ) ) ;
763+ }
764+
765+ var results = await Task . WhenAll ( tasks ) ;
766+ results . Select ( r => r . CurrentVersion ) . Max ( ) . ShouldBe ( 9 ) ;
767+ }
751768 }
752769}
0 commit comments