-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathDuckDBClientFactoryTests.cs
More file actions
50 lines (37 loc) · 1.61 KB
/
Copy pathDuckDBClientFactoryTests.cs
File metadata and controls
50 lines (37 loc) · 1.61 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
using System.Data.Common;
using System.Diagnostics;
using DuckDB.NET.Test.Helpers;
namespace DuckDB.NET.Test;
public class DuckDBClientFactoryTests
{
[Fact]
public void RegisterFactory()
{
DbProviderFactories.RegisterFactory(DuckDBClientFactory.ProviderInvariantName, DuckDBClientFactory.Instance);
DbProviderFactories.TryGetFactory(DuckDBClientFactory.ProviderInvariantName, out var factory);
Assert.NotNull(factory);
Assert.IsType<DuckDBClientFactory>(factory);
}
[Fact]
public void UseFactory()
{
DbProviderFactories.RegisterFactory(DuckDBClientFactory.ProviderInvariantName, DuckDBClientFactory.Instance);
DbProviderFactories.TryGetFactory(DuckDBClientFactory.ProviderInvariantName, out var factory);
Assert.NotNull(factory);
using var connection = factory.CreateConnection();
using var command = factory.CreateCommand();
var parameter = factory.CreateParameter();
var connectionStringBuilder = factory.CreateConnectionStringBuilder();
connectionStringBuilder["DataSource"] = DuckDBConnectionStringBuilder.InMemoryDataSource;
connection.ConnectionString = connectionStringBuilder.ConnectionString;
command.CommandText = "Select ?::integer";
command.Connection = connection;
parameter.Value = 42;
command.Parameters.Add(parameter);
connection.Open();
using var reader = command.ExecuteReader();
reader.Read();
var value = reader.GetInt32(0);
Assert.Equal(42, value);
}
}