From 28fa6bad259fd2c3b821bd961ab5d8c47a245018 Mon Sep 17 00:00:00 2001 From: Giorgi Date: Tue, 3 Oct 2023 17:21:08 +0400 Subject: [PATCH 1/2] Add DuckDB tests --- Directory.Packages.props | 1 + tests/Dapper.Tests/Dapper.Tests.csproj | 1 + tests/Dapper.Tests/Providers/DuckDBTests.cs | 67 +++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/Dapper.Tests/Providers/DuckDBTests.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index e8da7cb8..fc949476 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,7 @@ + diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index f3007f5c..f1e80830 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -15,6 +15,7 @@ + diff --git a/tests/Dapper.Tests/Providers/DuckDBTests.cs b/tests/Dapper.Tests/Providers/DuckDBTests.cs new file mode 100644 index 00000000..d06d25d6 --- /dev/null +++ b/tests/Dapper.Tests/Providers/DuckDBTests.cs @@ -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 + { + 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.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("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("Select ?", dp); + Assert.Equal(42, result); + } + } +} From 15802bb6de47b8051a2fa0ba10afab72ed239b7f Mon Sep 17 00:00:00 2001 From: Giorgi Date: Wed, 11 Oct 2023 00:18:55 +0400 Subject: [PATCH 2/2] Update DuckDB.NET.Data.Full version --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index fc949476..06e68e62 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,7 +1,7 @@ - +