public void Parse_WithJsonResponseWhereJsonIsWrong_ReturnsUnknown500Error() { // Arrange var response = new AblyResponse { TextResponse = string.Empty, Type = ResponseType.Json, StatusCode = (HttpStatusCode)500 }; // Act var errorInfo = ErrorInfo.Parse(response); // Assert errorInfo.Message.Should().Be("Unknown error"); errorInfo.Code.Should().Be(ErrorCodes.InternalError); errorInfo.StatusCode.Should().Be(response.StatusCode); }
public void Parse_WithJsonResponseWhereJsonIsWrong_ReturnsUnknown500Error() { //Arrange var response = new AblyResponse() { TextResponse = "", Type = ResponseType.Json, StatusCode = (HttpStatusCode)500 }; //Act var errorInfo = ErrorInfo.Parse(response); //Assert Assert.Equal("Unknown error", errorInfo.Reason); Assert.Equal(500, errorInfo.Code); Assert.Equal(response.StatusCode, errorInfo.StatusCode); }
public void Parse_WithValidJsonResponse_RetrievesCodeAndReasonFromJson() { //Arrange var reason = "test"; var code = 40400; var response = new AblyResponse() { TextResponse = string.Format("{{ \"error\": {{ \"code\":{0}, \"message\":\"{1}\" }} }}", code, reason), Type = ResponseType.Json, StatusCode = (HttpStatusCode)500 }; //Act var errorInfo = ErrorInfo.Parse(response); //Assert Assert.Equal(reason, errorInfo.Reason); Assert.Equal(code, errorInfo.Code); }
public void Parse_WithValidJsonResponse_RetrievesCodeAndReasonFromJson() { // Arrange const string reason = "test"; var response = new AblyResponse { TextResponse = $"{{ \"error\": {{ \"code\":{ErrorCodes.NotFound}, \"message\":\"{reason}\" }} }}", Type = ResponseType.Json, StatusCode = (HttpStatusCode)500 }; // Act var errorInfo = ErrorInfo.Parse(response); // Assert errorInfo.Message.Should().Be(reason); errorInfo.Code.Should().Be(ErrorCodes.NotFound); }