Add optional @ prefix to annotation to keep consistency with .http fi… · NpgsqlRest/NpgsqlRest@446e947 · GitHub
Skip to content

Commit 446e947

Browse files
committed
Add optional @ prefix to annotation to keep consistency with .http file conventions
1 parent d7191a1 commit 446e947

3 files changed

Lines changed: 124 additions & 3 deletions

File tree

NpgsqlRest/Defaults/CommentParsers/Utilities.cs

Lines changed: 9 additions & 3 deletions
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
namespace NpgsqlRestTests;
2+
3+
public static partial class Database
4+
{
5+
public static void CommentAtPrefixTests()
6+
{
7+
script.Append(@"
8+
-- Test @ prefix for authorize annotation
9+
create function comment_at_authorize1() returns text language sql as 'select ''at_authorize1''';
10+
comment on function comment_at_authorize1() is 'HTTP
11+
@authorize';
12+
13+
-- Test @ prefix for raw annotation
14+
create function comment_at_raw1() returns text language sql as 'select ''col1'';';
15+
comment on function comment_at_raw1() is 'HTTP
16+
@raw';
17+
18+
-- Test @ prefix for cached annotation
19+
create function comment_at_cached1() returns int language sql as 'select 42';
20+
comment on function comment_at_cached1() is 'HTTP
21+
@cached';
22+
23+
-- Test @ prefix combined with regular annotations (mixing styles)
24+
create function comment_at_mixed1() returns text language sql as 'select ''mixed1''';
25+
comment on function comment_at_mixed1() is 'HTTP
26+
@authorize
27+
raw';
28+
");
29+
}
30+
}
31+
32+
[Collection("TestFixture")]
33+
public class CommentAtPrefixTests(TestFixture test)
34+
{
35+
[Fact]
36+
public async Task Test_at_prefix_authorize()
37+
{
38+
// @authorize should work the same as authorize
39+
using var response = await test.Client.PostAsync("/api/comment-at-authorize1/", null);
40+
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
41+
}
42+
43+
[Fact]
44+
public async Task Test_at_prefix_raw()
45+
{
46+
// @raw should work the same as raw - returns raw text without JSON formatting
47+
using var response = await test.Client.PostAsync("/api/comment-at-raw1/", null);
48+
response.StatusCode.Should().Be(HttpStatusCode.OK);
49+
var content = await response.Content.ReadAsStringAsync();
50+
content.Should().Be("col1");
51+
}
52+
53+
[Fact]
54+
public async Task Test_at_prefix_cached()
55+
{
56+
// @cached should work the same as cached
57+
using var response1 = await test.Client.PostAsync("/api/comment-at-cached1/", null);
58+
response1.StatusCode.Should().Be(HttpStatusCode.OK);
59+
var content1 = await response1.Content.ReadAsStringAsync();
60+
content1.Should().Be("42");
61+
62+
// Second call should return cached result
63+
using var response2 = await test.Client.PostAsync("/api/comment-at-cached1/", null);
64+
response2.StatusCode.Should().Be(HttpStatusCode.OK);
65+
var content2 = await response2.Content.ReadAsStringAsync();
66+
content2.Should().Be("42");
67+
}
68+
69+
[Fact]
70+
public async Task Test_at_prefix_mixed_with_regular()
71+
{
72+
// Mixed @authorize and raw should both work
73+
using var response = await test.Client.PostAsync("/api/comment-at-mixed1/", null);
74+
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
75+
}
76+
}

changelog.md

Lines changed: 39 additions & 0 deletions

0 commit comments

Comments
 (0)