|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
| 15 | +using System; |
15 | 16 | using System.Collections.Generic;
|
16 | 17 | using System.Net;
|
17 | 18 | using System.Net.Http;
|
18 | 19 | using System.Text;
|
| 20 | +using FirebaseAdmin.Util; |
19 | 21 | using Xunit;
|
20 | 22 |
|
21 | 23 | namespace FirebaseAdmin.Messaging.Tests
|
@@ -140,5 +142,43 @@ public void NoDetails()
|
140 | 142 | Assert.Same(resp, error.HttpResponse);
|
141 | 143 | Assert.Null(error.InnerException);
|
142 | 144 | }
|
| 145 | + |
| 146 | + [Fact] |
| 147 | + public void DeserializeException() |
| 148 | + { |
| 149 | + var text = "plain text"; |
| 150 | + var resp = new HttpResponseMessage() |
| 151 | + { |
| 152 | + StatusCode = HttpStatusCode.ServiceUnavailable, |
| 153 | + Content = new StringContent(text, Encoding.UTF8, "text/plain"), |
| 154 | + }; |
| 155 | + var inner = new Exception("Deserialization error"); |
| 156 | + |
| 157 | + var error = MessagingErrorHandler.Instance.HandleDeserializeException( |
| 158 | + inner, new ResponseInfo(resp, text)); |
| 159 | + |
| 160 | + Assert.Equal(ErrorCode.Unknown, error.ErrorCode); |
| 161 | + Assert.Equal( |
| 162 | + $"Error parsing response from FCM. Deserialization error: {text}", |
| 163 | + error.Message); |
| 164 | + Assert.Null(error.MessagingErrorCode); |
| 165 | + Assert.Same(resp, error.HttpResponse); |
| 166 | + Assert.Same(inner, error.InnerException); |
| 167 | + } |
| 168 | + |
| 169 | + [Fact] |
| 170 | + public void HttpRequestException() |
| 171 | + { |
| 172 | + var exception = new HttpRequestException("network error"); |
| 173 | + |
| 174 | + var error = MessagingErrorHandler.Instance.HandleHttpRequestException(exception); |
| 175 | + |
| 176 | + Assert.Equal(ErrorCode.Unknown, error.ErrorCode); |
| 177 | + Assert.Equal( |
| 178 | + "Unknown error while making a remote service call: network error", error.Message); |
| 179 | + Assert.Null(error.MessagingErrorCode); |
| 180 | + Assert.Null(error.HttpResponse); |
| 181 | + Assert.Same(exception, error.InnerException); |
| 182 | + } |
143 | 183 | }
|
144 | 184 | }
|
0 commit comments