public void NonJsonResponse() { var text = "not json"; var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.ServiceUnavailable, Content = new StringContent(text, Encoding.UTF8, "text/plain"), }; var handler = new PlatformErrorHandler(); var error = Assert.Throws <FirebaseException>(() => handler.ThrowIfError(resp, text)); Assert.Equal(ErrorCode.Unavailable, error.ErrorCode); Assert.Equal( $"Unexpected HTTP response with status: 503 (ServiceUnavailable)\n{text}", error.Message); Assert.Same(resp, error.HttpResponse); Assert.Null(error.InnerException); }
public void PlatformErrorWithoutCodeOrMessage() { var json = @"{}"; var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.ServiceUnavailable, Content = new StringContent(json, Encoding.UTF8, "application/json"), }; var handler = new PlatformErrorHandler(); var error = Assert.Throws <FirebaseException>(() => handler.ThrowIfError(resp, json)); Assert.Equal(ErrorCode.Unavailable, error.ErrorCode); Assert.Equal( "Unexpected HTTP response with status: 503 (ServiceUnavailable)\n{}", error.Message); Assert.Same(resp, error.HttpResponse); Assert.Null(error.InnerException); }
public void PlatformError() { var json = @"{ ""error"": { ""status"": ""UNAVAILABLE"", ""message"": ""Test error message"" } }"; var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.ServiceUnavailable, Content = new StringContent(json, Encoding.UTF8, "application/json"), }; var handler = new PlatformErrorHandler(); var error = Assert.Throws <FirebaseException>(() => handler.ThrowIfError(resp, json)); Assert.Equal(ErrorCode.Unavailable, error.ErrorCode); Assert.Equal("Test error message", error.Message); Assert.Same(resp, error.HttpResponse); Assert.Null(error.InnerException); }