forked from npgsql/efcore.pg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We previously generated PostgreSQL GEOMETRY (or GEOGRAPHY) columns, not taking into account the CLR type. We now include that as a constraint on the column. Note that SRID support still needs to be done (npgsql#717). Fixes npgsql#719
- Loading branch information
Showing
2 changed files
with
157 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
test/EFCore.PG.Tests/Storage/NpgsqlNetTopologySuiteTypeMappingSourcePluginTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using GeoAPI.Geometries; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Internal; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal; | ||
using Xunit; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage | ||
{ | ||
public class NpgsqlNetTopologySuiteTypeMappingSourcePluginTest | ||
{ | ||
[Theory] | ||
[InlineData(typeof(IPoint), "GEOMETRY (POINT)")] | ||
[InlineData(typeof(IGeometry), "GEOMETRY")] | ||
[InlineData(typeof(string), null)] | ||
public void Geom_by_ClrType(Type clrType, string storeType) | ||
=> Assert.Equal(storeType, _geomPlugin.FindMapping(new RelationalTypeMappingInfo(clrType))?.StoreType); | ||
|
||
[Theory] | ||
[InlineData(typeof(IPoint), "GEOGRAPHY (POINT)")] | ||
[InlineData(typeof(IGeometry), "GEOGRAPHY")] | ||
[InlineData(typeof(string), null)] | ||
public void Geog_by_ClrType(Type clrType, string storeType) | ||
=> Assert.Equal(storeType, _geogPlugin.FindMapping(new RelationalTypeMappingInfo(clrType))?.StoreType); | ||
|
||
[Theory] | ||
[InlineData("GEOMETRY (POINT)", typeof(IPoint))] | ||
[InlineData("GEOGRAPHY (POINT)", typeof(IPoint))] | ||
[InlineData("GEOMETRY", typeof(IGeometry))] | ||
[InlineData("text", null)] | ||
public void By_StoreType(string storeType, Type clrType) | ||
=> Assert.Equal(clrType, _geomPlugin.FindMapping(new RelationalTypeMappingInfo(storeType))?.ClrType); | ||
|
||
[Theory] | ||
[MemberData(nameof(GetParseData))] | ||
public void ParseGeometryStoreType(string storeType, (bool IsGeography, string SpatialType, int? Srid)? expected) | ||
=> Assert.Equal(expected, NpgsqlNetTopologySuiteTypeMappingSourcePlugin.ParseGeometryStoreType(storeType)); | ||
|
||
static IEnumerable<object[]> GetParseData() => new[] | ||
{ | ||
new object[] { "geography (point,123)", (ValueTuple<bool, string, int?>)(true, "point", 123) }, | ||
new object[] { "GEOGRAPHY (point)", (ValueTuple<bool, string, int?>)(true, "point", null) }, | ||
new object[] { "geometry", (ValueTuple<bool, string, int?>)(false, null, null) }, | ||
new object[] { "geometry (geometry)", (ValueTuple<bool, string, int?>)(false, "geometry", null) }, | ||
new object[] { "text", null } | ||
}; | ||
|
||
readonly NpgsqlNetTopologySuiteTypeMappingSourcePlugin _geomPlugin = | ||
new NpgsqlNetTopologySuiteTypeMappingSourcePlugin(new NpgsqlNetTopologySuiteOptions()); | ||
readonly NpgsqlNetTopologySuiteTypeMappingSourcePlugin _geogPlugin = | ||
new NpgsqlNetTopologySuiteTypeMappingSourcePlugin(new NpgsqlNetTopologySuiteOptions() { IsGeographyDefault = true }); | ||
} | ||
} |