@@ -138,24 +138,35 @@ public void TestHandlingSuccessHttpCodes(HttpStatusCode status)
138138 [ TestMethod ]
139139 [ DataRow ( HttpStatusCode . BadRequest , "Bad Request" ) ]
140140 [ DataRow ( HttpStatusCode . RequestEntityTooLarge , "Payload too large" ) ]
141- [ DataRow ( ( HttpStatusCode ) 429 , "Too many request. " ) ]
141+ [ DataRow ( ( HttpStatusCode ) 429 , "Too many request" ) ]
142142 [ DataRow ( HttpStatusCode . NotFound , "Subscription no longer valid" ) ]
143143 [ DataRow ( HttpStatusCode . Gone , "Subscription no longer valid" ) ]
144144 [ DataRow ( HttpStatusCode . InternalServerError , "Received unexpected response code: 500" ) ]
145145 public void TestHandlingFailureHttpCodes ( HttpStatusCode status , string expectedMessage )
146146 {
147147 var actual = Assert . ThrowsException < WebPushException > ( ( ) => TestSendNotification ( status ) ) ;
148-
149148 Assert . AreEqual ( expectedMessage , actual . Message ) ;
150149 }
151150
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 )
153159 {
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+ }
156163
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 } ) ;
157169 client . SetVapidDetails ( TestSubject , TestPublicKey , TestPrivateKey ) ;
158-
159170 client . SendNotification ( subscription , "123" ) ;
160171 }
161172 }
0 commit comments