public async Task SendAsync() { var handler = new MockMessageHandler() { Response = new FirebaseMessagingClient.SendResponse() { Name = "test-response", }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var response = await client.SendAsync(message); Assert.Equal("test-response", response); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.Request); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); // Send in dryRun mode. response = await client.SendAsync(message, dryRun : true); Assert.Equal("test-response", response); req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.Request); Assert.Equal("test-topic", req.Message.Topic); Assert.True(req.ValidateOnly); Assert.Equal(2, handler.Calls); }
public async Task SendAsync() { var handler = new MockMessageHandler() { Response = new FirebaseMessagingClient.SingleMessageResponse() { Name = "test-response", }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var response = await client.SendAsync(message); Assert.Equal("test-response", response); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>(handler.LastRequestBody); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); this.CheckHeaders(handler.LastRequestHeaders); }
public async Task TransportError() { var handler = new MockMessageHandler() { Exception = new HttpRequestException("Transport error"), }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var ex = await Assert.ThrowsAsync <FirebaseMessagingException>( async() => await client.SendAsync(message)); Assert.Equal(ErrorCode.Unknown, ex.ErrorCode); Assert.Equal( "Unknown error while making a remote service call: Transport error", ex.Message); Assert.Null(ex.MessagingErrorCode); Assert.Null(ex.HttpResponse); Assert.Same(handler.Exception, ex.InnerException); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.LastRequestBody); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); }
public async Task HttpErrorNonJsonAsync() { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.InternalServerError, Response = "not json", }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var ex = await Assert.ThrowsAsync <FirebaseMessagingException>( async() => await client.SendAsync(message)); Assert.Equal(ErrorCode.Internal, ex.ErrorCode); Assert.Equal( "Unexpected HTTP response with status: 500 (InternalServerError)\nnot json", ex.Message); Assert.Null(ex.MessagingErrorCode); Assert.NotNull(ex.HttpResponse); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.LastRequestBody); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); }
public async Task HttpErrorNoDetailAsync() { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.InternalServerError, Response = @"{ ""error"": { ""status"": ""PERMISSION_DENIED"", ""message"": ""test error"" } }", }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var ex = await Assert.ThrowsAsync <FirebaseMessagingException>( async() => await client.SendAsync(message)); Assert.Equal(ErrorCode.PermissionDenied, ex.ErrorCode); Assert.Equal("test error", ex.Message); Assert.Null(ex.MessagingErrorCode); Assert.NotNull(ex.HttpResponse); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.LastRequestBody); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); }
public async Task SendDryRunAsync() { var handler = new MockMessageHandler() { Response = new FirebaseMessagingClient.SingleMessageResponse() { Name = "test-response", }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var response = await client.SendAsync(message, dryRun : true); Assert.Equal("test-response", response); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>(handler.LastRequestBody); Assert.Equal("test-topic", req.Message.Topic); Assert.True(req.ValidateOnly); Assert.Equal(1, handler.Calls); var versionHeader = handler.LastRequestHeaders.GetValues("X-Firebase-Client").First(); Assert.Equal(FirebaseMessagingClient.ClientVersion, versionHeader); }
public async Task HttpErrorAsync() { var handler = new MockMessageHandler() { StatusCode = HttpStatusCode.InternalServerError, Response = "not json", }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message = new Message() { Topic = "test-topic", }; var ex = await Assert.ThrowsAsync <FirebaseException>( async() => await client.SendAsync(message)); Assert.Contains("not json", ex.Message); var req = JsonConvert.DeserializeObject <FirebaseMessagingClient.SendRequest>( handler.Request); Assert.Equal("test-topic", req.Message.Topic); Assert.False(req.ValidateOnly); Assert.Equal(1, handler.Calls); }