@@ -25,6 +25,8 @@ let test_dynobj =
25
25
)
26
26
obj
27
27
28
+ let test_dyn_obj_json = """ {"dynamic_string":"yes","dynamic_number":69,"dynamic_boolean":true,"dynamic_array":["First","Second"],"dynamic_object":{"inner":"yup"}}"""
29
+
28
30
type DerivedClass1 ( staticProp : string ) =
29
31
inherit DynamicObj()
30
32
member this.StaticProp = staticProp
@@ -47,6 +49,8 @@ let test_derived_1 =
47
49
let obj = DerivedClass1( " lol" )
48
50
obj.SetProperty( " dynamicProp" , 42 )
49
51
obj
52
+
53
+ let test_derived_1_json = """ {"StaticProp":"lol","dynamicProp":42}"""
50
54
51
55
let test_derived_2 =
52
56
let obj = DerivedClass2(
@@ -68,19 +72,37 @@ let test_derived_2 =
68
72
)
69
73
obj
70
74
75
+ let test_derived_2_json = """ {"StaticString":"lol","StaticNumber":42.0,"StaticBoolean":true,"StaticArray":["First","Second"],"StaticObject":{"StaticProp":"lol","dynamicProp":42},"dynamic_string":"yes","dynamic_number":69,"dynamic_boolean":true,"dynamic_array":["First","Second"],"dynamic_object":{"inner":"yup"}}"""
76
+
71
77
#if ! FABLE_ COMPILER
72
78
let tests_newtonsoft = testList " Newtonsoft (.NET)" [
73
- testCase " Serialize DynamicObj" <| fun _ ->
74
- let actual = JsonConvert.SerializeObject( test_ dynobj)
75
- Expect.equal actual """ {"dynamic_string":"yes","dynamic_number":69,"dynamic_boolean":true,"dynamic_array":["First","Second"],"dynamic_object":{"inner":"yup"}}""" " "
79
+ testList " Serialization" [
80
+ testCase " Serialize DynamicObj" <| fun _ ->
81
+ let actual = JsonConvert.SerializeObject( test_ dynobj)
82
+ Expect.equal actual test_ dyn_ obj_ json " "
83
+
84
+ testCase " Serialize simple derived class from DynamicObj" <| fun _ ->
85
+ let actual = JsonConvert.SerializeObject( test_ derived_ 1)
86
+ Expect.equal actual test_ derived_ 1_ json " "
87
+
88
+ testCase " Serialize complex derived class from DynamicObj" <| fun _ ->
89
+ let actual = JsonConvert.SerializeObject( test_ derived_ 2)
90
+ Expect.equal actual test_ derived_ 2_ json " "
91
+ ]
92
+ ftestList " Deserialization" [
93
+ testCase " Deserialize DynamicObj" <| fun _ ->
94
+ let actual = JsonConvert.DeserializeObject< DynamicObj>( test_ dyn_ obj_ json)
95
+
96
+ printfn " expected props:"
97
+ for prop in test_ dynobj.GetProperties( true ) do
98
+ printfn $" {prop.Key}, {prop.Value}, {prop.Value.GetType()}"
76
99
77
- testCase " Serialize simplederived class from DynamicObj " <| fun _ ->
78
- let actual = JsonConvert.SerializeObject ( test _ derived _ 1 )
79
- Expect.equal actual """ {"StaticProp":"lol","dynamicProp":42} """ " "
100
+ printfn " actual props: "
101
+ for prop in actual.GetProperties ( true ) do
102
+ printfn $ " {prop.Key}, {prop.Value}, {prop.Value.GetType()} "
80
103
81
- testCase " Serialize complex derived class from DynamicObj" <| fun _ ->
82
- let actual = JsonConvert.SerializeObject( test_ derived_ 2)
83
- Expect.equal actual """ {"StaticString":"lol","StaticNumber":42.0,"StaticBoolean":true,"StaticArray":["First","Second"],"StaticObject":{"StaticProp":"lol","dynamicProp":42},"dynamic_string":"yes","dynamic_number":69,"dynamic_boolean":true,"dynamic_array":["First","Second"],"dynamic_object":{"inner":"yup"}}""" " "
104
+ Expect.equal ( actual.GetHashCode()) ( test_ dynobj.GetHashCode()) " "
105
+ ]
84
106
]
85
107
#endif
86
108
0 commit comments