@@ -108,6 +108,45 @@ public void ToApiGatewayHttpV2Request_WithBinaryContent_ShouldBase64EncodeBody()
108
108
_mockRouteConfigParser . Verify ( x => x . ExtractPathParameters ( It . IsAny < ApiGatewayRouteConfig > ( ) , "/api/users/123/avatar" ) , Times . Once ) ;
109
109
}
110
110
111
+ [ Fact ]
112
+ public void ToApiGatewayRequest_WithBinaryContent_ShouldBase64EncodeBody ( )
113
+ {
114
+ var context = new DefaultHttpContext ( ) ;
115
+ var request = context . Request ;
116
+ request . Method = "POST" ;
117
+ request . Path = "/api/users/123/avatar" ;
118
+ request . ContentType = "application/octet-stream" ;
119
+ var bodyContent = new byte [ ] { 1 , 2 , 3 , 4 , 5 } ;
120
+ request . Body = new MemoryStream ( bodyContent ) ;
121
+
122
+ _mockHttpRequestUtility . Setup ( x => x . IsBinaryContent ( It . IsAny < string > ( ) ) ) . Returns ( true ) ;
123
+ _mockHttpRequestUtility . Setup ( x => x . ReadRequestBody ( It . IsAny < HttpRequest > ( ) ) ) . Returns ( Encoding . UTF8 . GetString ( bodyContent ) ) ;
124
+
125
+ _mockRouteConfigParser . Setup ( x => x . GetRouteConfig ( "POST" , "/api/users/123/avatar" ) )
126
+ . Returns ( new ApiGatewayRouteConfig
127
+ {
128
+ LambdaResourceName = "UploadAvatarFunction" ,
129
+ Endpoint = "POST /api/users/{userId}/avatar" ,
130
+ HttpMethod = "POST" ,
131
+ Path = "/api/users/{userId}/avatar"
132
+ } ) ;
133
+
134
+ var result = context . ToApiGatewayRequest ( ) ;
135
+
136
+ Assert . NotNull ( result ) ;
137
+ Assert . True ( result . IsBase64Encoded ) ;
138
+ Assert . Equal ( Convert . ToBase64String ( bodyContent ) , result . Body ) ;
139
+ Assert . Equal ( "123" , result . PathParameters [ "userId" ] ) ;
140
+ Assert . Equal ( "/api/users/{userId}/avatar" , result . Resource ) ;
141
+ Assert . Equal ( "POST" , result . HttpMethod ) ;
142
+ Assert . Equal ( HttpUtility . UrlEncode ( "/api/users/123/avatar" ) , result . Path ) ;
143
+
144
+ _mockRouteConfigParser . Verify ( x => x . GetRouteConfig ( "POST" , "/api/users/123/avatar" ) , Times . Once ) ;
145
+ _mockRouteConfigParser . Verify ( x => x . ExtractPathParameters ( It . IsAny < ApiGatewayRouteConfig > ( ) , "/api/users/123/avatar" ) , Times . Once ) ;
146
+ _mockHttpRequestUtility . Verify ( x => x . IsBinaryContent ( "application/octet-stream" ) , Times . Once ) ;
147
+ _mockHttpRequestUtility . Verify ( x => x . ReadRequestBody ( It . IsAny < HttpRequest > ( ) ) , Times . Once ) ;
148
+ }
149
+
111
150
[ Fact ]
112
151
public void ToApiGatewayRequest_ShouldReturnValidApiGatewayProxyRequest ( )
113
152
{
0 commit comments