|
11 | 11 | using Amazon.DynamoDBv2.DocumentModel;
|
12 | 12 | using Amazon.DynamoDBv2.DataModel;
|
13 | 13 | using Amazon.DynamoDBv2.Model;
|
| 14 | +using Amazon.DynamoDBv2; |
14 | 15 | using ThirdParty.Json.LitJson;
|
15 | 16 |
|
16 | 17 | using Moq;
|
@@ -243,6 +244,72 @@ public void TestExplicitNullPropertyOnDocument()
|
243 | 244 | Assert.IsNull(doc["Name"].AsPrimitive().Value);
|
244 | 245 | }
|
245 | 246 |
|
| 247 | + [TestMethod] |
| 248 | + [TestCategory("DynamoDBv2")] |
| 249 | + public void TestFromJsonCanHandleAllDateTypes() |
| 250 | + { |
| 251 | + var json = @" |
| 252 | + { |
| 253 | + ""StringValue"": ""test string"", |
| 254 | + ""BoolValue"": true, |
| 255 | + ""IntValue"": 200, |
| 256 | + ""DateValue"": ""2022-12-29T12:46:14.097Z"", |
| 257 | + ""NullableBoolValue"": null, |
| 258 | + ""NullableIntValue"": null, |
| 259 | + ""NullableDateValue"": null, |
| 260 | + ""SubData"": null, |
| 261 | + ""SubData2"": { |
| 262 | + ""StringValue"": null, |
| 263 | + ""NullableBoolValue"": false, |
| 264 | + ""NullableIntValue"": 500, |
| 265 | + ""NullableDateValue"": ""2022-12-28T12:46:14.097Z"" |
| 266 | + } |
| 267 | + }"; |
| 268 | + |
| 269 | + using (var dbClient = new AmazonDynamoDBClient()) |
| 270 | + using (var context = new DynamoDBContext(dbClient)) |
| 271 | + { |
| 272 | + var document = Document.FromJson(json); |
| 273 | + var container = context.FromDocument<DataContainer>(document); |
| 274 | + |
| 275 | + Assert.IsNotNull(container); |
| 276 | + Assert.AreEqual(container.StringValue, "test string"); |
| 277 | + Assert.AreEqual(container.BoolValue, true); |
| 278 | + Assert.AreEqual(container.IntValue, 200); |
| 279 | + Assert.AreEqual(container.DateValue, DateTime.Parse("2022-12-29T12:46:14.097Z")); |
| 280 | + Assert.IsNull(container.NullableBoolValue); |
| 281 | + Assert.IsNull(container.NullableIntValue); |
| 282 | + Assert.IsNull(container.NullableDateValue); |
| 283 | + Assert.IsNull(container.SubData); |
| 284 | + Assert.IsNotNull(container.SubData2); |
| 285 | + Assert.IsNull(container.SubData2.StringValue); |
| 286 | + Assert.IsNotNull(container.SubData2.NullableIntValue); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + public class DataContainer |
| 291 | + { |
| 292 | + public string StringValue { get; set; } |
| 293 | + public bool BoolValue { get; set; } |
| 294 | + public int IntValue { get; set; } |
| 295 | + public DateTime DateValue { get; set; } |
| 296 | + |
| 297 | + public bool? NullableBoolValue { get; set; } |
| 298 | + public int? NullableIntValue { get; set; } |
| 299 | + public DateTime? NullableDateValue { get; set; } |
| 300 | + |
| 301 | + public SubContainer SubData { get; set; } |
| 302 | + public SubContainer SubData2 { get; set; } |
| 303 | + |
| 304 | + public class SubContainer |
| 305 | + { |
| 306 | + public string StringValue { get; set; } |
| 307 | + public bool? NullableBoolValue { get; set; } |
| 308 | + public int? NullableIntValue { get; set; } |
| 309 | + public DateTime? NullableDateValue { get; set; } |
| 310 | + } |
| 311 | + } |
| 312 | + |
246 | 313 | #if ASYNC_AWAIT
|
247 | 314 | [TestMethod]
|
248 | 315 | [TestCategory("DynamoDBv2")]
|
|
0 commit comments