@@ -5,6 +5,7 @@ namespace StripeTests
5
5
using System . IO ;
6
6
using System . Text ;
7
7
using System . Threading . Tasks ;
8
+ using Stripe ;
8
9
using Stripe . Infrastructure . FormEncoding ;
9
10
using Xunit ;
10
11
@@ -71,6 +72,132 @@ public async Task Ctor_OneStreamEntry_Success()
71
72
result ) ;
72
73
}
73
74
75
+ [ Fact ]
76
+ public async Task Ctor_OneMultipartFileContentEntry_Success ( )
77
+ {
78
+ var source = new Dictionary < string , object >
79
+ {
80
+ { "key" , new MultipartFileContent { Data = new MemoryStream ( Encoding . UTF8 . GetBytes ( "Hello World!" ) ) } } ,
81
+ } ;
82
+ var content = new MultipartFormDataContent ( source , "test-boundary" ) ;
83
+
84
+ var stream = await content . ReadAsStreamAsync ( ) ;
85
+ Assert . Equal ( 174 , stream . Length ) ;
86
+ var result = new StreamReader ( stream ) . ReadToEnd ( ) ;
87
+ Assert . Equal (
88
+ "--test-boundary\r \n "
89
+ + "Content-Disposition: form-data; name=\" key\" ; filename=blob; filename*=utf-8''blob\r \n "
90
+ + "Content-Type: application/octet-stream\r \n \r \n Hello World!\r \n "
91
+ + "--test-boundary--\r \n " ,
92
+ result ) ;
93
+ }
94
+
95
+ [ Fact ]
96
+ public async Task Ctor_OneMultipartFileContentWithNameEntry_Success ( )
97
+ {
98
+ var source = new Dictionary < string , object >
99
+ {
100
+ {
101
+ "key" , new MultipartFileContent
102
+ {
103
+ Data = new MemoryStream ( Encoding . UTF8 . GetBytes ( "Hello World!" ) ) ,
104
+ Name = "file" ,
105
+ }
106
+ } ,
107
+ } ;
108
+ var content = new MultipartFormDataContent ( source , "test-boundary" ) ;
109
+
110
+ var stream = await content . ReadAsStreamAsync ( ) ;
111
+ Assert . Equal ( 174 , stream . Length ) ;
112
+ var result = new StreamReader ( stream ) . ReadToEnd ( ) ;
113
+ Assert . Equal (
114
+ "--test-boundary\r \n "
115
+ + "Content-Disposition: form-data; name=\" key\" ; filename=file; filename*=utf-8''file\r \n "
116
+ + "Content-Type: application/octet-stream\r \n \r \n Hello World!\r \n "
117
+ + "--test-boundary--\r \n " ,
118
+ result ) ;
119
+ }
120
+
121
+ [ Fact ]
122
+ public async Task Ctor_OneMultipartFileContentWithNameAndExtEntry_Success ( )
123
+ {
124
+ var source = new Dictionary < string , object >
125
+ {
126
+ {
127
+ "key" , new MultipartFileContent
128
+ {
129
+ Data = new MemoryStream ( Encoding . UTF8 . GetBytes ( "Hello World!" ) ) ,
130
+ Name = "file.csv" ,
131
+ }
132
+ } ,
133
+ } ;
134
+ var content = new MultipartFormDataContent ( source , "test-boundary" ) ;
135
+
136
+ var stream = await content . ReadAsStreamAsync ( ) ;
137
+ Assert . Equal ( 166 , stream . Length ) ;
138
+ var result = new StreamReader ( stream ) . ReadToEnd ( ) ;
139
+ Assert . Equal (
140
+ "--test-boundary\r \n "
141
+ + "Content-Disposition: form-data; name=\" key\" ; filename=file.csv; filename*=utf-8''file.csv\r \n "
142
+ + "Content-Type: text/csv\r \n \r \n Hello World!\r \n "
143
+ + "--test-boundary--\r \n " ,
144
+ result ) ;
145
+ }
146
+
147
+ [ Fact ]
148
+ public async Task Ctor_OneMultipartFileContentWithNameAndTypeEntry_Success ( )
149
+ {
150
+ var source = new Dictionary < string , object >
151
+ {
152
+ {
153
+ "key" , new MultipartFileContent
154
+ {
155
+ Data = new MemoryStream ( Encoding . UTF8 . GetBytes ( "Hello World!" ) ) ,
156
+ Name = "file" ,
157
+ Type = "application/json" ,
158
+ }
159
+ } ,
160
+ } ;
161
+ var content = new MultipartFormDataContent ( source , "test-boundary" ) ;
162
+
163
+ var stream = await content . ReadAsStreamAsync ( ) ;
164
+ Assert . Equal ( 166 , stream . Length ) ;
165
+ var result = new StreamReader ( stream ) . ReadToEnd ( ) ;
166
+ Assert . Equal (
167
+ "--test-boundary\r \n "
168
+ + "Content-Disposition: form-data; name=\" key\" ; filename=file; filename*=utf-8''file\r \n "
169
+ + "Content-Type: application/json\r \n \r \n Hello World!\r \n "
170
+ + "--test-boundary--\r \n " ,
171
+ result ) ;
172
+ }
173
+
174
+ [ Fact ]
175
+ public async Task Ctor_OneMultipartFileContentWithNameAndExtAndTypeEntry_Success ( )
176
+ {
177
+ var source = new Dictionary < string , object >
178
+ {
179
+ {
180
+ "key" , new MultipartFileContent
181
+ {
182
+ Data = new MemoryStream ( Encoding . UTF8 . GetBytes ( "Hello World!" ) ) ,
183
+ Name = "file.json" ,
184
+ Type = "application/octet-stream" ,
185
+ }
186
+ } ,
187
+ } ;
188
+ var content = new MultipartFormDataContent ( source , "test-boundary" ) ;
189
+
190
+ var stream = await content . ReadAsStreamAsync ( ) ;
191
+ Assert . Equal ( 184 , stream . Length ) ;
192
+ var result = new StreamReader ( stream ) . ReadToEnd ( ) ;
193
+ Assert . Equal (
194
+ "--test-boundary\r \n "
195
+ + "Content-Disposition: form-data; name=\" key\" ; filename=file.json; filename*=utf-8''file.json\r \n "
196
+ + "Content-Type: application/octet-stream\r \n \r \n Hello World!\r \n "
197
+ + "--test-boundary--\r \n " ,
198
+ result ) ;
199
+ }
200
+
74
201
[ Fact ]
75
202
public async Task Ctor_TwoEntries_Success ( )
76
203
{
0 commit comments