@@ -25,6 +25,7 @@ namespace SysML2.NET.Serializer.Json.Tests
2525 using System . IO ;
2626 using System . Text ;
2727 using System . Text . Json ;
28+ using System . Threading ;
2829
2930 using NUnit . Framework ;
3031
@@ -75,7 +76,102 @@ public void Verify_that_Elements_can_be_serialized()
7576
7677 Assert . That ( ( ) => this . serializer . Serialize ( elements , SerializationModeKind . JSON , stream , jsonWriterOptions ) , Throws . Nothing ) ; ;
7778
78- string json = Encoding . UTF8 . GetString ( stream . ToArray ( ) ) ;
79+ var json = Encoding . UTF8 . GetString ( stream . ToArray ( ) ) ;
80+ Console . WriteLine ( json ) ;
81+ }
82+
83+ [ Test ]
84+ public void Verify_that_Element_can_be_serialized ( )
85+ {
86+ var partDefinition = new PartDefinition
87+ {
88+ Id = Guid . NewGuid ( ) ,
89+ IsIndividual = true ,
90+ IsVariation = false ,
91+ IsAbstract = false ,
92+ IsSufficient = false ,
93+ AliasIds = new List < string > { "PartDefinition:Alias_1" , "PartDefinition:Alias_2" } ,
94+ Name = "PartDefinition:Name" ,
95+ OwnedRelationship = new List < Guid > { Guid . NewGuid ( ) } ,
96+ OwningRelationship = Guid . NewGuid ( ) ,
97+ ShortName = "PartDefinition:ShortName"
98+ } ;
99+
100+
101+ var stream = new MemoryStream ( ) ;
102+ var jsonWriterOptions = new JsonWriterOptions { Indented = true } ;
103+
104+ Assert . That ( ( ) => this . serializer . Serialize ( partDefinition , SerializationModeKind . JSON , stream , jsonWriterOptions ) , Throws . Nothing ) ; ;
105+
106+ var json = Encoding . UTF8 . GetString ( stream . ToArray ( ) ) ;
107+ Console . WriteLine ( json ) ;
108+ }
109+
110+ [ Test ]
111+ public void Verify_that_Elements_can_be_serialized_async ( )
112+ {
113+ var element = new Element
114+ {
115+ Id = Guid . NewGuid ( ) ,
116+ AliasIds = new List < string > { "Element:Alias_1" , "Element:Alias_2" } ,
117+ ElementId = "Element:ElementId" ,
118+ Name = "Element:Name" ,
119+ OwnedRelationship = new List < Guid > { Guid . NewGuid ( ) } ,
120+ OwningRelationship = Guid . NewGuid ( ) ,
121+ ShortName = "Element:ShortName"
122+ } ;
123+
124+ var partDefinition = new PartDefinition
125+ {
126+ Id = Guid . NewGuid ( ) ,
127+ IsIndividual = true ,
128+ IsVariation = false ,
129+ IsAbstract = false ,
130+ IsSufficient = false ,
131+ AliasIds = new List < string > { "PartDefinition:Alias_1" , "PartDefinition:Alias_2" } ,
132+ Name = "PartDefinition:Name" ,
133+ OwnedRelationship = new List < Guid > { Guid . NewGuid ( ) } ,
134+ OwningRelationship = Guid . NewGuid ( ) ,
135+ ShortName = "PartDefinition:ShortName"
136+ } ;
137+
138+ var elements = new List < IElement > { element , partDefinition } ;
139+ var stream = new MemoryStream ( ) ;
140+ var jsonWriterOptions = new JsonWriterOptions { Indented = true } ;
141+
142+ var cts = new CancellationTokenSource ( ) ;
143+
144+ Assert . That ( async ( ) => await this . serializer . SerializeAsync ( elements , SerializationModeKind . JSON , stream , jsonWriterOptions , cts . Token ) , Throws . Nothing ) ; ;
145+
146+ var json = Encoding . UTF8 . GetString ( stream . ToArray ( ) ) ;
147+ Console . WriteLine ( json ) ;
148+ }
149+
150+ [ Test ]
151+ public void Verify_that_Element_can_be_serialized_async ( )
152+ {
153+ var partDefinition = new PartDefinition
154+ {
155+ Id = Guid . NewGuid ( ) ,
156+ IsIndividual = true ,
157+ IsVariation = false ,
158+ IsAbstract = false ,
159+ IsSufficient = false ,
160+ AliasIds = new List < string > { "PartDefinition:Alias_1" , "PartDefinition:Alias_2" } ,
161+ Name = "PartDefinition:Name" ,
162+ OwnedRelationship = new List < Guid > { Guid . NewGuid ( ) } ,
163+ OwningRelationship = Guid . NewGuid ( ) ,
164+ ShortName = "PartDefinition:ShortName"
165+ } ;
166+
167+ var stream = new MemoryStream ( ) ;
168+ var jsonWriterOptions = new JsonWriterOptions { Indented = true } ;
169+
170+ var cts = new CancellationTokenSource ( ) ;
171+
172+ Assert . That ( async ( ) => await this . serializer . SerializeAsync ( partDefinition , SerializationModeKind . JSON , stream , jsonWriterOptions , cts . Token ) , Throws . Nothing ) ; ;
173+
174+ var json = Encoding . UTF8 . GetString ( stream . ToArray ( ) ) ;
79175 Console . WriteLine ( json ) ;
80176 }
81177 }
0 commit comments