public void Should_not_deserialize_with_json_property_if_not_appropriate_type(DeviceItem obj) { var json = JsonForCastle.SerializeObject(obj); var result = JsonForCastle.DeserializeObject <DeviceItem>(json); result.Should().NotBeNull(); }
public void Should_deserialize_with_json_property_if_appropriate_type(IHasJson obj) { var json = JsonForCastle.SerializeObject(obj); var result = JsonForCastle.DeserializeObject <Device>(json); result.Internal.Should().NotBeNull(); }
public void Should_deserialize_from_snakecase() { const string json = "{\"user_id\":\"123\"}"; var result = JsonForCastle.DeserializeObject <GenericObject>(json); result.UserId.Should().Be("123"); }
private async Task <TResponse> SendRequest <TResponse>(HttpMethod method, string endpoint, object payload = null) where TResponse : class, new() { var jsonContent = payload != null?payload.ToHttpContent() : null; var requestMessage = new HttpRequestMessage(method, endpoint) { Content = jsonContent }; _logger.Info(() => string.Concat( "Request", Environment.NewLine, requestMessage, Environment.NewLine, payload != null ? JsonForCastle.SerializeObject(payload) : "" )); try { var response = await _httpClient.SendAsync(requestMessage); var content = response.Content != null ? await response.Content.ReadAsStringAsync() : ""; _logger.Info(() => string.Concat( "Response", Environment.NewLine, response, Environment.NewLine, content )); if (response.IsSuccessStatusCode) { return(JsonForCastle.DeserializeObject <TResponse>(content)); } throw await response.ToCastleException(requestMessage.RequestUri.AbsoluteUri); } catch (OperationCanceledException) { throw new CastleTimeoutException( requestMessage.RequestUri.AbsoluteUri, (int)_httpClient.Timeout.TotalMilliseconds); } }
public void Should_only_allow_serialization_for_scrub() { Action act = () => JsonForCastle.DeserializeObject <NotValidScrubbing>("{ \"generic_property\":\"test\" }"); act.Should().Throw <NotSupportedException>(); }
public void Should_deserialize_to_default_if_error() { var result = JsonForCastle.DeserializeObject <VoidResponse>(""); result.Should().NotBeNull(); }