File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
src/StripeTests/Infrastructure Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,14 @@ public void Serialize()
4444 JsonConvert . DeserializeObject < Event > ( serialized ) ,
4545 Formatting . Indented ) ;
4646 Assert . Equal ( serialized , reserialized ) ;
47+
48+ json = GetResourceAsString ( "api_fixtures.customer_with_expansions.json" ) ;
49+ var customer = JsonConvert . DeserializeObject < Customer > ( json ) ;
50+ serialized = JsonConvert . SerializeObject ( customer , Formatting . Indented ) ;
51+ reserialized = JsonConvert . SerializeObject (
52+ JsonConvert . DeserializeObject < Customer > ( serialized ) ,
53+ Formatting . Indented ) ;
54+ Assert . Equal ( serialized , reserialized ) ;
4755 }
4856 }
4957}
Original file line number Diff line number Diff line change 1+ #if NET6_0_OR_GREATER
2+ namespace StripeTests
3+ {
4+ using System ;
5+ using System . Text . Json ;
6+ using System . Xml ;
7+ using Stripe ;
8+ using StripeTests . Infrastructure . TestData ;
9+ using Xunit ;
10+
11+ public class StjDeserializationTest : BaseStripeTest
12+ {
13+ [ Fact ]
14+ public void RoundtripDatetime ( )
15+ {
16+ var date = DateTime . UtcNow ;
17+ var roundedDate = date . AddTicks ( - 1 * ( date . Ticks % TimeSpan . TicksPerSecond ) ) ;
18+ var obj = new TestObjectDateTime
19+ {
20+ Date = roundedDate ,
21+ } ;
22+
23+ var reloaded = JsonSerializer . Deserialize < TestObjectDateTime > ( JsonSerializer . Serialize ( obj ) ) ;
24+ Assert . Equal ( reloaded . Date , obj . Date ) ;
25+ }
26+
27+ [ Fact ]
28+ public void HandleNull ( )
29+ {
30+ var obj = new TestObjectDateTime
31+ {
32+ Date = null ,
33+ } ;
34+
35+ var reloaded = JsonSerializer . Deserialize < TestObjectDateTime > ( JsonSerializer . Serialize ( obj ) ) ;
36+ Assert . Null ( reloaded . Date ) ;
37+ }
38+
39+ [ Fact ( Skip = "System.Text.JSON Deserialization does not work correctly currently for handling non-nullable null values" ) ]
40+ public void Serialize ( )
41+ {
42+ var json = GetResourceAsString ( "api_fixtures.customer_with_expansions.json" ) ;
43+ var customer = JsonSerializer . Deserialize < Customer > ( json ) ;
44+ var serialized = JsonSerializer . Serialize ( customer ) ;
45+ var reserialized = JsonSerializer . Serialize (
46+ JsonSerializer . Deserialize < Customer > ( serialized ) ) ;
47+ Assert . Equal ( serialized , reserialized ) ;
48+ }
49+ }
50+ }
51+ #endif
You can’t perform that action at this time.
0 commit comments