public async Task SendAllAsyncNullList() { var factory = new MockHttpClientFactory(new MockMessageHandler()); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); await Assert.ThrowsAsync <ArgumentNullException>(() => client.SendAllAsync(null)); }
public async Task SendAllAsyncWithTooManyMessages() { var factory = new MockHttpClientFactory(new MockMessageHandler()); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var messages = Enumerable.Range(0, 101).Select(_ => new Message { Topic = "test-topic" }); await Assert.ThrowsAsync <ArgumentException>(() => client.SendAllAsync(messages)); }
public async Task SendAllAsyncWithErrorNoDetail() { var rawResponse = @" --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Vary: Origin Vary: X-Origin Vary: Referer { ""name"": ""projects/fir-adminintegrationtests/messages/8580920590356323124"" } --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 400 Bad Request Content-Type: application/json; charset=UTF-8 { ""error"": { ""code"": 400, ""message"": ""The registration token is not a valid FCM registration token"", ""status"": ""INVALID_ARGUMENT"" } } --batch_test-boundary "; var handler = new MockMessageHandler() { Response = rawResponse, ApplyHeaders = (_, headers) => { headers.Remove("Content-Type"); headers.TryAddWithoutValidation("Content-Type", "multipart/mixed; boundary=batch_test-boundary"); }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(new FirebaseMessagingClient.Args() { ClientFactory = factory, Credential = MockCredential, ProjectId = "test-project", }); var message1 = new Message() { Token = "test-token1", }; var message2 = new Message() { Token = "test-token2", }; var response = await client.SendAllAsync(new[] { message1, message2 }); Assert.Equal(1, response.SuccessCount); Assert.Equal(1, response.FailureCount); Assert.Equal("projects/fir-adminintegrationtests/messages/8580920590356323124", response.Responses[0].MessageId); var exception = response.Responses[1].Exception; Assert.NotNull(exception); Assert.Equal(ErrorCode.InvalidArgument, exception.ErrorCode); Assert.Equal("The registration token is not a valid FCM registration token", exception.Message); Assert.Null(exception.MessagingErrorCode); Assert.NotNull(exception.HttpResponse); Assert.Equal(1, handler.Calls); Assert.Equal(2, this.CountLinesWithPrefix(handler.LastRequestBody, VersionHeader)); Assert.Equal(2, this.CountLinesWithPrefix(handler.LastRequestBody, ApiFormatHeader)); }
public async Task SendAllAsyncWithNoMessages() { var factory = new MockHttpClientFactory(new MockMessageHandler()); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); await Assert.ThrowsAsync <ArgumentException>(() => client.SendAllAsync(Enumerable.Empty <Message>())); }
public async Task SendAllAsync() { var rawResponse = @" --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Vary: Origin Vary: X-Origin Vary: Referer { ""name"": ""projects/fir-adminintegrationtests/messages/8580920590356323124"" } --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Vary: Origin Vary: X-Origin Vary: Referer { ""name"": ""projects/fir-adminintegrationtests/messages/5903525881088369386"" } --batch_test-boundary "; var handler = new MockMessageHandler() { Response = rawResponse, ApplyHeaders = (_, headers) => { headers.Remove("Content-Type"); headers.TryAddWithoutValidation("Content-Type", "multipart/mixed; boundary=batch_test-boundary"); }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message1 = new Message() { Token = "test-token1", }; var message2 = new Message() { Token = "test-token2", }; var response = await client.SendAllAsync(new[] { message1, message2 }); Assert.Equal(2, response.SuccessCount); Assert.Equal("projects/fir-adminintegrationtests/messages/8580920590356323124", response.Responses[0].MessageId); Assert.Equal("projects/fir-adminintegrationtests/messages/5903525881088369386", response.Responses[1].MessageId); Assert.Equal(1, handler.Calls); Assert.Equal(2, this.CountLinesWithPrefix(handler.LastRequestBody, VersionHeader)); Assert.Equal(2, this.CountLinesWithPrefix(handler.LastRequestBody, ApiFormatHeader)); }
public async Task SendAllAsyncWithError() { var rawResponse = @" --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Vary: Origin Vary: X-Origin Vary: Referer { ""name"": ""projects/fir-adminintegrationtests/messages/8580920590356323124"" } --batch_test-boundary Content-Type: application/http Content-ID: response- HTTP/1.1 400 Bad Request Content-Type: application/json; charset=UTF-8 Vary: Origin Vary: X-Origin Vary: Referer { ""error"": { ""code"": 400, ""message"": ""The registration token is not a valid FCM registration token"", ""errors"": [ { ""message"": ""The registration token is not a valid FCM registration token"", ""domain"": ""global"", ""reason"": ""badRequest"" } ], ""status"": ""INVALID_ARGUMENT"" } } --batch_test-boundary "; var handler = new MockMessageHandler() { Response = rawResponse, ApplyContentHeaders = (headers) => { headers.Remove("Content-Type"); headers.TryAddWithoutValidation("Content-Type", "multipart/mixed; boundary=batch_test-boundary"); }, }; var factory = new MockHttpClientFactory(handler); var client = new FirebaseMessagingClient(factory, MockCredential, "test-project"); var message1 = new Message() { Token = "test-token1", }; var message2 = new Message() { Token = "test-token2", }; var response = await client.SendAllAsync(new[] { message1, message2 }); Assert.Equal(1, response.SuccessCount); Assert.Equal(1, response.FailureCount); Assert.Equal("projects/fir-adminintegrationtests/messages/8580920590356323124", response.Responses[0].MessageId); Assert.NotNull(response.Responses[1].Exception); Assert.Equal(1, handler.Calls); var versionHeader = $"X-Firebase-Client: {FirebaseMessagingClient.ClientVersion}"; Assert.Equal(2, this.CountLinesWithPrefix(handler.Request, versionHeader)); }