public void TestCase_GeometryValue() { var mockGeom = new Mock <IGeometry>(); mockGeom.Setup(g => g.AsText()).Returns("POINT (0 0)"); var value = new GeometryValue(); Assert.AreEqual(PropertyDefinitionType.Geometry, value.PropertyDefType); Assert.AreEqual(PropertyValueType.Geometry, value.Type); Assert.True(value.IsNull); Assert.Throws <Exception>(() => { var v = value.Value; }); Assert.Throws <Exception>(() => { var v = value.ValueAsString(); }); value.Value = mockGeom.Object; Assert.NotNull(value.Value); Assert.AreEqual("POINT (0 0)", value.ValueAsString()); Assert.False(value.IsNull); value = new GeometryValue(mockGeom.Object); Assert.False(value.IsNull); Assert.NotNull(value.Value); Assert.AreEqual("POINT (0 0)", value.ValueAsString()); value.SetNull(); Assert.True(value.IsNull); Assert.Throws <Exception>(() => { var v = value.Value; }); }
private void Bind(FdoRow row) { //Set all property values to null and then set the proper values foreach (string propName in currentValues.Keys) { //Get the [target] property name. If reverse-mapped to the [source], use the //mapped [source] property name. Otherwise it is assumed that [source] name //is the same as the [target] name string name = propName; if (_mappings[name] != null) { name = _mappings[name]; } LiteralValue lVal = currentValues[propName] as LiteralValue; if (lVal.LiteralValueType == LiteralValueType.LiteralValueType_Data) { DataValue dVal = lVal as DataValue; dVal.SetNull(); switch (dVal.DataType) { case DataType.DataType_BLOB: { byte [] blob = row[name] as byte[]; if (blob != null) { (dVal as BLOBValue).Data = blob; } } break; case DataType.DataType_Boolean: { if (row[name] != null) { (dVal as BooleanValue).Boolean = Convert.ToBoolean(row[name]); } } break; case DataType.DataType_Byte: { if (row[name] != null) { (dVal as ByteValue).Byte = Convert.ToByte(row[name]); } } break; case DataType.DataType_CLOB: { byte[] clob = row[name] as byte[]; if (clob != null) { (dVal as CLOBValue).Data = clob; } } break; case DataType.DataType_DateTime: { if (row[name] != null) { (dVal as DateTimeValue).DateTime = Convert.ToDateTime(row[name]); } } break; case DataType.DataType_Decimal: { if (row[name] != null) { (dVal as DecimalValue).Decimal = Convert.ToDouble(row[name]); } } break; case DataType.DataType_Double: { if (row[name] != null) { (dVal as DoubleValue).Double = Convert.ToDouble(row[name]); } } break; case DataType.DataType_Int16: { if (row[name] != null) { (dVal as Int16Value).Int16 = Convert.ToInt16(row[name]); } } break; case DataType.DataType_Int32: { if (row[name] != null) { (dVal as Int32Value).Int32 = Convert.ToInt32(row[name]); } } break; case DataType.DataType_Int64: { if (row[name] != null) { (dVal as Int64Value).Int64 = Convert.ToInt64(row[name]); } } break; case DataType.DataType_Single: { if (row[name] != null) { (dVal as SingleValue).Single = Convert.ToSingle(row[name]); } } break; case DataType.DataType_String: { if (row[name] != null) { (dVal as StringValue).String = row[name].ToString(); } } break; } } else { GeometryValue gVal = lVal as GeometryValue; gVal.SetNull(); IGeometry geom = row[name] as IGeometry; if (geom != null) { IGeometry origGeom = geom; //HACK: Just for you SQL Server 2008! if (geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_Polygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_CurvePolygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurvePolygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiPolygon) { if (_conn.Provider.ToUpper().StartsWith("OSGEO.SQLSERVERSPATIAL")) { //This isn't the most optimal way, as the most optimal //method according to RFC48 is to get the source rule and //strictness and pass that to SpatialUtility.GetPolygonVertexOrderAction() //along with the target rule and strictness. I don't think warping the //existing API to address such a provider-specific corner case is worth it. var caps = _clsDef.Capabilities; var rule = caps.get_PolygonVertexOrderRule(name); geom = SpatialUtility.FixPolygonVertexOrder(origGeom, rule); } } if (geom != null) { gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(geom); } else { gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(origGeom); } } } } }