コード例 #1
0
        public async Task UnexpectedErrorResponse(HttpStatusCode statusCode, ErrorCode expected)
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = statusCode,
                Response   = "NonJsonErrorResponse",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(expected, exception.ErrorCode);
            Assert.Equal(
                "Unexpected HTTP response with status: "
                + $"{(int)statusCode} ({statusCode}){Environment.NewLine}NonJsonErrorResponse",
                exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
        }
コード例 #2
0
        public async Task ServiceUnavailable()
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = HttpStatusCode.ServiceUnavailable,
                Response   = "ServiceUnavailable",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential, RetryOptions.NoBackOff);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(ErrorCode.Unavailable, exception.ErrorCode);
            Assert.Equal(
                $"Unexpected HTTP response with status: 503 (ServiceUnavailable){Environment.NewLine}ServiceUnavailable",
                exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
            Assert.Equal(5, handler.Calls);
        }
コード例 #3
0
        public async Task UnsubscribeFromTopicAsync()
        {
            var handler = new MockMessageHandler()
            {
                Response = @"{""results"":[{}]}",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var result = await client.UnsubscribeFromTopicAsync("test-topic", new List <string> {
                "abc123"
            });

            Assert.Equal(1, result.SuccessCount);
        }
コード例 #4
0
        public async Task TransportError()
        {
            var handler = new MockMessageHandler()
            {
                Exception = new HttpRequestException("Transport error"),
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential, RetryOptions.NoBackOff);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(ErrorCode.Unknown, exception.ErrorCode);
            Assert.Null(exception.MessagingErrorCode);
            Assert.Null(exception.HttpResponse);
            Assert.NotNull(exception.InnerException);
            Assert.Equal(5, handler.Calls);
        }
コード例 #5
0
        public async Task Unauthorized()
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = HttpStatusCode.Unauthorized,
                Response   = "Unauthorized",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync("test-topic", new List <string> {
                "abc123"
            }));

            Assert.Equal(ErrorCode.Unauthenticated, exception.ErrorCode);
            Assert.Equal("Unexpected HTTP response with status: 401 (Unauthorized)\nUnauthorized", exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
        }
コード例 #6
0
        public async Task BadRequest()
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = HttpStatusCode.BadRequest,
                Response   = "BadRequest",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(ErrorCode.InvalidArgument, exception.ErrorCode);
            Assert.Equal("Unexpected HTTP response with status: 400 (BadRequest)\nBadRequest", exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
        }
コード例 #7
0
        public async Task Forbidden()
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = HttpStatusCode.Forbidden,
                Response   = "Forbidden",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(ErrorCode.PermissionDenied, exception.ErrorCode);
            Assert.Equal("Unexpected HTTP response with status: 403 (Forbidden)\nForbidden", exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
        }
コード例 #8
0
        public async Task ErrorResponse(HttpStatusCode statusCode, ErrorCode expected)
        {
            var handler = new MockMessageHandler()
            {
                StatusCode = statusCode,
                Response   = @"{""error"":""ErrorCode""}",
            };
            var factory = new MockHttpClientFactory(handler);

            var client = new InstanceIdClient(factory, MockCredential);

            var exception = await Assert.ThrowsAsync <FirebaseMessagingException>(
                () => client.SubscribeToTopicAsync(new List <string> {
                "abc123"
            }, "test-topic"));

            Assert.Equal(expected, exception.ErrorCode);
            Assert.Equal(
                "Error while calling the IID service: ErrorCode",
                exception.Message);
            Assert.Null(exception.MessagingErrorCode);
            Assert.NotNull(exception.HttpResponse);
            Assert.Null(exception.InnerException);
        }