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

Commit cc14803

Browse files
actually testing docs endpoint. this will require you to generate the docs on first run / change
documenting this and the build as well
1 parent 33e6b7e commit cc14803

5 files changed

Lines changed: 108 additions & 4 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Fully RESTful HTTP Server for [SQL Stream Store](https://github.com/SQLStreamSto
44

55
The solution includes example of use LittleHalHost.Example project. The url structure and parameters are described in LittleHalHost.Example/readme.md
66

7+
# Development
8+
9+
- `./build.sh` or `./build.cmd` to run the complete dockerized build.
10+
- `dotnet run --project build/build.csproj` to build without using docker.
11+
To see a list of build targets, `dotnet run --project build/build.csproj -- --list-targets`.
12+
For general help with the build, `dotnet run --project build/build.csproj -- --help`.
13+
- If you are running test from your IDE, you _must_ build with the `GenerateDocumentation` target at least once, otherwise the tests around documentation will fail.
14+
715
# Clients
816

917
- [Official dotnet client](https://github.com/SQLStreamStore/SQLStreamStore)
@@ -15,4 +23,4 @@ Ask questions in the `#sql-stream-store` channel in the [ddd-cqrs-es slack](http
1523

1624
# Licences
1725

18-
Licenced under [MIT](LICENSE).
26+
Licenced under [MIT](LICENSE).

src/SqlStreamStore.HAL.Tests/AllJsonSchemasTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where s_isSqlStreamStoreSchema.IsMatch(manifestName)
4141
public async Task byte_order_mark_not_present(string manifestName)
4242
{
4343
byte[] firstThreeBytes = new byte[3];
44-
44+
4545
using(var stream = GetStream(manifestName))
4646
{
4747
await stream.ReadAsync(firstThreeBytes);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace SqlStreamStore.HAL.Tests
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Net;
8+
using System.Net.Http;
9+
using System.Net.Http.Headers;
10+
using System.Threading.Tasks;
11+
using Shouldly;
12+
using SqlStreamStore.HAL.StreamMessage;
13+
using SqlStreamStore.HAL.StreamMetadata;
14+
using SqlStreamStore.HAL.Streams;
15+
using Xunit;
16+
17+
public class DocumentationTests : IDisposable
18+
{
19+
private static readonly MediaTypeWithQualityHeaderValue[] s_MarkdownMediaTypes =
20+
{
21+
new MediaTypeWithQualityHeaderValue(Constants.MediaTypes.TextMarkdown),
22+
new MediaTypeWithQualityHeaderValue(Constants.MediaTypes.TextMarkdown)
23+
{
24+
CharSet = "utf-8"
25+
},
26+
new MediaTypeWithQualityHeaderValue(Constants.MediaTypes.Any)
27+
};
28+
private static readonly IDictionary<string, Type> s_documentedRels = new Dictionary<string, Type>
29+
{
30+
["append"] = typeof(StreamResource),
31+
["delete-stream"] = typeof(StreamResource),
32+
["delete-message"] = typeof(StreamMessageResource),
33+
["metadata"] = typeof(StreamMetadataResource)
34+
};
35+
36+
private readonly SqlStreamStoreHalMiddlewareFixture _fixture;
37+
38+
public DocumentationTests()
39+
{
40+
_fixture = new SqlStreamStoreHalMiddlewareFixture();
41+
}
42+
43+
public static IEnumerable<object[]> DocumentationCases()
44+
=> from pair in s_documentedRels
45+
from mediaType in s_MarkdownMediaTypes
46+
select new object[]
47+
{
48+
pair.Key,
49+
mediaType,
50+
pair.Value.Assembly.GetManifestResourceStream(pair.Value, $"Schema.{pair.Key}.schema.md")
51+
};
52+
53+
[Fact]
54+
public async Task documentation_not_found()
55+
{
56+
using(var response = await _fixture.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"/docs/{Guid.NewGuid()}")
57+
{
58+
Headers = { Accept = { MediaTypeWithQualityHeaderValue.Parse(Constants.MediaTypes.TextMarkdown) } }
59+
}))
60+
{
61+
response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
62+
}
63+
}
64+
65+
[Theory, MemberData(nameof(DocumentationCases))]
66+
public async Task documentation(string rel, MediaTypeWithQualityHeaderValue accept, Stream content)
67+
{
68+
content.ShouldNotBeNull();
69+
70+
using (var expectedDocument = new MemoryStream())
71+
using (var actualDocument = new MemoryStream())
72+
using(var response = await _fixture.HttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"/docs/{rel}")
73+
{
74+
Headers = { Accept = { accept } }
75+
}))
76+
{
77+
response.StatusCode.ShouldBe(HttpStatusCode.OK);
78+
79+
await content.CopyToAsync(expectedDocument);
80+
81+
await response.Content.CopyToAsync(actualDocument);
82+
83+
expectedDocument.ToArray().ShouldBe(actualDocument.ToArray());
84+
}
85+
}
86+
87+
public void Dispose() => _fixture.Dispose();
88+
}
89+
}

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class Constants
99
{
1010
public static class MediaTypes
1111
{
12-
public const string TextMarkdown = "text/markdown; charset=UTF-8";
12+
public const string TextMarkdown = "text/markdown";
1313
public const string HalJson = "application/hal+json";
1414
public const string Any = "*/*";
1515
}

src/SqlStreamStore.HAL/MarkdownResponse.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
namespace SqlStreamStore.HAL
22
{
33
using System.IO;
4+
using System.Net.Http.Headers;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Microsoft.AspNetCore.Http;
78

89
internal class MarkdownResponse : Response
910
{
11+
private static readonly string s_TextMarkdown
12+
= new MediaTypeHeaderValue(Constants.MediaTypes.TextMarkdown)
13+
{
14+
CharSet = "utf-8"
15+
}.ToString();
16+
1017
private readonly Stream _body;
1118

1219
public MarkdownResponse(Stream body)
13-
: base(body == null ? 404 : 200, Constants.MediaTypes.TextMarkdown)
20+
: base(body == null ? 404 : 200, s_TextMarkdown)
1421
{
1522
_body = body;
1623
}

0 commit comments

Comments
 (0)