Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DuckDB tests #1970

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -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" />
Expand Down
1 change: 1 addition & 0 deletions tests/Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
67 changes: 67 additions & 0 deletions tests/Dapper.Tests/Providers/DuckDBTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}