@@ -138,24 +138,35 @@ public void TestHandlingSuccessHttpCodes(HttpStatusCode status)
138
138
[ TestMethod ]
139
139
[ DataRow ( HttpStatusCode . BadRequest , "Bad Request" ) ]
140
140
[ DataRow ( HttpStatusCode . RequestEntityTooLarge , "Payload too large" ) ]
141
- [ DataRow ( ( HttpStatusCode ) 429 , "Too many request. " ) ]
141
+ [ DataRow ( ( HttpStatusCode ) 429 , "Too many request" ) ]
142
142
[ DataRow ( HttpStatusCode . NotFound , "Subscription no longer valid" ) ]
143
143
[ DataRow ( HttpStatusCode . Gone , "Subscription no longer valid" ) ]
144
144
[ DataRow ( HttpStatusCode . InternalServerError , "Received unexpected response code: 500" ) ]
145
145
public void TestHandlingFailureHttpCodes ( HttpStatusCode status , string expectedMessage )
146
146
{
147
147
var actual = Assert . ThrowsException < WebPushException > ( ( ) => TestSendNotification ( status ) ) ;
148
-
149
148
Assert . AreEqual ( expectedMessage , actual . Message ) ;
150
149
}
151
150
152
- private void TestSendNotification ( HttpStatusCode status )
151
+ [ TestMethod ]
152
+ [ DataRow ( HttpStatusCode . BadRequest , "authorization key missing" , "Bad Request. Details: authorization key missing" ) ]
153
+ [ DataRow ( HttpStatusCode . RequestEntityTooLarge , "max size is 512" , "Payload too large. Details: max size is 512" ) ]
154
+ [ DataRow ( ( HttpStatusCode ) 429 , "the api is limited" , "Too many request. Details: the api is limited" ) ]
155
+ [ DataRow ( HttpStatusCode . NotFound , "" , "Subscription no longer valid" ) ]
156
+ [ DataRow ( HttpStatusCode . Gone , "" , "Subscription no longer valid" ) ]
157
+ [ DataRow ( HttpStatusCode . InternalServerError , "internal error" , "Received unexpected response code: 500. Details: internal error" ) ]
158
+ public void TestHandlingFailureMessages ( HttpStatusCode status , string response , string expectedMessage )
153
159
{
154
- var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ; ;
155
- httpMessageHandlerMock . When ( TestFcmEndpoint ) . Respond ( status ) ;
160
+ var actual = Assert . ThrowsException < WebPushException > ( ( ) => TestSendNotification ( status , response ) ) ;
161
+ Assert . AreEqual ( expectedMessage , actual . Message ) ;
162
+ }
156
163
164
+ private void TestSendNotification ( HttpStatusCode status , string response = null )
165
+ {
166
+ var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
167
+ var httpContent = response == null ? null : new StringContent ( response ) ;
168
+ httpMessageHandlerMock . When ( TestFcmEndpoint ) . Respond ( new HttpResponseMessage { StatusCode = status , Content = httpContent } ) ;
157
169
client . SetVapidDetails ( TestSubject , TestPublicKey , TestPrivateKey ) ;
158
-
159
170
client . SendNotification ( subscription , "123" ) ;
160
171
}
161
172
}
0 commit comments