diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a31c48f20..f4f8edd6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,24 @@ jobs: env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: test + clickhouse: + image: clickhouse/clickhouse-server:latest + ports: + - 8123/tcp steps: + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 3.1.x + 5.x + - uses: actions/cache@v3 + name: Cache NuGet packages + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- - name: Checkout code uses: actions/checkout@v1 - name: .NET Build @@ -49,5 +66,6 @@ jobs: OLEDBConnectionString: Provider=SQLOLEDB;Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.; PostgesConnectionString: Server=localhost;Port=${{ job.services.postgres.ports[5432] }};Database=test;User Id=postgres;Password=postgres; SqlServerConnectionString: Server=tcp:localhost,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=Password.; + ClickHouseConnectionString: Server=localhost;Port=${{ job.services.clickhouse.ports[8123] }};Username=default - name: .NET Lib Pack run: dotnet pack Build.csproj --no-build -c Release /p:PackageOutputPath=%CD%\.nupkgs /p:CI=true diff --git a/tests/Dapper.Tests/Dapper.Tests.csproj b/tests/Dapper.Tests/Dapper.Tests.csproj index b9f8b9347..a79a36b53 100644 --- a/tests/Dapper.Tests/Dapper.Tests.csproj +++ b/tests/Dapper.Tests/Dapper.Tests.csproj @@ -38,4 +38,9 @@ PreserveNewest + + + 6.5.2 + + diff --git a/tests/Dapper.Tests/Providers/ClickHouseTests.cs b/tests/Dapper.Tests/Providers/ClickHouseTests.cs new file mode 100644 index 000000000..a2024a604 --- /dev/null +++ b/tests/Dapper.Tests/Providers/ClickHouseTests.cs @@ -0,0 +1,93 @@ +#if NETCOREAPP3_1_OR_GREATER + +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; +using ClickHouse.Client.ADO; +using Xunit; +using Xunit.Sdk; + +namespace Dapper.Tests.Providers +{ + public class ClickHouseProvider : DatabaseProvider + { + public override DbProviderFactory Factory { get; } = new ClickHouseConnectionFactory(); + + public override string GetConnectionString() => + GetConnectionString("ClickHouseConnectionString", "Server=localhost;Port=8123;Username=default"); + } + + public class ClickHouseTests : TestBase + { + private ClickHouseConnection CreateConnection() => (ClickHouseConnection)Provider.GetOpenConnection(); + + public static IEnumerable SelectTestCases + { + get + { + yield return new object[] { "SELECT toInt16(-16)", (short)-16 }; + yield return new object[] { "SELECT toUInt16(16)", (ushort)16 }; + yield return new object[] { "SELECT toInt32(-32)", -32 }; + yield return new object[] { "SELECT toFloat64(64)", 64.0 }; + yield return new object[] { "SELECT 'hello'", "hello" }; + yield return new object[] { "SELECT array('hello', 'world')", new[] { "hello", "world" } }; + } + } + + [TheoryClickHouse] + [MemberData(nameof(SelectTestCases))] + public void ShouldSelect(string sql, object expected) => Assert.Equal(expected, connection.ExecuteScalar(sql)); + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class FactClickHouseAttribute : FactAttribute + { + public override string Skip + { + get { return unavailable ?? base.Skip; } + set { base.Skip = value; } + } + + private static readonly string unavailable; + + static FactClickHouseAttribute() + { + try + { + using (DatabaseProvider.Instance.GetOpenConnection()) { /* just trying to see if it works */ } + } + catch (Exception ex) + { + unavailable = $"ClickHouse is unavailable: {ex.Message}"; + } + } + } + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class TheoryClickHouseAttribute : TheoryAttribute + { + public override string Skip + { + get { return unavailable ?? base.Skip; } + set { base.Skip = value; } + } + + private static readonly string unavailable; + + static TheoryClickHouseAttribute() + { + try + { + using (DatabaseProvider.Instance.GetOpenConnection()) { /* just trying to see if it works */ } + } + catch (Exception ex) + { + unavailable = $"ClickHouse is unavailable: {ex.Message}"; + } + } + } + } +} + +#endif