mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-17 05:12:13 +08:00
Add DuckDB tests (#1970)
* Add DuckDB tests * Update DuckDB.NET.Data.Full version
This commit is contained in:
committed by
GitHub
parent
a37b151bb7
commit
2837480903
@@ -1,6 +1,7 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<!-- note: 6.2.0 has regressions; don't force the update -->
|
||||
<PackageVersion Include="DuckDB.NET.Data.Full" Version="0.9.0.3" />
|
||||
<PackageVersion Include="EntityFramework" Version="6.1.3" />
|
||||
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../Dapper.ProviderTools/Dapper.ProviderTools.csproj" />
|
||||
<ProjectReference Include="../../Dapper.SqlBuilder/Dapper.SqlBuilder.csproj" />
|
||||
<PackageReference Include="DuckDB.NET.Data.Full" />
|
||||
<PackageReference Include="FirebirdSql.Data.FirebirdClient" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" />
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using DuckDB.NET.Data;
|
||||
using Xunit;
|
||||
|
||||
namespace Dapper.Tests
|
||||
{
|
||||
public class DuckDBProvider : DatabaseProvider
|
||||
{
|
||||
public override DbProviderFactory Factory => DuckDBClientFactory.Instance;
|
||||
public override string GetConnectionString() => "Data Source=:memory:";
|
||||
}
|
||||
|
||||
public abstract class DuckDBTypeTestBase : TestBase<DuckDBProvider>
|
||||
{
|
||||
protected DuckDBConnection GetDuckDBConnection(bool open = true)
|
||||
=> (DuckDBConnection)(open ? Provider.GetOpenConnection() : Provider.GetClosedConnection());
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public class FactDuckDBAttribute : FactAttribute
|
||||
{
|
||||
public override string? Skip
|
||||
{
|
||||
get { return unavailable ?? base.Skip; }
|
||||
set { base.Skip = value; }
|
||||
}
|
||||
|
||||
private static readonly string? unavailable;
|
||||
|
||||
static FactDuckDBAttribute()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var _ = DatabaseProvider<DuckDBProvider>.Instance.GetOpenConnection();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
unavailable = $"DuckDB is unavailable: {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DuckDBTests : DuckDBTypeTestBase
|
||||
{
|
||||
[FactDuckDB]
|
||||
public void DuckDBNamedParameter()
|
||||
{
|
||||
using var connection = GetDuckDBConnection();
|
||||
|
||||
var result = connection.QueryFirst<int>("Select $foo", new {foo = 42});
|
||||
Assert.Equal(42, result);
|
||||
}
|
||||
|
||||
[FactDuckDB]
|
||||
public void DuckDBPositionalParameter()
|
||||
{
|
||||
using var connection = GetDuckDBConnection();
|
||||
|
||||
var dp = new DynamicParameters();
|
||||
dp.Add("?", 42);
|
||||
|
||||
var result = connection.QueryFirst<int>("Select ?", dp);
|
||||
Assert.Equal(42, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user