Skip to content

Commit 0724927

Browse files
author
Leo
committed
Test fixes
1 parent 3576351 commit 0724927

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/InstanceIdClientTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task BadRequest()
7878
() => client.SubscribeToTopicAsync("test-topic", new List<string> { "abc123" }));
7979

8080
Assert.Equal(ErrorCode.InvalidArgument, exception.ErrorCode);
81-
Assert.Equal("Unexpected HTTP response with status: 400 (Bad Request)\nBad Request", exception.Message);
81+
Assert.Equal("Unexpected HTTP response with status: 400 (BadRequest)\nBadRequest", exception.Message);
8282
Assert.Null(exception.MessagingErrorCode);
8383
Assert.NotNull(exception.HttpResponse);
8484
Assert.Null(exception.InnerException);
@@ -144,7 +144,7 @@ public async Task NotFound()
144144
() => client.SubscribeToTopicAsync("test-topic", new List<string> { "abc123" }));
145145

146146
Assert.Equal(ErrorCode.NotFound, exception.ErrorCode);
147-
Assert.Equal("Unexpected HTTP response with status: 404 (Not Found)\nNot Found", exception.Message);
147+
Assert.Equal("Unexpected HTTP response with status: 404 (NotFound)\nNotFound", exception.Message);
148148
Assert.Null(exception.MessagingErrorCode);
149149
Assert.NotNull(exception.HttpResponse);
150150
Assert.Null(exception.InnerException);
@@ -166,7 +166,7 @@ public async Task ServiceUnavailable()
166166
() => client.SubscribeToTopicAsync("test-topic", new List<string> { "abc123" }));
167167

168168
Assert.Equal(ErrorCode.Unavailable, exception.ErrorCode);
169-
Assert.Equal("Unexpected HTTP response with status: 503 (Service Unavailable)\nService Unavailable", exception.Message);
169+
Assert.Equal("Unexpected HTTP response with status: 503 (ServiceUnavailable)\nServiceUnavailable", exception.Message);
170170
Assert.Null(exception.MessagingErrorCode);
171171
Assert.NotNull(exception.HttpResponse);
172172
Assert.Null(exception.InnerException);

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/TopicManagementResponseTest.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,23 @@ public void NullResponse()
4545
[Fact]
4646
public void EmptyResponse()
4747
{
48-
Assert.Throws<ArgumentException>(() =>
48+
Assert.Throws<ArgumentNullException>(() =>
4949
{
5050
var instanceIdServiceResponse = new InstanceIdServiceResponse();
5151
new TopicManagementResponse(instanceIdServiceResponse);
5252
});
5353
}
5454

5555
[Fact]
56-
public void UnknownError()
56+
public void UnregisteredToken()
5757
{
5858
var json = @"{""results"": [{}, {""error"":""NOT_FOUND""}]}";
5959
var instanceIdServiceResponse = JsonConvert.DeserializeObject<InstanceIdServiceResponse>(json);
6060
var response = new TopicManagementResponse(instanceIdServiceResponse);
6161

6262
Assert.Single(response.Errors);
63-
Assert.Equal("unknown-error", response.Errors[0].Reason);
64-
Assert.Equal(0, response.Errors[0].Index);
65-
}
66-
67-
[Fact]
68-
public void UnexpectedResponse()
69-
{
70-
var json = @"{""results"": [{""unexpected"":""NOT_A_REAL_CODE""}]}";
71-
var instanceIdServiceResponse = JsonConvert.DeserializeObject<InstanceIdServiceResponse>(json);
72-
var response = new TopicManagementResponse(instanceIdServiceResponse);
73-
74-
Assert.Single(response.Errors);
75-
Assert.Equal("unknown-error", response.Errors[0].Reason);
76-
Assert.Equal(0, response.SuccessCount);
63+
Assert.Equal("registration-token-not-registered", response.Errors[0].Reason);
64+
Assert.Equal(1, response.Errors[0].Index);
7765
}
7866

7967
[Fact]

FirebaseAdmin/FirebaseAdmin/Messaging/TopicManagementResponse.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ public sealed class TopicManagementResponse
2828
/// <param name="instanceIdServiceResponse">The results from the response produced by FCM topic management operations.</param>
2929
internal TopicManagementResponse(InstanceIdServiceResponse instanceIdServiceResponse)
3030
{
31-
if (instanceIdServiceResponse == null || instanceIdServiceResponse.ResultCount == 0)
31+
if (instanceIdServiceResponse == null)
3232
{
33-
throw new ArgumentException("unexpected response from topic management service");
33+
throw new ArgumentNullException("Unexpected null response from topic management service");
34+
}
35+
36+
if (instanceIdServiceResponse.ResultCount == 0)
37+
{
38+
throw new ArgumentNullException("Unexpected empty response from topic management service");
3439
}
3540

3641
var resultErrors = new List<ErrorInfo>();

0 commit comments

Comments
 (0)