1- using Microsoft . Kiota . Abstractions . Serialization ;
1+ using System . IO ;
2+ using Microsoft . Kiota . Abstractions . Serialization ;
23using Moq ;
34using Xunit ;
45
@@ -10,10 +11,22 @@ public class MultipartBodyTests
1011 public void KeepsFilename ( )
1112 {
1213 var writerMock = new Mock < ISerializationWriter > ( ) ;
14+ var jsonWriterMock = new Mock < ISerializationWriter > ( ) ;
1315 var requestAdapterMock = new Mock < IRequestAdapter > ( ) ;
1416 var serializationFactoryMock = new Mock < ISerializationWriterFactory > ( ) ;
1517
1618 var body = new MultipartBody ( ) ;
19+ jsonWriterMock . Setup ( w => w . WriteStringValue ( "" , "fileContent" ) ) ;
20+ using var ms = new MemoryStream ( ) ;
21+ using var sr = new StreamWriter ( ms ) ;
22+
23+ sr . Write ( "fileContent" ) ;
24+ sr . Flush ( ) ;
25+ jsonWriterMock . Setup ( w => w . GetSerializedContent ( ) ) . Returns ( ms ) ;
26+
27+ serializationFactoryMock
28+ . Setup ( r => r . GetSerializationWriter ( "application/json" ) )
29+ . Returns ( jsonWriterMock . Object ) ;
1730
1831 requestAdapterMock
1932 . Setup ( r => r . SerializationWriterFactory )
@@ -24,7 +37,7 @@ public void KeepsFilename()
2437 writerMock . Setup ( w => w . WriteStringValue ( "" , "--" + body . Boundary ) ) ;
2538 writerMock . Setup ( w => w . WriteStringValue ( "Content-Type" , "application/json" ) ) ;
2639 writerMock . Setup ( w => w . WriteStringValue ( "Content-Disposition" , "form-data; name=\" file\" ; filename=\" file.json\" " ) ) ;
27- writerMock . Setup ( w => w . WriteStringValue ( "" , "fileContent" ) ) ;
40+ writerMock . Setup ( w => w . WriteByteArrayValue ( "" , ms . ToArray ( ) ) ) ;
2841 writerMock . Setup ( w => w . WriteStringValue ( "" , "" ) ) ;
2942 writerMock . Setup ( w => w . WriteStringValue ( "" , "--" + body . Boundary + "--" ) ) ;
3043
@@ -40,10 +53,22 @@ public void KeepsFilename()
4053 public void WorksWithoutFilename ( )
4154 {
4255 var writerMock = new Mock < ISerializationWriter > ( ) ;
56+ var jsonWriterMock = new Mock < ISerializationWriter > ( ) ;
4357 var requestAdapterMock = new Mock < IRequestAdapter > ( ) ;
4458 var serializationFactoryMock = new Mock < ISerializationWriterFactory > ( ) ;
4559
4660 var body = new MultipartBody ( ) ;
61+ jsonWriterMock . Setup ( w => w . WriteStringValue ( "" , "fileContent" ) ) ;
62+ using var ms = new MemoryStream ( ) ;
63+ using var sr = new StreamWriter ( ms ) ;
64+
65+ sr . Write ( "fileContent" ) ;
66+ sr . Flush ( ) ;
67+ jsonWriterMock . Setup ( w => w . GetSerializedContent ( ) ) . Returns ( ms ) ;
68+
69+ serializationFactoryMock
70+ . Setup ( r => r . GetSerializationWriter ( "application/json" ) )
71+ . Returns ( jsonWriterMock . Object ) ;
4772
4873 requestAdapterMock
4974 . Setup ( r => r . SerializationWriterFactory )
@@ -54,7 +79,7 @@ public void WorksWithoutFilename()
5479 writerMock . Setup ( w => w . WriteStringValue ( "" , "--" + body . Boundary ) ) ;
5580 writerMock . Setup ( w => w . WriteStringValue ( "Content-Type" , "application/json" ) ) ;
5681 writerMock . Setup ( w => w . WriteStringValue ( "Content-Disposition" , "form-data; name=\" file\" " ) ) ;
57- writerMock . Setup ( w => w . WriteStringValue ( "" , "fileContent" ) ) ;
82+ writerMock . Setup ( w => w . WriteByteArrayValue ( "" , ms . ToArray ( ) ) ) ;
5883 writerMock . Setup ( w => w . WriteStringValue ( "" , "" ) ) ;
5984 writerMock . Setup ( w => w . WriteStringValue ( "" , "--" + body . Boundary + "--" ) ) ;
6085
0 commit comments