Skip to content

Commit

Permalink
Merge pull request DapperLib#27 from greygeek/master
Browse files Browse the repository at this point in the history
Added test for Posgresql Array parameters
  • Loading branch information
SamSaffron committed Mar 12, 2012
2 parents 29171ea + 46ed988 commit 4326bea
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Tests/DapperTests.csproj
Expand Up @@ -65,6 +65,9 @@
<Reference Include="NHibernate.ByteCode.LinFu">
<HintPath>NHibernate\NHibernate.ByteCode.LinFu.dll</HintPath>
</Reference>
<Reference Include="Npgsql">
<HintPath>..\..\..\WebSites\PoolBooking\bin\Npgsql.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Common, Version=1.0.4110.36238, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>OrmLite\ServiceStack.Common.dll</HintPath>
Expand Down Expand Up @@ -183,7 +186,7 @@
<LastGenOutput>DataClasses.designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
51 changes: 50 additions & 1 deletion Tests/Tests.cs
@@ -1,4 +1,5 @@
using System;
#define POSTGRESQL
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
Expand All @@ -8,6 +9,10 @@
using System.Data;
using System.Collections;
using System.Reflection;
#if POSTGRESQL
using Dapper.Contrib.Extensions;
using Npgsql;
#endif

namespace SqlMapper
{
Expand Down Expand Up @@ -1388,5 +1393,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<Cat>("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
}
}

0 comments on commit 4326bea

Please sign in to comment.