-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathDuckDBDatabaseFixture.cs
More file actions
47 lines (37 loc) · 1.09 KB
/
Copy pathDuckDBDatabaseFixture.cs
File metadata and controls
47 lines (37 loc) · 1.09 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
namespace DuckDB.NET.Test;
public class DuckDBDatabaseFixture : IDisposable
{
public DuckDBDatabaseFixture()
{
Connection = new DuckDBConnection("DataSource=:memory:");
Connection.Open();
}
public void Dispose()
{
Connection.Dispose();
}
internal DuckDBConnection Connection { get; }
}
public class DuckDBTestBase : IDisposable, IClassFixture<DuckDBDatabaseFixture>
{
protected DuckDBCommand Command { get; }
protected DuckDBConnection Connection { get; }
protected Faker Faker { get; init; } = new Faker();
protected List<T> GetRandomList<T>(Func<Faker, T> generator, int? count = 20)
{
return Enumerable.Range(0, count ?? Faker.Random.Int(0, 50)).Select(i => generator(Faker)).ToList();
}
public DuckDBTestBase(DuckDBDatabaseFixture db)
{
Connection = db.Connection;
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
Command = db.Connection.CreateCommand();
}
public virtual void Dispose()
{
Command?.Dispose();
}
}