Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }