Skip to content

Commit 455ea24

Browse files
committed
Added a couple of missing FCM tests
1 parent 2826f59 commit 455ea24

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessagingErrorHandlerTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System;
1516
using System.Collections.Generic;
1617
using System.Net;
1718
using System.Net.Http;
1819
using System.Text;
20+
using FirebaseAdmin.Util;
1921
using Xunit;
2022

2123
namespace FirebaseAdmin.Messaging.Tests
@@ -140,5 +142,43 @@ public void NoDetails()
140142
Assert.Same(resp, error.HttpResponse);
141143
Assert.Null(error.InnerException);
142144
}
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+
}
143183
}
144184
}

FirebaseAdmin/FirebaseAdmin/Messaging/MessagingErrorHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public FirebaseMessagingException HandleDeserializeException(
6767
{
6868
return new FirebaseMessagingException(
6969
ErrorCode.Unknown,
70-
$"Error parsing response from FCM: {responseInfo.Body}",
70+
$"Error parsing response from FCM. {exception.Message}: {responseInfo.Body}",
7171
inner: exception,
7272
response: responseInfo.HttpResponse);
7373
}

0 commit comments

Comments
 (0)