-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathErrorHandlingTests.cs
More file actions
101 lines (92 loc) · 2.97 KB
/
Copy pathErrorHandlingTests.cs
File metadata and controls
101 lines (92 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace NpgsqlRestTests;
public static partial class Database
{
public static void ErrorHandlingTests()
{
script.Append(@"
create function raise_exception()
returns text
language plpgsql
as
$$
begin
raise exception 'Test exception';
return 'test';
end;
$$;
create function assert_failure_exception()
returns text
language plpgsql
as
$$
begin
assert false, 'Test assert failure';
return 'test';
end;
$$;
create function division_by_zero_exception(
_meta json = null
)
returns text
language plpgsql
as
$$
declare
_result int = 1 / 0;
begin
return 'test';
end;
$$;
create function custom_division_by_zero_exception(
_meta json = null
)
returns text
language plpgsql
as
$$
declare
_result int = 1 / 0;
begin
return 'test';
end;
$$;
comment on function custom_division_by_zero_exception(json) is 'error_code_policy test_err_policy';
");
}
}
[Collection("TestFixture")]
public class ErrorHandlingTests(TestFixture test)
{
[Fact]
public async Task Test_raise_exception_test()
{
using var result = await test.Client.PostAsync("/api/raise-exception/", null);
result.StatusCode.Should().Be(HttpStatusCode.BadRequest);
var response = await result.Content.ReadAsStringAsync();
response.Should().Be("{\"title\":\"Test exception\",\"status\":400,\"detail\":\"P0001\"}");
}
[Fact]
public async Task Test_assert_failure_exception_test()
{
using var result = await test.Client.PostAsync("/api/assert-failure-exception/", null);
result.StatusCode.Should().Be(HttpStatusCode.BadRequest);
var response = await result.Content.ReadAsStringAsync();
response.Should().Be("{\"title\":\"Test assert failure\",\"status\":400,\"detail\":\"P0004\"}");
}
[Fact]
public async Task Test_division_by_zero_exception_test()
{
using var result = await test.Client.PostAsync("/api/division-by-zero-exception/", null);
result.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
var response = await result.Content.ReadAsStringAsync();
response.Should().Be("{\"title\":\"22012: division by zero\",\"status\":500,\"detail\":\"22012\"}");
}
[Fact]
public async Task Test_custom_division_by_zero_exception()
{
using var result = await test.Client.PostAsync("/api/custom-division-by-zero-exception/", null);
result.StatusCode.Should().Be(HttpStatusCode.Conflict);
var response = await result.Content.ReadAsStringAsync();
response.Should().Be("{\"title\":\"Conflict - Custom Policy\",\"status\":409,\"detail\":\"22012\"}");
}
}