@@ -17,8 +17,8 @@ Content _getTestContent(String input) {
1717}
1818
1919void main () {
20- group ('Content Serdes Tests ' , () {
21- test ('Content Validation ' , () async {
20+ group ('ContentSerdes should ' , () {
21+ test ('validate Content ' , () async {
2222 final contentSerdes = ContentSerdes ();
2323
2424 final testContent1 = _getTestContent ('42' );
@@ -57,7 +57,7 @@ void main() {
5757 null ,
5858 );
5959 });
60- test ('Codec Registration ' , () async {
60+ test ('support registration of new Codecs ' , () async {
6161 final contentSerdes = ContentSerdes ();
6262
6363 expect (
@@ -130,5 +130,40 @@ void main() {
130130 throwsArgumentError,
131131 );
132132 });
133+
134+ test ('return a Content object with an empty Stream for undefined values' ,
135+ () async {
136+ final contentSerdes = ContentSerdes ();
137+ final content = contentSerdes.valueToContent (null , null );
138+
139+ expect (await content.body.isEmpty, isTrue);
140+ });
141+
142+ test ('reject undefined DataSchemaValues if a DataSchema is given' ,
143+ () async {
144+ final contentSerdes = ContentSerdes ();
145+
146+ expect (
147+ () => contentSerdes.valueToContent (
148+ null ,
149+ // FIXME(JKRhb): Should not be necessary to use fromJson here
150+ DataSchema .fromJson ({'type' : 'object' }, PrefixMapping ()),
151+ ),
152+ throwsA (isA <ContentSerdesException >()),
153+ );
154+ });
155+
156+ test ('convert DataSchemaValues to Content' , () async {
157+ final contentSerdes = ContentSerdes ();
158+ const inputValue = 'foo' ;
159+
160+ final content = contentSerdes.valueToContent (
161+ DataSchemaValue .fromString (inputValue),
162+ null ,
163+ );
164+
165+ expect (await content.toByteList (), [34 , 102 , 111 , 111 , 34 ]);
166+ expect (content.type, 'application/json' );
167+ });
133168 });
134169}
0 commit comments