-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSingleRecordTests.cs
More file actions
69 lines (58 loc) · 2.05 KB
/
Copy pathSingleRecordTests.cs
File metadata and controls
69 lines (58 loc) · 2.05 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
#pragma warning disable CS8602 // Dereference of a possibly null reference.
namespace NpgsqlRestTests;
public static partial class Database
{
public static void SingleRecordTests()
{
script.Append(
"""
create table customers (
customer_id bigint not null PRIMARY KEY,
name text NOT NULL,
email text NULL,
created_at TIMESTAMP NOT NULL default '2024-02-29'
);
comment on table customers is 'disabled';
insert into customers
(customer_id, name, email)
values
(1, 'test', 'email@email.com');
create function get_latest_customer() returns customers language sql
as $$
select *
from customers
order by created_at
limit 1
$$;
create function get_latest_customer_record() returns record language sql
as $$
select *
from customers
order by created_at
limit 1
$$;
""");
}
}
[Collection("TestFixture")]
public class SingleRecordTests(TestFixture test)
{
[Fact]
public async Task Test_get_latest_customer()
{
using var response = await test.Client.GetAsync($"/api/get-latest-customer/");
var content = await response.Content.ReadAsStringAsync();
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/json");
content.Should().Be("{\"customerId\":1,\"name\":\"test\",\"email\":\"email@email.com\",\"createdAt\":\"2024-02-29T00:00:00\"}");
}
[Fact]
public async Task Test_get_latest_customer_record()
{
using var response = await test.Client.GetAsync($"/api/get-latest-customer-record/");
var content = await response.Content.ReadAsStringAsync();
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/json");
content.Should().Be("[\"1\",\"test\",\"email@email.com\",\"2024-02-29 00:00:00\"]");
}
}