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 static StringContent ToHttpContent(this object obj) { return(new StringContent( JsonForCastle.SerializeObject(obj), Encoding.UTF8, "application/json")); }
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"); }
public void Should_serialize_client_id_to_false_if_empty(string value, string expected) { var obj = new RequestContext() { ClientId = value }; var result = JsonForCastle.SerializeObject(obj); result.Should().Contain(expected); }
public void Should_serialize_header_to_truebool_if_truestring( string name, string value, string expected) { var obj = new RequestContext() { Headers = new Dictionary <string, string>() { [name] = value } }; var result = JsonForCastle.SerializeObject(obj); result.Should().Contain(expected); }
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 JObject BuildTrackRequest(ActionRequest request) { var prepared = (request ?? new ActionRequest()).PrepareApiCopy(_configuration.AllowList, _configuration.DenyList); return(JsonForCastle.FromObject(prepared)); }
public JObject BuildAuthenticateRequest(ActionRequest request) { var prepared = (request ?? new ActionRequest()).PrepareApiCopy(_configuration.Whitelist, _configuration.Blacklist); return(JsonForCastle.FromObject(prepared)); }
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(); }