|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Data; |
3 | 4 | using System.Linq;
|
4 | 5 | using System.Threading.Tasks;
|
5 | 6 | using Npgsql;
|
@@ -111,16 +112,60 @@ public async Task TestAllTypesExample()
|
111 | 112 | Assert.Equal("127.0.0.1", row["ip"]);
|
112 | 113 |
|
113 | 114 | // Container types
|
| 115 | + // FIXME: While doing conversations with ARRAY types works natively, |
| 116 | + // it doesn't work for OBJECT types. |
| 117 | + // Yet, they can be submitted as STRING in JSON format. |
114 | 118 | Assert.Equal(new List<string>{"foo", "bar"}, row["array"]);
|
115 |
| - Assert.Equal(DBNull.Value, row["object"]); // FIXME |
| 119 | + Assert.Equal(@"{""foo"":""bar""}", row["object"]); |
| 120 | + |
116 | 121 | // Geospatial types
|
| 122 | + // TODO: Unlock native data types? |
| 123 | + // GEO_POINT and GEO_SHAPE types can be marshalled back and forth using STRING. |
| 124 | + // GEO_POINT is using a tuple format, GEO_SHAPE is using the GeoJSON format. |
117 | 125 | // Assert.Equal(new List<double>{85.43, 66.23}, row["geopoint"]); // TODO
|
118 | 126 | Assert.Equal("(85.42999997735023,66.22999997343868)", row["geopoint"].ToString()); // FIXME
|
119 |
| - Assert.Equal(DBNull.Value, row["geoshape"]); // FIXME |
| 127 | + Assert.Equal(@"{""coordinates"":[[[5.0,5.0],[5.0,10.0],[10.0,10.0],[10.0,5.0],[5.0,5.0]]],""type"":""Polygon""}", row["geoshape"]); |
120 | 128 |
|
121 | 129 | // Vector type
|
122 | 130 | Assert.Equal((new List<double>{1.1, 2.2, 3.3}).Select(d => (float) d).ToArray(), row["float_vector"]);
|
123 | 131 | }
|
124 | 132 |
|
| 133 | + [Fact] |
| 134 | + public async Task TestContainerTypesExample() |
| 135 | + { |
| 136 | + var conn = fixture.Db; |
| 137 | + |
| 138 | + // Invoke database workload. |
| 139 | + var task = DatabaseWorkloadsMore.ContainerTypesExample(conn); |
| 140 | + var dt = await task.WaitAsync(TimeSpan.FromSeconds(0.5)); |
| 141 | + |
| 142 | + // Check results. |
| 143 | + var row = dt.Rows[0]; |
| 144 | + // FIXME: While doing conversations with ARRAY types works natively, |
| 145 | + // it doesn't work for OBJECT types. |
| 146 | + // Yet, they can be submitted as STRING in JSON format. |
| 147 | + Assert.Equal(new List<string>{"foo", "bar"}, row["array"]); |
| 148 | + Assert.Equal(@"{""foo"":""bar""}", row["object"]); |
| 149 | + |
| 150 | + // Run a special query indexing into ARRAY types. |
| 151 | + await using (var cmd = new NpgsqlCommand(@"SELECT ""array[2]"" AS foo FROM testdrive.container", conn)) |
| 152 | + await using (var reader = cmd.ExecuteReader()) |
| 153 | + { |
| 154 | + var dataTable = new DataTable(); |
| 155 | + dataTable.Load(reader); |
| 156 | + Assert.Equal("bar", dataTable.Rows[0]["foo"]); |
| 157 | + } |
| 158 | + |
| 159 | + // Run a special query indexing into OBJECT types. |
| 160 | + await using (var cmd = new NpgsqlCommand(@"SELECT ""object['foo']"" AS foo FROM testdrive.container", conn)) |
| 161 | + await using (var reader = cmd.ExecuteReader()) |
| 162 | + { |
| 163 | + var dataTable = new DataTable(); |
| 164 | + dataTable.Load(reader); |
| 165 | + Assert.Equal("bar", dataTable.Rows[0]["foo"]); |
| 166 | + } |
| 167 | + |
| 168 | + } |
| 169 | + |
125 | 170 | }
|
126 | 171 | }
|
0 commit comments