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 @@ -26,7 +26,7 @@ public async Task read_single_message_stream()
2626 using ( var response = await _fixture . HttpClient . GetAsync ( "/streams/a-stream/0" ) )
2727 {
2828 response . StatusCode . ShouldBe ( HttpStatusCode . OK ) ;
29- response . Headers . ETag . ShouldBe ( new EntityTagHeaderValue ( $@ """{ writeResult . CurrentVersion } ; { writeResult . CurrentPosition } """));
29+ response . Headers . ETag . ShouldBe ( new EntityTagHeaderValue ( $@ """{ writeResult . CurrentVersion } """));
3030
3131 var resource = await response.AsHal();
3232
Original file line number Diff line number Diff line change 1+ namespace SqlStreamStore . HAL
2+ {
3+ using System ;
4+
5+ internal struct ETag : IEquatable < ETag >
6+ {
7+ private readonly string _value ;
8+
9+ public static ETag FromPosition ( long position ) => new ETag ( $@ """{ position } """);
10+ public static ETag FromStreamVersion(int streamVersion) => new ETag($@""" { streamVersion } """);
11+
12+ private ETag(string value)
13+ {
14+ if(value == null)
15+ {
16+ throw new ArgumentNullException(nameof(value));
17+ }
18+ if(value[0] != '"' || value[value.Length - 1] != '"')
19+ {
20+ throw new ArgumentException("ETags bust be enclosed in double quotes.", nameof(value));
21+ }
22+
23+ _value = value;
24+ }
25+
26+ public bool Equals(ETag other) => string.Equals(_value, other._value);
27+ public override bool Equals(object obj) => obj is ETag other && Equals(other);
28+ public override int GetHashCode() => _value.GetHashCode();
29+ public static bool operator ==(ETag left, ETag right) => left.Equals(right);
30+ public static bool operator !=(ETag left, ETag right) => !left.Equals(right);
31+ public static implicit operator string(ETag etag) => etag._value;
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -81,7 +81,13 @@ public async Task<Response> Get(
8181 . AddLinks ( Links . Message ( operation ) )
8282 . AddLinks ( Links . Find ( ) ) )
8383 {
84- Headers = { [ Constants . Headers . ETag ] = new [ ] { $@ """{ message . StreamVersion } ;{ message . Position } """ } }
84+ Headers =
85+ {
86+ [ Constants . Headers . ETag ] = new string [ ]
87+ {
88+ ETag . FromStreamVersion ( message . StreamVersion )
89+ }
90+ }
8591 } ;
8692 }
8793
Original file line number Diff line number Diff line change @@ -48,7 +48,13 @@ public async Task<Response> Get(
4848 Schemas . SetStreamMetadata ) ,
4949 result . MetadataStreamVersion >= 0 ? 200 : 404 )
5050 {
51- Headers = { [ Constants . Headers . ETag ] = new [ ] { $@ """{ result . MetadataStreamVersion } """ } }
51+ Headers =
52+ {
53+ [ Constants . Headers . ETag ] = new string [ ]
54+ {
55+ ETag . FromStreamVersion ( result . MetadataStreamVersion )
56+ }
57+ }
5258 } ;
5359
5460 return response ;
You can’t perform that action at this time.
0 commit comments