Skip to content

Commit 338c7d3

Browse files
muhammad-othmanashovlin
authored andcommitted
move TestFromJsonCanHandleAllDataTypes to JSONTests
1 parent 3a405a7 commit 338c7d3

File tree

2 files changed

+66
-67
lines changed

2 files changed

+66
-67
lines changed

sdk/test/Services/DynamoDBv2/IntegrationTests/JSONTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public void TestJSON()
7777
TestPutGet();
7878

7979
TestArrayMethods();
80+
81+
TestFromJsonCanHandleAllDataTypes();
8082
}
8183

8284
private void TestPutGet()
@@ -325,5 +327,69 @@ private static void CompareJson(string jsonA, string jsonB)
325327

326328
Assert.AreEqual(aRt, bRt);
327329
}
330+
331+
private static void TestFromJsonCanHandleAllDataTypes()
332+
{
333+
var json = @"
334+
{
335+
""StringValue"": ""test string"",
336+
""BoolValue"": true,
337+
""IntValue"": 200,
338+
""DateValue"": ""2022-12-29T12:46:14.097Z"",
339+
""NullableBoolValue"": null,
340+
""NullableIntValue"": null,
341+
""NullableDateValue"": null,
342+
""SubData"": null,
343+
""SubData2"": {
344+
""StringValue"": null,
345+
""NullableBoolValue"": false,
346+
""NullableIntValue"": 500,
347+
""NullableDateValue"": ""2022-12-28T12:46:14.097Z""
348+
}
349+
}";
350+
351+
using (var dbClient = new AmazonDynamoDBClient())
352+
using (var context = new DynamoDBContext(dbClient))
353+
{
354+
var document = Document.FromJson(json);
355+
var container = context.FromDocument<DataContainer>(document);
356+
357+
Assert.IsNotNull(container);
358+
Assert.AreEqual(container.StringValue, "test string");
359+
Assert.AreEqual(container.BoolValue, true);
360+
Assert.AreEqual(container.IntValue, 200);
361+
Assert.AreEqual(container.DateValue, DateTime.Parse("2022-12-29T12:46:14.097Z"));
362+
Assert.IsNull(container.NullableBoolValue);
363+
Assert.IsNull(container.NullableIntValue);
364+
Assert.IsNull(container.NullableDateValue);
365+
Assert.IsNull(container.SubData);
366+
Assert.IsNotNull(container.SubData2);
367+
Assert.IsNull(container.SubData2.StringValue);
368+
Assert.IsNotNull(container.SubData2.NullableIntValue);
369+
}
370+
}
371+
372+
private class DataContainer
373+
{
374+
public string StringValue { get; set; }
375+
public bool BoolValue { get; set; }
376+
public int IntValue { get; set; }
377+
public DateTime DateValue { get; set; }
378+
379+
public bool? NullableBoolValue { get; set; }
380+
public int? NullableIntValue { get; set; }
381+
public DateTime? NullableDateValue { get; set; }
382+
383+
public SubContainer SubData { get; set; }
384+
public SubContainer SubData2 { get; set; }
385+
386+
public class SubContainer
387+
{
388+
public string StringValue { get; set; }
389+
public bool? NullableBoolValue { get; set; }
390+
public int? NullableIntValue { get; set; }
391+
public DateTime? NullableDateValue { get; set; }
392+
}
393+
}
328394
}
329395
}

sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Amazon.DynamoDBv2.DocumentModel;
1212
using Amazon.DynamoDBv2.DataModel;
1313
using Amazon.DynamoDBv2.Model;
14-
using Amazon.DynamoDBv2;
1514
using ThirdParty.Json.LitJson;
1615

1716
using Moq;
@@ -244,72 +243,6 @@ public void TestExplicitNullPropertyOnDocument()
244243
Assert.IsNull(doc["Name"].AsPrimitive().Value);
245244
}
246245

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-
313246
#if ASYNC_AWAIT
314247
[TestMethod]
315248
[TestCategory("DynamoDBv2")]

0 commit comments

Comments
 (0)