public void IsEmpty_WhenCodeIsNotZero_ShouldReturnFalse() { // Arrange // Act ErrorResponseInfo target = new ErrorResponseInfo(string.Empty, 0, 400, string.Empty); // Assert target.IsEmpty().Should().Be.False(); }
public void IsEmpty_WhenMessageIsWhiteSpace_ShouldReturnTrue() { // Arrange // Act ErrorResponseInfo target = new ErrorResponseInfo(string.Empty, 0, 0, " "); // Assert target.IsEmpty().Should().Be.True(); }
public void Constructor_WhenCalled_ExpectAllValuesSet() { const int code = 999; const string message = "Message"; const int id = 400; ErrorResponseInfo target = new ErrorResponseInfo(id, code, message); target.Id.Should().Equal(id); target.Code.Should().Equal(code); target.Message.Should().Equal(message); target.AdvisoryDelay.Should().Equal(0); }
public bool Handle(IParameters parameters, string response) { _hasError = false; if (_errorParser.CanParse(parameters)) { ErrorInfo = _errorParser.Parse(response) as ErrorResponseInfo; if (ErrorInfo?.Code > 0) { _hasError = true; } } // This return value is indicating whether errors occurred while running the error parsing process, // not whether errors were returned from the IRandomService call, return true; }
public IResponseInfo Parse(string response) { if (string.IsNullOrWhiteSpace(response)) return ErrorResponseInfo.Empty(); JObject json = JObject.Parse(response); var version = JsonHelper.JsonToString(json.GetValue(JsonRpcConstants.RPC_PARAMETER_NAME)); ErrorResponseInfo returnValue = ErrorResponseInfo.Empty(version); var result = json.GetValue(JsonRpcConstants.ERROR_PARAMETER_NAME) as JObject; if (result != null) { string message = null; var code = JsonHelper.JsonToInt(result.GetValue(JsonRpcConstants.CODE_PARAMETER_NAME)); var data = result.GetValue(JsonRpcConstants.DATA_PARAMETER_NAME); if (!data.HasValues) { message = ResourceHelper.GetString(StringsConstants.ERROR_CODE_KEY + code); } else { var unformattedMessage = ResourceHelper.GetString(StringsConstants.ERROR_CODE_KEY + code); if (!string.IsNullOrWhiteSpace(unformattedMessage)) message = string.Format(unformattedMessage, data.Values<object>().ToArray()); } if (string.IsNullOrWhiteSpace(message)) { message = JsonHelper.JsonToString(result.GetValue(JsonRpcConstants.MESSAGE_PARAMETER_NAME)); if (data.HasValues) message = string.Format(message, data.Values<object>().ToArray()); } int id = JsonHelper.JsonToInt(json.GetValue("id")); returnValue = new ErrorResponseInfo(version, id, code, message); } return returnValue; }
public void IsEmpty_WhenMessageIsNotNullOrEmpty_ShouldReturnFalse() { // Arrange // Act ErrorResponseInfo target = new ErrorResponseInfo(string.Empty, 0, 0, "Test Message"); // Assert target.IsEmpty().Should().Be.False(); }
public void GetHashCode_WhenCalled_ShouldNotThrowException() { // Arrange const string version = "2.0"; int id = RandomGenerator.GetInteger(1); const int code = 400; const string message = "Test Message"; var target = new ErrorResponseInfo(version, id, code, message); // Act var actual = target.GetHashCode(); // Assert actual.Should().Not.Equal(0); }
public void Equals_WhenPropertiesDoNotMatch_ShouldReturnFalse() { // Arrange const string version = "2.0"; int id = RandomGenerator.GetInteger(1); const int code = 400; const string message = "Test Message"; var one = new ErrorResponseInfo(version, id, code, message); var two = new ErrorResponseInfo(version, id, 12346, message); // Act var actual = one.Equals(two); // Assert actual.Should().Be.False(); }
public void IsEmpty_WhenCodeAndMessageAreNotEmpty_ShouldReturnFalse() { // Arrange // Act ErrorResponseInfo target = new ErrorResponseInfo(string.Empty, 0, 400, "Test Message"); // Assert target.IsEmpty().Should().Be.False(); }