public void Serialize_Default_ReturnsExpected() { var health = new HealthEndpointResponse(null); var json = Serialize(health); Assert.Equal("{\"status\":\"UNKNOWN\"}", json); }
public void Serialize_WithDetails_ReturnsExpected() { var health = new HealthEndpointResponse(null) { Status = HealthStatus.OUT_OF_SERVICE, Description = "Test", Details = new Dictionary <string, object>() { { "item1", new HealthData() }, { "item2", "String" }, { "item3", false } } }; var json = Serialize(health); Assert.Equal("{\"status\":\"OUT_OF_SERVICE\",\"description\":\"Test\",\"item1\":{\"stringProperty\":\"Testdata\",\"intProperty\":100,\"boolProperty\":true},\"item2\":\"String\",\"item3\":false}", json); }
private string Serialize(HealthEndpointResponse result) { try { var options = new JsonSerializerOptions() { IgnoreNullValues = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; options.Converters.Add(new HealthConverter()); return(JsonSerializer.Serialize(result, options)); } catch (Exception) { } return(string.Empty); }