-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLiteQueryStreamTests.cs
More file actions
34 lines (31 loc) · 1.23 KB
/
Copy pathSQLiteQueryStreamTests.cs
File metadata and controls
34 lines (31 loc) · 1.23 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
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using Microsoft.Data.Sqlite;
using Xunit;
namespace DbaClientX.Tests;
public class SQLiteQueryStreamTests
{
private class CancelSqlite : DBAClientX.SQLite
{
public override async IAsyncEnumerable<DataRow> QueryStreamAsync(string database, string query, IDictionary<string, object?>? parameters = null, bool useTransaction = false, [EnumeratorCancellation] CancellationToken cancellationToken = default, IDictionary<string, SqliteType>? parameterTypes = null, IDictionary<string, ParameterDirection>? parameterDirections = null)
{
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
yield break;
}
}
[Fact]
public async Task QueryStreamAsync_CanBeCancelled()
{
using var sqlite = new CancelSqlite();
using var cts = new CancellationTokenSource(100);
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
await foreach (var _ in sqlite.QueryStreamAsync(":memory:", "q", cancellationToken: cts.Token))
{
}
});
}
}