forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAsyncTests.cs
More file actions
49 lines (44 loc) · 1.65 KB
/
AsyncTests.cs
File metadata and controls
49 lines (44 loc) · 1.65 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
using NUnit.Framework;
using System.Data;
using System.Threading.Tasks;
using static Npgsql.Tests.TestUtil;
namespace Npgsql.Tests;
public class AsyncTests : TestBase
{
[Test]
public async Task NonQuery()
{
await using var conn = await OpenConnectionAsync();
var tableName = await CreateTempTable(conn, "int INTEGER");
await using var cmd = conn.CreateCommand();
cmd.CommandText = $"INSERT INTO {tableName} (int) VALUES (4)";
await cmd.ExecuteNonQueryAsync();
Assert.That(await conn.ExecuteScalarAsync($"SELECT int FROM {tableName}"), Is.EqualTo(4));
}
[Test]
public async Task Scalar()
{
await using var conn = await OpenConnectionAsync();
await using var cmd = new NpgsqlCommand("SELECT 1", conn);
Assert.That(await cmd.ExecuteScalarAsync(), Is.EqualTo(1));
}
[Test]
public async Task Reader()
{
await using var conn = await OpenConnectionAsync();
await using var cmd = new NpgsqlCommand("SELECT 1", conn);
await using var reader = await cmd.ExecuteReaderAsync();
await reader.ReadAsync();
Assert.That(reader[0], Is.EqualTo(1));
}
[Test]
public async Task Columnar()
{
await using var conn = await OpenConnectionAsync();
await using var cmd = new NpgsqlCommand("SELECT NULL, 2, 'Some Text'", conn);
await using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess);
await reader.ReadAsync();
Assert.That(await reader.IsDBNullAsync(0), Is.True);
Assert.That(await reader.GetFieldValueAsync<string>(2), Is.EqualTo("Some Text"));
}
}