-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathReturnTableTests.cs
More file actions
142 lines (128 loc) · 4.98 KB
/
Copy pathReturnTableTests.cs
File metadata and controls
142 lines (128 loc) · 4.98 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma warning disable CS8602 // Dereference of a possibly null reference.
namespace NpgsqlRestTests;
public static partial class Database
{
public static void ReturnTableTests()
{
script.Append("""
create function case_return_table1()
returns table (
int_field int,
text_field text,
bool_field bool,
int_array int[],
text_array text[],
bool_array bool[]
)
language plpgsql
as
$$
begin
return query
select t.*
from (
values
(1, 'ABC', null, array[1,null,3], array['ABC', 'XYZ'], array[true, false]),
(2, null, false, array[1,2,3], array['ABC', null], array[false, true]),
(null, 'IJN', true, array[3,2,1], array['XYZ', 'ABC'], array[true, null])
) t;
end;
$$;
create function case_return_table2()
returns table (
"real" real,
"double" double precision,
"jsonpath" jsonpath,
"timestamp" timestamp,
"timestamptz" timestamptz,
"date" date,
"time" time,
"timetz" timetz,
"interval" interval,
"uuid" uuid,
"varbit" varbit,
"bit" bit(3),
"inet" inet,
"macaddr" macaddr,
"bytea" bytea
)
language plpgsql
as
$$
begin
return query
select t.*
from (
values
(
1.1::real, 2.2::double precision,
'$.path'::jsonpath,
'2023-01-29'::timestamp, '2023-01-30'::timestamptz, '2023-01-31'::date, '00:15:45'::time, '00:35:45'::timetz,
'1 day 10 hours 30 minutes 1 second'::interval, '1137788C-F1BA-4379-8F5A-F530CACDE300'::uuid,
'111100001'::varbit, '111100001'::bit(3),
'192.168.5.18'::inet, '00-B0-D0-63-C2-26'::macaddr,
'\xDEADBEEF'::bytea
)
) t;
end;
$$;
""");
}
}
[Collection("TestFixture")]
public class ReturnTableTests(TestFixture test)
{
[Fact]
public async Task Test_case_return_table1()
{
using var result = await test.Client.PostAsync("/api/case-return-table1/", null);
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result?.Content?.Headers?.ContentType?.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(3);
array[0]["intField"].ToJsonString().Should().Be("1");
array[0]["textField"].GetValue<string>().Should().Be("ABC");
array[0]["boolField"].Should().BeNull();
array[0]["intArray"].ToJsonString().Should().Be("[1,null,3]");
array[0]["textArray"].ToJsonString().Should().Be("[\"ABC\",\"XYZ\"]");
array[0]["boolArray"].ToJsonString().Should().Be("[true,false]");
array[1]["intField"].ToJsonString().Should().Be("2");
array[1]["textField"].Should().BeNull();
array[1]["boolField"].ToJsonString().Should().Be("false");
array[1]["intArray"].ToJsonString().Should().Be("[1,2,3]");
array[1]["textArray"].ToJsonString().Should().Be("[\"ABC\",null]");
array[1]["boolArray"].ToJsonString().Should().Be("[false,true]");
array[2]["intField"].Should().BeNull();
array[2]["textField"].GetValue<string>().Should().Be("IJN");
array[2]["boolField"].ToJsonString().Should().Be("true");
array[2]["intArray"].ToJsonString().Should().Be("[3,2,1]");
array[2]["textArray"].ToJsonString().Should().Be("[\"XYZ\",\"ABC\"]");
array[2]["boolArray"].ToJsonString().Should().Be("[true,null]");
}
[Fact]
public async Task Test_case_return_table2()
{
using var result = await test.Client.PostAsync("/api/case-return-table2/", null);
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result?.Content?.Headers?.ContentType?.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["real"].ToJsonString().Should().Be("1.1");
array[0]["double"].ToJsonString().Should().Be("2.2");
array[0]["jsonpath"].GetValue<string>().Should().Be("$.\"path\"");
array[0]["timestamp"].GetValue<string>().Should().Be("2023-01-29T00:00:00");
array[0]["timestamptz"].GetValue<string>().Should().Be("2023-01-30T00:00:00+00");
array[0]["date"].GetValue<string>().Should().Be("2023-01-31");
array[0]["time"].GetValue<string>().Should().Be("00:15:45");
array[0]["timetz"].GetValue<string>().Should().Be("00:35:45+00");
array[0]["interval"].GetValue<string>().Should().Be("1 day 10:30:01");
array[0]["uuid"].GetValue<string>().Should().Be("1137788c-f1ba-4379-8f5a-f530cacde300");
array[0]["varbit"].GetValue<string>().Should().Be("111100001");
array[0]["bit"].GetValue<string>().Should().Be("111");
array[0]["inet"].GetValue<string>().Should().Be("192.168.5.18");
array[0]["macaddr"].GetValue<string>().Should().Be("00:b0:d0:63:c2:26");
array[0]["bytea"].GetValue<string>().Should().Be("\\xdeadbeef");
}
}