diff --git a/Tests/DapperTests.csproj b/Tests/DapperTests.csproj index be8c3e97a101a8c06eda5b8fca9684542eec333b..f31614a996cee728438a694dd59d13b560a090cc 100644 --- a/Tests/DapperTests.csproj +++ b/Tests/DapperTests.csproj @@ -65,6 +65,9 @@ NHibernate\NHibernate.ByteCode.LinFu.dll + + ..\..\..\WebSites\PoolBooking\bin\Npgsql.dll + False OrmLite\ServiceStack.Common.dll @@ -183,7 +186,7 @@ DataClasses.designer.cs Designer - + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Tests/Tests.cs b/Tests/Tests.cs index 8d100a26a038047932f86f3f49fcc83705ac43bb..6df31847e579567d2caa0e7ee2472f317d7a8f97 100644 --- a/Tests/Tests.cs +++ b/Tests/Tests.cs @@ -1,4 +1,5 @@ -using System; +#define POSTGRESQL +using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; @@ -8,6 +9,10 @@ using System.Data; using System.Collections; using System.Reflection; +#if POSTGRESQL +using Dapper.Contrib.Extensions; +using Npgsql; +#endif namespace SqlMapper { @@ -1335,5 +1340,49 @@ public enum ShortEnum : short { Zero = 0, One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6 } + +#if POSTGRESQL + [Table("tcat")] + class Cat + { + [Key] + public int Id { get; set; } + public string Breed { get; set; } + public string Name { get; set; } + } + + Cat[] Cats = { + new Cat() { Breed = "Abyssinian", Name="KACTUS"}, + new Cat() { Breed = "Aegean cat", Name="KADAFFI"}, + new Cat() { Breed = "American Bobtail", Name="KANJI"}, + new Cat() { Breed = "Balinese", Name="MACARONI"}, + new Cat() { Breed = "Bombay", Name="MACAULAY"}, + new Cat() { Breed = "Burmese", Name="MACBETH"}, + new Cat() { Breed = "Chartreux", Name="MACGYVER"}, + new Cat() { Breed = "German Rex", Name="MACKENZIE"}, + new Cat() { Breed = "Javanese", Name="MADISON"}, + new Cat() { Breed = "Persian", Name="MAGNA"} + }; + + public void TestPostresqlArrayParameters() + { + using (var conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=dappertest;Password=dapperpass;Database=dappertest;Encoding=UNICODE")) + { + conn.Open(); + IDbTransaction transaction = conn.BeginTransaction(); + conn.Execute("create table tcat ( id serial not null, breed character varying(20) not null, name character varying (20) not null);"); + + foreach (var cat in Cats) + conn.Insert(cat); + + var r = conn.Query("select * from tcat where id=any(:catids)", new { catids = new[] { 1, 3, 5 } }); + r.Count().IsEqualTo(3); + r.Count(c => c.Id == 1).IsEqualTo(1); + r.Count(c => c.Id == 3).IsEqualTo(1); + r.Count(c => c.Id == 5).IsEqualTo(1); + transaction.Rollback(); + } + } +#endif } }