public void Path() { var expectedOpen = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }, true); var expectedClosed = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }, false); var cmd = new NpgsqlCommand("SELECT @p1, @p2, @p3", Conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Path) { Value = expectedOpen }; var p2 = new NpgsqlParameter("p2", NpgsqlDbType.Path) { Value = expectedClosed }; var p3 = new NpgsqlParameter { ParameterName = "p3", Value = expectedClosed }; Assert.That(p3.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Path)); cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Parameters.Add(p3); var reader = cmd.ExecuteReader(); reader.Read(); for (var i = 0; i < cmd.Parameters.Count; i++) { var expected = i == 0 ? expectedOpen : expectedClosed; Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPath))); Assert.That(reader[i], Is.EqualTo(expected)); } }
public async Task Path() { using (var conn = await OpenConnectionAsync()) { var expectedOpen = new NpgsqlPath(new[] {new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4)}, true); var expectedClosed = new NpgsqlPath(new[] {new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4)}, false); var cmd = new NpgsqlCommand("SELECT @p1, @p2, @p3", conn); var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Path) {Value = expectedOpen}; var p2 = new NpgsqlParameter("p2", NpgsqlDbType.Path) {Value = expectedClosed}; var p3 = new NpgsqlParameter {ParameterName = "p3", Value = expectedClosed}; Assert.That(p3.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Path)); cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Parameters.Add(p3); using (var reader = await cmd.ExecuteReaderAsync()) { reader.Read(); for (var i = 0; i < cmd.Parameters.Count; i++) { var expected = i == 0 ? expectedOpen : expectedClosed; Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPath))); var actual = reader.GetFieldValue<NpgsqlPath>(i); Assert.That(actual.Open, Is.EqualTo(expected.Open)); Assert.That(actual, Has.Count.EqualTo(expected.Count)); for (var j = 0; j < actual.Count; j++) AssertPointsEqual(actual[j], expected[j]); } } } }
public void TestOpenPathSupport() { _conn.Open(); NpgsqlCommand command = new NpgsqlCommand("select field_path from tablee where field_serial = 5", _conn); NpgsqlPath path = (NpgsqlPath)command.ExecuteScalar(); Assert.AreEqual(true, path.Open); Assert.AreEqual(2, path.Count); Assert.AreEqual(4, path[0].X); Assert.AreEqual(3, path[0].Y); Assert.AreEqual(5, path[1].X); Assert.AreEqual(4, path[1].Y); }
private object YieldJToken(Type ctype, JToken jt, int rank) { if (rank == 0) { if (ctype == typeof_BitArray) { return(Executer.Parse1010(jt.ToString())); } if (ctype == typeof_NpgsqlPoint) { return(NpgsqlPoint.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlLine) { return(NpgsqlLine.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlLSeg) { return(NpgsqlLSeg.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlBox) { return(NpgsqlBox.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlPath) { return(NpgsqlPath.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlPolygon) { return(NpgsqlPolygon.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlCircle) { return(NpgsqlCircle.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlInet) { return(new NpgsqlInet(jt.ToString())); } if (ctype == typeof_IPAddress) { return(new NpgsqlInet(jt.ToString())); } if (ctype == typeof_PhysicalAddress) { return(PhysicalAddress.Parse(jt.ToString())); } if (ctype == typeof_NpgsqlRange_int) { return(Executer.ParseNpgsqlRange <int>(jt.ToString())); } if (ctype == typeof_NpgsqlRange_long) { return(Executer.ParseNpgsqlRange <long>(jt.ToString())); } if (ctype == typeof_NpgsqlRange_decimal) { return(Executer.ParseNpgsqlRange <decimal>(jt.ToString())); } if (ctype == typeof_NpgsqlRange_DateTime) { return(Executer.ParseNpgsqlRange <DateTime>(jt.ToString())); } return(null); } return(jt.Select <JToken, object>(a => YieldJToken(ctype, a, rank - 1))); }
public void MainTest() { NpgsqlPoint point = new NpgsqlPoint(1, 2); NpgsqlLSeg lSeg = new NpgsqlLSeg(new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4)); NpgsqlBox box = new NpgsqlBox(new NpgsqlPoint(1, 1), new NpgsqlPoint(-1, -1)); NpgsqlPath path = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }) { Open = true }; NpgsqlPolygon polygon = new NpgsqlPolygon(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4), new NpgsqlPoint(5, 6) }); NpgsqlCircle circle = new NpgsqlCircle(new NpgsqlPoint(1, 2), 3); using (Domain.OpenSession()) { using (var t = Session.Current.OpenTransaction()) { _ = new Container { Point = new NpgsqlPoint(), LSeg = new NpgsqlLSeg(), Box = new NpgsqlBox(), Path = new NpgsqlPath(), Polygon = new NpgsqlPolygon(), Circle = new NpgsqlCircle() }; _ = new Container { Point = point, LSeg = lSeg, Box = box, Path = path, Polygon = polygon, Circle = circle }; t.Complete(); } using (var t = Session.Current.OpenTransaction()) { var record = Query.All <Container>().First(c => c.Id == 1); Console.WriteLine("The record without the initial parameters:"); OutputRecord(record); Assert.IsTrue(record.Point.Equals(new NpgsqlPoint())); Assert.IsTrue(record.LSeg.Equals(new NpgsqlLSeg())); Assert.IsTrue(record.Box.Equals(new NpgsqlBox())); Assert.IsTrue(record.Path.Equals(new NpgsqlPath(new[] { new NpgsqlPoint() }))); Assert.IsTrue(record.Polygon.Equals(new NpgsqlPolygon(new[] { new NpgsqlPoint() }))); Assert.IsTrue(record.Circle.Equals(new NpgsqlCircle())); record = Query.All <Container>().First(c => c.Id == 2); Console.WriteLine("The record with the initial parameters:"); OutputRecord(record); Assert.IsTrue(record.Point.Equals(point)); Assert.IsTrue(record.LSeg.Equals(lSeg)); Assert.IsTrue(record.Box.Equals(box)); Assert.IsTrue(record.Path.Equals(path)); Assert.IsTrue(record.Polygon.Equals(polygon)); Assert.IsTrue(record.Circle.Equals(circle)); t.Complete(); } } }