This repository was archived by the owner on Sep 3, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 using System . Net ;
77 using System . Net . Http ;
88 using System . Net . Http . Headers ;
9- using System . Reflection ;
109 using System . Threading . Tasks ;
1110 using Newtonsoft . Json . Linq ;
1211 using Shouldly ;
@@ -285,17 +284,12 @@ public static IEnumerable<object[]> BadExpectedVersionCases()
285284 {
286285 var random = new Random ( ) ;
287286
288- var minimum = ( from fieldInfo in typeof ( ExpectedVersion )
289- . GetFields ( BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy )
290- where fieldInfo . IsLiteral
291- && ! fieldInfo . IsInitOnly
292- && fieldInfo . FieldType == typeof ( int )
293- select ( int ) fieldInfo . GetRawConstantValue ( ) ) . Min ( ) - 1 ;
287+ var maximumBadExpectedVersion = Constants . Headers . MinimumExpectedVersion - 1 ;
294288
295- yield return new object [ ] { minimum } ;
289+ yield return new object [ ] { maximumBadExpectedVersion } ;
296290 for ( var i = 0 ; i < 5 ; i ++ )
297291 {
298- yield return new object [ ] { random . Next ( int . MinValue , minimum ) } ;
292+ yield return new object [ ] { random . Next ( int . MinValue , maximumBadExpectedVersion ) } ;
299293 }
300294 }
301295
Original file line number Diff line number Diff line change 11namespace SqlStreamStore . HAL
22{
3+ using System . Linq ;
4+ using System . Reflection ;
35 using Microsoft . AspNetCore . Http ;
6+ using SqlStreamStore . Streams ;
47
58 internal static class Constants
69 {
@@ -13,6 +16,13 @@ public static class MediaTypes
1316
1417 public static class Headers
1518 {
19+ public static int MinimumExpectedVersion = ( from fieldInfo in typeof ( ExpectedVersion )
20+ . GetFields ( BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy )
21+ where fieldInfo . IsLiteral
22+ && ! fieldInfo . IsInitOnly
23+ && fieldInfo . FieldType == typeof ( int )
24+ select ( int ) fieldInfo . GetRawConstantValue ( ) ) . Min ( ) ;
25+
1626 public const string ExpectedVersion = "SSS-ExpectedVersion" ;
1727 public const string HeadPosition = "SSS-HeadPosition" ;
1828 public const string Location = "Location" ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public async Task<Response> Post(
2929 AppendStreamOperation operation ,
3030 CancellationToken cancellationToken )
3131 {
32- if ( operation . ExpectedVersion < ExpectedVersion . NoStream )
32+ if ( operation . ExpectedVersion < Constants . Headers . MinimumExpectedVersion )
3333 {
3434 return new HalJsonResponse ( new HALResponse ( new
3535 {
You can’t perform that action at this time.
0 commit comments