Permalink
Browse files

Added test to map string to citext

  • Loading branch information...
roji committed Jan 2, 2018
1 parent e8c763c commit a6053764ab135d619af41e83944c3d0454ced2d9
Showing with 26 additions and 0 deletions.
  1. +1 −0 .appveyor.yml
  2. +1 −0 .travis.yml
  3. +24 −0 test/Npgsql.Tests/TypeMapperTests.cs
View
@@ -18,6 +18,7 @@ install:
services:
- postgresql
before_build:
- '"C:\Program Files\PostgreSQL\9.6\bin\psql" -c "CREATE EXTENSION citext"'
- '"C:\Program Files\PostgreSQL\9.6\bin\psql" -c "CREATE EXTENSION postgis"'
- appveyor-retry dotnet restore -v Minimal
- appveyor-retry nuget restore Npgsql.sln # For VSIX
View
@@ -15,6 +15,7 @@ env:
before_script:
- psql -U postgres -c "CREATE USER npgsql_tests PASSWORD 'npgsql_tests' SUPERUSER"
- psql -U postgres -c "CREATE DATABASE npgsql_tests OWNER npgsql_tests"
- psql -U postgres -c "CREATE EXTENSION citext" npgsql_tests
- psql -U postgres -c "CREATE EXTENSION postgis" npgsql_tests
- dotnet restore -v Minimal
script:
@@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Npgsql.BackendMessages;
using Npgsql.PostgresTypes;
using Npgsql.TypeHandlers;
using Npgsql.TypeHandlers.NumericHandlers;
using Npgsql.TypeHandling;
using Npgsql.TypeMapping;
@@ -155,6 +156,29 @@ public void MandatoryMappingFields()
Assert.That(() => new NpgsqlTypeMappingBuilder{ PgTypeName = "foo" }.Build(), Throws.ArgumentException);
}
[Test]
public void StringToCitext()
{
using (var conn = OpenLocalConnection())
{
conn.TypeMapper.RemoveMapping("text");
conn.TypeMapper.AddMapping(new NpgsqlTypeMappingBuilder
{
PgTypeName = "citext",
NpgsqlDbType = NpgsqlDbType.Citext,
DbTypes = new[] { DbType.String },
ClrTypes = new[] { typeof(string) },
TypeHandlerFactory = new TextHandlerFactory()
}.Build());
using (var cmd = new NpgsqlCommand("SELECT @p = 'hello'::citext", conn))
{
cmd.Parameters.AddWithValue("p", "HeLLo");
Assert.That(cmd.ExecuteScalar(), Is.True);
}
}
}
#region Support
MyInt32HandlerFactory MapMyIntGlobally()

0 comments on commit a605376

Please sign in to comment.