5
5
using Xunit ;
6
6
using Moq ;
7
7
using System . Text ;
8
- using Microsoft . Extensions . Primitives ;
9
- using System . Linq ;
10
8
11
9
public class HttpContextExtensionsTests
12
10
{
@@ -54,7 +52,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
54
52
request . QueryString = new QueryString ( "?status=pending" ) ;
55
53
request . Headers [ "User-Agent" ] = "TestAgent" ;
56
54
request . Headers [ "Accept" ] = "application/json" ;
57
- request . Headers [ "Cookie" ] = "session=abc123; theme=dark; complex=this+has+special ;" ;
55
+ request . Headers [ "Cookie" ] = "session=abc123; theme=dark; complex=this+has+spaces ;" ;
58
56
59
57
var result = context . ToApiGatewayHttpV2Request ( ) ;
60
58
@@ -66,7 +64,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR
66
64
Assert . Equal ( 3 , result . Cookies . Length ) ;
67
65
Assert . Contains ( "session=abc123" , result . Cookies ) ;
68
66
Assert . Contains ( "theme=dark" , result . Cookies ) ;
69
- Assert . Contains ( "complex=this%2bhas%2bspecial " , result . Cookies ) ;
67
+ Assert . Contains ( "complex=this%2bhas%2bspaces " , result . Cookies ) ;
70
68
Assert . Equal ( "123" , result . PathParameters [ "userId" ] ) ;
71
69
Assert . Equal ( "GET" , result . RequestContext . Http . Method ) ;
72
70
Assert . Equal ( "/api/users/123/orders" , result . RequestContext . Http . Path ) ;
@@ -161,37 +159,39 @@ public void ToApiGatewayRequest_ShouldReturnValidApiGatewayProxyRequest()
161
159
request . Path = "/api/users/123/orders" ;
162
160
request . QueryString = new QueryString ( "?status=pending&tag=important&tag=urgent" ) ;
163
161
request . Headers [ "User-Agent" ] = "TestAgent" ;
164
- request . Headers [ "Accept" ] = new StringValues ( new [ ] { "text/html" , "application/json" } ) ;
165
- request . Headers [ "Cookie" ] = "session=abc123; theme=dark; complex=this+has+special; " ;
162
+ request . Headers [ "Accept" ] = new Microsoft . Extensions . Primitives . StringValues ( new [ ] { "text/html" , "application/json" } ) ;
163
+ request . Headers [ "Cookie" ] = "session=abc123; theme=dark" ;
166
164
request . Headers [ "X-Custom-Header" ] = "value1" ;
167
165
168
166
_mockHttpRequestUtility . Setup ( x => x . ExtractHeaders ( It . IsAny < IHeaderDictionary > ( ) ) )
169
167
. Returns ( (
170
168
new Dictionary < string , string >
171
169
{
172
- { "User-Agent" , "TestAgent" } ,
173
- { "Accept" , "application/json" } ,
174
- { "X-Custom-Header" , "value1" }
170
+ { "User-Agent" , "TestAgent" } ,
171
+ { "Accept" , "application/json" } ,
172
+ { "Cookie" , "session=abc123; theme=dark" } ,
173
+ { "X-Custom-Header" , "value1" }
175
174
} ,
176
175
new Dictionary < string , IList < string > >
177
176
{
178
- { "User-Agent" , new List < string > { "TestAgent" } } ,
179
- { "Accept" , new List < string > { "text/html" , "application/json" } } ,
180
- { "X-Custom-Header" , new List < string > { "value1" } }
177
+ { "User-Agent" , new List < string > { "TestAgent" } } ,
178
+ { "Accept" , new List < string > { "text/html" , "application/json" } } ,
179
+ { "Cookie" , new List < string > { "session=abc123; theme=dark" } } ,
180
+ { "X-Custom-Header" , new List < string > { "value1" } }
181
181
}
182
182
) ) ;
183
183
184
184
_mockHttpRequestUtility . Setup ( x => x . ExtractQueryStringParameters ( It . IsAny < IQueryCollection > ( ) ) )
185
185
. Returns ( (
186
186
new Dictionary < string , string >
187
187
{
188
- { "status" , "pending" } ,
189
- { "tag" , "urgent" }
188
+ { "status" , "pending" } ,
189
+ { "tag" , "urgent" }
190
190
} ,
191
191
new Dictionary < string , IList < string > >
192
192
{
193
- { "status" , new List < string > { "pending" } } ,
194
- { "tag" , new List < string > { "important" , "urgent" } }
193
+ { "status" , new List < string > { "pending" } } ,
194
+ { "tag" , new List < string > { "important" , "urgent" } }
195
195
}
196
196
) ) ;
197
197
@@ -204,11 +204,13 @@ public void ToApiGatewayRequest_ShouldReturnValidApiGatewayProxyRequest()
204
204
205
205
Assert . Equal ( "TestAgent" , result . Headers [ "User-Agent" ] ) ;
206
206
Assert . Equal ( "application/json" , result . Headers [ "Accept" ] ) ;
207
+ Assert . Equal ( "session=abc123; theme=dark" , result . Headers [ "Cookie" ] ) ;
207
208
Assert . Equal ( "value1" , result . Headers [ "X-Custom-Header" ] ) ;
208
209
209
- var expectedCookieString = $ "session={ HttpUtility . UrlEncode ( "abc123" ) } ; theme={ HttpUtility . UrlEncode ( "dark" ) } ; complex={ HttpUtility . UrlEncode ( "this+has+special" ) } ";
210
- Assert . Equal ( expectedCookieString , result . Headers [ "Cookie" ] ) ;
211
- Assert . Equal ( [ expectedCookieString ] , result . MultiValueHeaders [ "Cookie" ] ) ;
210
+ Assert . Equal ( new List < string > { "TestAgent" } , result . MultiValueHeaders [ "User-Agent" ] ) ;
211
+ Assert . Equal ( new List < string > { "text/html" , "application/json" } , result . MultiValueHeaders [ "Accept" ] ) ;
212
+ Assert . Equal ( new List < string > { "session=abc123; theme=dark" } , result . MultiValueHeaders [ "Cookie" ] ) ;
213
+ Assert . Equal ( new List < string > { "value1" } , result . MultiValueHeaders [ "X-Custom-Header" ] ) ;
212
214
213
215
Assert . Equal ( "pending" , result . QueryStringParameters [ "status" ] ) ;
214
216
Assert . Equal ( "urgent" , result . QueryStringParameters [ "tag" ] ) ;
0 commit comments