Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 190f29e

Browse files
added link to metadata stream
1 parent bc1bcd0 commit 190f29e

6 files changed

Lines changed: 74 additions & 43 deletions

File tree

src/SqlStreamStore.HAL.Tests/AllStreamMessageTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public async Task read_single_message_all_stream()
2929

3030
var resource = await response.AsHal();
3131

32-
resource.Links.Keys.ShouldBe(new[] { "self", "streamStore:feed" });
32+
resource.Links.Keys.ShouldBe(new[] { Constants.Relations.Self, "streamStore:feed" });
3333

34-
resource.ShouldLink("self", "/stream/0");
34+
resource.ShouldLink(Constants.Relations.Self, "/stream/0");
3535
resource.ShouldLink("streamStore:feed", HeadOfAll);
3636
}
3737
}
@@ -45,9 +45,9 @@ public async Task read_single_message_does_not_exist_all_stream()
4545

4646
var resource = await response.AsHal();
4747

48-
resource.Links.Keys.ShouldBe(new[] { "streamStore:feed" });
48+
resource.Links.Keys.ShouldBe(new[] { Constants.Relations.Feed });
4949

50-
resource.ShouldLink("streamStore:feed", HeadOfAll);
50+
resource.ShouldLink(Constants.Relations.Feed, HeadOfAll);
5151
}
5252
}
5353
}

src/SqlStreamStore.HAL.Tests/StreamMessageTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public async Task read_single_message_stream()
2929

3030
var resource = await response.AsHal();
3131

32-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "next", "last", "streamStore:feed" });
32+
resource.Links.Keys.ShouldBe(new[] { Constants.Relations.Self, Constants.Relations.First, Constants.Relations.Next, Constants.Relations.Last, "streamStore:feed" });
3333

34-
resource.ShouldLink("self", "0");
35-
resource.ShouldLink("first", "0");
36-
resource.ShouldLink("next", "1");
37-
resource.ShouldLink("last", "-1");
38-
resource.ShouldLink("streamStore:feed", HeadOfStream);
34+
resource.ShouldLink(Constants.Relations.Self, "0");
35+
resource.ShouldLink(Constants.Relations.First, "0");
36+
resource.ShouldLink(Constants.Relations.Next, "1");
37+
resource.ShouldLink(Constants.Relations.Last, "-1");
38+
resource.ShouldLink(Constants.Relations.Feed, HeadOfStream);
3939
}
4040
}
4141

@@ -48,12 +48,12 @@ public async Task read_single_message_does_not_exist_stream()
4848

4949
var resource = await response.AsHal();
5050

51-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "last", "streamStore:feed" });
51+
resource.Links.Keys.ShouldBe(new[] { Constants.Relations.Self, Constants.Relations.First, Constants.Relations.Last, Constants.Relations.Feed });
5252

53-
resource.ShouldLink("self", "0");
54-
resource.ShouldLink("first", "0");
55-
resource.ShouldLink("last", "-1");
56-
resource.ShouldLink("streamStore:feed", HeadOfStream);
53+
resource.ShouldLink(Constants.Relations.Self, "0");
54+
resource.ShouldLink(Constants.Relations.First, "0");
55+
resource.ShouldLink(Constants.Relations.Last, "-1");
56+
resource.ShouldLink(Constants.Relations.Feed, HeadOfStream);
5757
}
5858
}
5959
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace SqlStreamStore.HAL.Tests
2+
{
3+
public class StreamMetadataTests
4+
{
5+
private readonly SqlStreamStoreHalMiddlewareFixture _fixture;
6+
7+
public StreamMetadataTests()
8+
{
9+
_fixture = new SqlStreamStoreHalMiddlewareFixture();
10+
}
11+
}
12+
}

src/SqlStreamStore.HAL.Tests/StreamNavigationTests.cs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public StreamNavigationTests()
2020
_fixture = new SqlStreamStoreHalMiddlewareFixture();
2121
}
2222

23-
2423
public void Dispose() => _fixture.Dispose();
2524

2625
public static IEnumerable<object[]> GetNoMessagesPagingCases()
@@ -29,6 +28,8 @@ public static IEnumerable<object[]> GetNoMessagesPagingCases()
2928
yield return new object[] { "a-stream", "/streams/", HttpStatusCode.NotFound };
3029
}
3130

31+
private static bool IsAllStream(string path) => path == "/stream";
32+
3233
[Theory, MemberData(nameof(GetNoMessagesPagingCases))]
3334
public async Task read_head_link_no_messages(string stream, string baseAddress, HttpStatusCode statusCode)
3435
{
@@ -38,15 +39,18 @@ public async Task read_head_link_no_messages(string stream, string baseAddress,
3839

3940
var resource = await response.AsHal();
4041

41-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "last", "streamStore:feed" });
42+
resource.ShouldLink(Constants.Relations.Self, $"{stream}?{LastLinkQuery}");
4243

43-
resource.ShouldLink("self", $"{stream}?{LastLinkQuery}");
44+
resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");
4445

45-
resource.ShouldLink("last", $"{stream}?{LastLinkQuery}");
46+
resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");
4647

47-
resource.ShouldLink("first", $"{stream}?{FirstLinkQuery}");
48+
resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{LastLinkQuery}");
4849

49-
resource.ShouldLink("streamStore:feed", $"{stream}?{LastLinkQuery}");
50+
if(!IsAllStream($"{baseAddress}{stream}"))
51+
{
52+
resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
53+
}
5054
}
5155
}
5256

@@ -67,17 +71,20 @@ public async Task read_head_link_when_multiple_pages(string stream, string baseA
6771

6872
var resource = await response.AsHal();
6973

70-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "previous", "last", "streamStore:feed" });
74+
resource.ShouldLink(Constants.Relations.Self, $"{stream}?{LastLinkQuery}");
7175

72-
resource.ShouldLink("self", $"{stream}?{LastLinkQuery}");
76+
resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");
7377

74-
resource.ShouldLink("last", $"{stream}?{LastLinkQuery}");
78+
resource.ShouldLink(Constants.Relations.Previous, $"{stream}?d=b&m=20&p=9");
7579

76-
resource.ShouldLink("previous", $"{stream}?d=b&m=20&p=9");
80+
resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");
7781

78-
resource.ShouldLink("first", $"{stream}?{FirstLinkQuery}");
82+
resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{LastLinkQuery}");
7983

80-
resource.ShouldLink("streamStore:feed", $"{stream}?{LastLinkQuery}");
84+
if(!IsAllStream($"{baseAddress}{stream}"))
85+
{
86+
resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
87+
}
8188
}
8289
}
8390

@@ -92,15 +99,18 @@ public async Task read_first_link(string stream, string baseAddress)
9299

93100
var resource = await response.AsHal();
94101

95-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "last", "streamStore:feed" });
102+
resource.ShouldLink(Constants.Relations.Self, $"{stream}?{FirstLinkQuery}");
96103

97-
resource.ShouldLink("self", $"{stream}?{FirstLinkQuery}");
104+
resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");
98105

99-
resource.ShouldLink("last", $"{stream}?{LastLinkQuery}");
106+
resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");
100107

101-
resource.ShouldLink("first", $"{stream}?{FirstLinkQuery}");
108+
resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{LastLinkQuery}");
102109

103-
resource.ShouldLink("streamStore:feed", $"{stream}?{LastLinkQuery}");
110+
if(!IsAllStream($"{baseAddress}{stream}"))
111+
{
112+
resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
113+
}
104114
}
105115
}
106116

@@ -115,18 +125,20 @@ public async Task read_first_link_when_multiple_pages(string stream, string base
115125

116126
var resource = await response.AsHal();
117127

118-
resource.Links.Keys.ShouldBe(new[] { "self", "first", "next", "last", "streamStore:feed" });
128+
resource.ShouldLink(Constants.Relations.Self, $"{stream}?{FirstLinkQuery}");
119129

130+
resource.ShouldLink(Constants.Relations.Last, $"{stream}?{LastLinkQuery}");
120131

121-
resource.ShouldLink("self", $"{stream}?{FirstLinkQuery}");
132+
resource.ShouldLink(Constants.Relations.Next, $"{stream}?d=f&m=20&p=20");
122133

123-
resource.ShouldLink("last", $"{stream}?{LastLinkQuery}");
134+
resource.ShouldLink(Constants.Relations.First, $"{stream}?{FirstLinkQuery}");
124135

125-
resource.ShouldLink("next", $"{stream}?d=f&m=20&p=20");
136+
resource.ShouldLink(Constants.Relations.Feed, $"{stream}?{LastLinkQuery}");
126137

127-
resource.ShouldLink("first", $"{stream}?{FirstLinkQuery}");
128-
129-
resource.ShouldLink("streamStore:feed", $"{stream}?{LastLinkQuery}");
138+
if(!IsAllStream($"{baseAddress}{stream}"))
139+
{
140+
resource.ShouldLink(Constants.Relations.Metadata, $"{stream}/metadata");
141+
}
130142
}
131143
}
132144

@@ -137,14 +149,14 @@ public async Task read_stream_should_include_the_last_position_and_version()
137149

138150
var page = await _fixture.StreamStore.ReadStreamForwards("a-stream", StreamVersion.Start, 10, false);
139151

140-
using(var response = await _fixture.HttpClient.GetAsync($"/streams/a-stream"))
152+
using(var response = await _fixture.HttpClient.GetAsync("/streams/a-stream"))
141153
{
142154
response.StatusCode.ShouldBe(HttpStatusCode.OK);
143155

144156
var resource = await response.AsHal();
145-
146-
((int)resource.State.lastStreamVersion).ShouldBe(page.LastStreamVersion);
147-
((long)resource.State.lastStreamPosition).ShouldBe(page.LastStreamPosition);
157+
158+
((int) resource.State.lastStreamVersion).ShouldBe(page.LastStreamVersion);
159+
((long) resource.State.lastStreamPosition).ShouldBe(page.LastStreamPosition);
148160
}
149161
}
150162
}

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static class Relations
2828
public const string Last = "last";
2929
public const string Feed = "streamStore:feed";
3030
public const string Message = "streamStore:message";
31+
public const string Metadata = "streamStore:metadata";
3132
}
3233

3334
public static class Streams

src/SqlStreamStore.HAL/StreamResource.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public async Task<Response> GetPage(ReadStreamOptions options, CancellationToken
114114
.AddLinks(StreamLinks.Self(options))
115115
.AddLinks(StreamLinks.Navigation(page, options))
116116
.AddLinks(StreamLinks.Feed(page, options))
117+
.AddLinks(StreamLinks.Metadata(options))
117118
.AddEmbeddedCollection(
118119
Constants.Relations.Message,
119120
page.Messages.Zip(payloads,
@@ -284,6 +285,11 @@ public static Link Feed(AppendStreamOptions options)
284285
Constants.MaxCount,
285286
StreamVersion.End,
286287
false));
288+
289+
public static Link Metadata(ReadStreamOptions options)
290+
=> new Link(
291+
Constants.Relations.Metadata,
292+
$"{options.StreamId}/metadata");
287293

288294
public static IEnumerable<Link> Navigation(ReadStreamPage page, ReadStreamOptions options)
289295
{

0 commit comments

Comments
 (0)