22{
33 using System ;
44 using System . Collections . Generic ;
5+ using System . Linq ;
56 using FluentAssertions ;
67 using LEGO . AsyncAPI . Models ;
78 using LEGO . AsyncAPI . Models . Any ;
1314
1415 internal class AsyncApiMessage_Should
1516 {
16- [ Test ]
17+ [ Test ]
18+ public void AsyncApiMessage_WithNoSchemaFormat_DeserializesToDefault ( )
19+ {
20+ // Arrange
21+ var expected =
22+ @"payload:
23+ properties:
24+ propertyA:
25+ type:
26+ - string
27+ - 'null'" ;
28+
29+ // Act
30+ var message = new AsyncApiStringReader ( ) . ReadFragment < AsyncApiMessage > ( expected , AsyncApiVersion . AsyncApi2_0 , out var diagnostic ) ;
31+
32+ // Assert
33+ diagnostic . Errors . Should ( ) . BeEmpty ( ) ;
34+ message . SchemaFormat . Should ( ) . BeNull ( ) ;
35+ }
36+
37+ [ Test ]
38+ public void AsyncApiMessage_WithUnsupportedSchemaFormat_DeserializesWithError ( )
39+ {
40+ // Arrange
41+ var expected =
42+ @"payload:
43+ properties:
44+ propertyA:
45+ type:
46+ - string
47+ - 'null'
48+ schemaFormat: application/vnd.apache.avro;version=1.9.0" ;
49+
50+ // Act
51+ new AsyncApiStringReader ( ) . ReadFragment < AsyncApiMessage > ( expected , AsyncApiVersion . AsyncApi2_0 , out var diagnostic ) ;
52+
53+ // Assert
54+ diagnostic . Errors . Should ( ) . HaveCount ( 1 ) ;
55+ diagnostic . Errors . First ( ) . Message . Should ( ) . StartWith ( "'application/vnd.apache.avro;version=1.9.0' is not a supported format" ) ;
56+ }
57+
58+ [ Test ]
59+ public void AsyncApiMessage_WithNoSchemaFormat_DoesNotSerializeSchemaFormat ( )
60+ {
61+ // Arrange
62+ var expected =
63+ @"payload:
64+ properties:
65+ propertyA:
66+ type:
67+ - string
68+ - 'null'" ;
69+
70+ var message = new AsyncApiMessage ( ) ;
71+ message . Payload = new AsyncApiSchema ( )
72+ {
73+ Properties = new Dictionary < string , AsyncApiSchema > ( )
74+ {
75+ {
76+ "propertyA" , new AsyncApiSchema ( )
77+ {
78+ Type = new List < SchemaType > { SchemaType . String , SchemaType . Null } ,
79+ }
80+ } ,
81+ } ,
82+ } ;
83+
84+ // Act
85+ var actual = message . SerializeAsYaml ( AsyncApiVersion . AsyncApi2_0 ) ;
86+
87+ actual = actual . MakeLineBreaksEnvironmentNeutral ( ) ;
88+ expected = expected . MakeLineBreaksEnvironmentNeutral ( ) ;
89+
90+ var deserializedMessage = new AsyncApiStringReader ( ) . ReadFragment < AsyncApiMessage > ( expected , AsyncApiVersion . AsyncApi2_0 , out _ ) ;
91+
92+ // Assert
93+ Assert . AreEqual ( actual , expected ) ;
94+ message . Should ( ) . BeEquivalentTo ( deserializedMessage ) ;
95+ }
96+
97+ [ Test ]
98+ public void AsyncApiMessage_WithSchemaFormat_Serializes ( )
99+ {
100+ // Arrange
101+ var expected =
102+ @"payload:
103+ properties:
104+ propertyA:
105+ type:
106+ - string
107+ - 'null'
108+ schemaFormat: application/vnd.aai.asyncapi+json;version=2.5.0" ;
109+
110+ var message = new AsyncApiMessage ( ) ;
111+ message . SchemaFormat = "application/vnd.aai.asyncapi+json;version=2.5.0" ;
112+ message . Payload = new AsyncApiSchema ( )
113+ {
114+ Properties = new Dictionary < string , AsyncApiSchema > ( )
115+ {
116+ {
117+ "propertyA" , new AsyncApiSchema ( )
118+ {
119+ Type = new List < SchemaType > { SchemaType . String , SchemaType . Null } ,
120+ }
121+ } ,
122+ } ,
123+ } ;
124+
125+ // Act
126+ var actual = message . SerializeAsYaml ( AsyncApiVersion . AsyncApi2_0 ) ;
127+
128+ actual = actual . MakeLineBreaksEnvironmentNeutral ( ) ;
129+ expected = expected . MakeLineBreaksEnvironmentNeutral ( ) ;
130+
131+ var deserializedMessage = new AsyncApiStringReader ( ) . ReadFragment < AsyncApiMessage > ( expected , AsyncApiVersion . AsyncApi2_0 , out _ ) ;
132+
133+ // Assert
134+ Assert . AreEqual ( actual , expected ) ;
135+ message . Should ( ) . BeEquivalentTo ( deserializedMessage ) ;
136+ }
137+
138+ [ Test ]
17139 public void AsyncApiMessage_WithFilledObject_Serializes ( )
18140 {
19141 var expected =
@@ -33,7 +155,6 @@ public void AsyncApiMessage_WithFilledObject_Serializes()
33155 description: CorrelationDescription
34156 location: Header
35157 x-extension-a: a
36- schemaFormat: MessageSchemaFormat
37158contentType: MessageContentType
38159name: MessageName
39160title: MessageTitle
@@ -133,7 +254,6 @@ public void AsyncApiMessage_WithFilledObject_Serializes()
133254 { "x-extension-a" , new AsyncApiString ( "a" ) } ,
134255 } ,
135256 } ,
136- SchemaFormat = "MessageSchemaFormat" ,
137257 ContentType = "MessageContentType" ,
138258 Name = "MessageName" ,
139259 Title = "MessageTitle" ,
0 commit comments