|
9 | 9 |
|
10 | 10 | namespace PostgrestTests |
11 | 11 | { |
12 | | - [TestClass] |
13 | | - public class LinqTests |
14 | | - { |
15 | | - private static string baseUrl = "http://localhost:3000"; |
| 12 | + [TestClass] |
| 13 | + public class LinqTests |
| 14 | + { |
| 15 | + private static string baseUrl = "http://localhost:3000"; |
16 | 16 |
|
17 | 17 | [TestMethod("Linq: Select")] |
18 | 18 | public async Task TestLinqSelect() |
@@ -213,6 +213,63 @@ public async Task TestLinqUpdate() |
213 | 213 | Assert.IsNotNull(exists); |
214 | 214 | Assert.IsTrue(count == 1); |
215 | 215 |
|
| 216 | + var originalRecord = await client.Table<KitchenSink>().Where(x => x.Id == 1).Single(); |
| 217 | + |
| 218 | + var newRecord = await client.Table<KitchenSink>() |
| 219 | + .Set(x => new KeyValuePair<object, object>(x.BooleanValue, !originalRecord.BooleanValue)) |
| 220 | + .Set(x => new KeyValuePair<object, object>(x.IntValue, originalRecord.IntValue + 1)) |
| 221 | + .Set(x => new KeyValuePair<object, object>(x.FloatValue, originalRecord.FloatValue + 1)) |
| 222 | + .Set(x => new KeyValuePair<object, object>(x.DoubleValue, originalRecord.DoubleValue + 1)) |
| 223 | + .Set(x => new KeyValuePair<object, object>(x.DateTimeValue, DateTime.Now)) |
| 224 | + .Set(x => new KeyValuePair<object, object>(x.ListOfStrings, new List<string>(originalRecord.ListOfStrings) |
| 225 | + { |
| 226 | + "updated" |
| 227 | + })) |
| 228 | + .Where(x => x.Id == originalRecord.Id) |
| 229 | + .Update(new QueryOptions { Returning = QueryOptions.ReturnType.Representation }); |
| 230 | + |
| 231 | + var testRecord1 = newRecord.Models[0]; |
| 232 | + |
| 233 | + Assert.AreNotEqual(originalRecord.BooleanValue, testRecord1.BooleanValue); |
| 234 | + Assert.AreNotEqual(originalRecord.IntValue, testRecord1.IntValue); |
| 235 | + Assert.AreNotEqual(originalRecord.FloatValue, testRecord1.FloatValue); |
| 236 | + Assert.AreNotEqual(originalRecord.DoubleValue, testRecord1.DoubleValue); |
| 237 | + Assert.AreNotEqual(originalRecord.DateTimeValue, testRecord1.DateTimeValue); |
| 238 | + CollectionAssert.AreNotEqual(originalRecord.ListOfStrings, testRecord1.ListOfStrings); |
| 239 | + |
| 240 | + |
| 241 | + var newRecord2 = await client.Table<KitchenSink>() |
| 242 | + .Set(x => x.BooleanValue, !testRecord1.BooleanValue) |
| 243 | + .Set(x => x.IntValue, testRecord1.IntValue + 1) |
| 244 | + .Set(x => x.FloatValue, testRecord1.FloatValue + 1) |
| 245 | + .Set(x => x.DoubleValue, testRecord1.DoubleValue + 1) |
| 246 | + .Set(x => x.DateTimeValue, DateTime.Now.AddSeconds(30)) |
| 247 | + .Set(x => x.ListOfStrings, new List<string>(testRecord1.ListOfStrings) |
| 248 | + { |
| 249 | + "updated" |
| 250 | + }) |
| 251 | + .Where(x => x.Id == testRecord1.Id) |
| 252 | + .Update(new QueryOptions { Returning = QueryOptions.ReturnType.Representation }); |
| 253 | + |
| 254 | + var testRecord2 = newRecord2.Models[0]; |
| 255 | + |
| 256 | + Assert.AreNotEqual(testRecord1.BooleanValue, testRecord2.BooleanValue); |
| 257 | + Assert.AreNotEqual(testRecord1.IntValue, testRecord2.IntValue); |
| 258 | + Assert.AreNotEqual(testRecord1.FloatValue, testRecord2.FloatValue); |
| 259 | + Assert.AreNotEqual(testRecord1.DoubleValue, testRecord2.DoubleValue); |
| 260 | + Assert.AreNotEqual(testRecord1.DateTimeValue, testRecord2.DateTimeValue); |
| 261 | + CollectionAssert.AreNotEqual(testRecord1.ListOfStrings, testRecord2.ListOfStrings); |
| 262 | + |
| 263 | + Assert.ThrowsException<ArgumentException>(() => |
| 264 | + { |
| 265 | + return client.Table<Movie>().Set(x => x.Name, DateTime.Now).Update(); |
| 266 | + }); |
| 267 | + |
| 268 | + Assert.ThrowsException<ArgumentException>(() => |
| 269 | + { |
| 270 | + return client.Table<Movie>().Set(x => DateTime.Now, newName).Update(); |
| 271 | + }); |
| 272 | + |
216 | 273 | Assert.ThrowsException<ArgumentException>(() => |
217 | 274 | { |
218 | 275 | return client.Table<Movie>().Set(x => new KeyValuePair<object, object>(x.Name, DateTime.Now)).Update(); |
|
0 commit comments