Skip to content

Commit 2837480

Browse files
authored
Add DuckDB tests (#1970)
* Add DuckDB tests * Update DuckDB.NET.Data.Full version
1 parent a37b151 commit 2837480

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project>
22
<ItemGroup>
33
<!-- note: 6.2.0 has regressions; don't force the update -->
4+
<PackageVersion Include="DuckDB.NET.Data.Full" Version="0.9.0.3" />
45
<PackageVersion Include="EntityFramework" Version="6.1.3" />
56
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
67
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />

tests/Dapper.Tests/Dapper.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ItemGroup>
1616
<ProjectReference Include="../../Dapper.ProviderTools/Dapper.ProviderTools.csproj" />
1717
<ProjectReference Include="../../Dapper.SqlBuilder/Dapper.SqlBuilder.csproj" />
18+
<PackageReference Include="DuckDB.NET.Data.Full" />
1819
<PackageReference Include="FirebirdSql.Data.FirebirdClient" />
1920
<PackageReference Include="Microsoft.Data.SqlClient" />
2021
<PackageReference Include="Microsoft.Data.Sqlite" />
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Data.Common;
3+
using DuckDB.NET.Data;
4+
using Xunit;
5+
6+
namespace Dapper.Tests
7+
{
8+
public class DuckDBProvider : DatabaseProvider
9+
{
10+
public override DbProviderFactory Factory => DuckDBClientFactory.Instance;
11+
public override string GetConnectionString() => "Data Source=:memory:";
12+
}
13+
14+
public abstract class DuckDBTypeTestBase : TestBase<DuckDBProvider>
15+
{
16+
protected DuckDBConnection GetDuckDBConnection(bool open = true)
17+
=> (DuckDBConnection)(open ? Provider.GetOpenConnection() : Provider.GetClosedConnection());
18+
19+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
20+
public class FactDuckDBAttribute : FactAttribute
21+
{
22+
public override string? Skip
23+
{
24+
get { return unavailable ?? base.Skip; }
25+
set { base.Skip = value; }
26+
}
27+
28+
private static readonly string? unavailable;
29+
30+
static FactDuckDBAttribute()
31+
{
32+
try
33+
{
34+
using var _ = DatabaseProvider<DuckDBProvider>.Instance.GetOpenConnection();
35+
}
36+
catch (Exception ex)
37+
{
38+
unavailable = $"DuckDB is unavailable: {ex.Message}";
39+
}
40+
}
41+
}
42+
}
43+
44+
public class DuckDBTests : DuckDBTypeTestBase
45+
{
46+
[FactDuckDB]
47+
public void DuckDBNamedParameter()
48+
{
49+
using var connection = GetDuckDBConnection();
50+
51+
var result = connection.QueryFirst<int>("Select $foo", new {foo = 42});
52+
Assert.Equal(42, result);
53+
}
54+
55+
[FactDuckDB]
56+
public void DuckDBPositionalParameter()
57+
{
58+
using var connection = GetDuckDBConnection();
59+
60+
var dp = new DynamicParameters();
61+
dp.Add("?", 42);
62+
63+
var result = connection.QueryFirst<int>("Select ?", dp);
64+
Assert.Equal(42, result);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)