public async Task Can_format_payload_with_multiple_fields_correctly() { // Arrange await using var ms = new MemoryStream(); await using var jsonWriter = new Utf8JsonWriter(ms); var fields = new Dictionary <string, object> { { "field1key", "field1value" }, { "field2key", 2 }, { "field3key", false } }; var timestamp = new DateTime(2017, 1, 1, 1, 1, 1, DateTimeKind.Utc); var point = new DatadogPoint(null, "measurement", fields, MetricTags.Empty, new DefaultDatadogMetricJsonWriter(), FlushInterval, timestamp); // Act jsonWriter.WriteStartArray(); await point.Write(jsonWriter); jsonWriter.WriteEndArray(); await jsonWriter.FlushAsync(); var result = Encoding.UTF8.GetString(ms.ToArray()); // Assert result.Should().Be("[{\"metric\":\"measurement.field1key\",\"points\":[[1483232461,0]],\"type\":\"gauge\",\"tags\":[]},{\"metric\":\"measurement.field2key\",\"points\":[[1483232461,2]],\"type\":\"gauge\",\"tags\":[]},{\"metric\":\"measurement.field3key\",\"points\":[[1483232461,0]],\"type\":\"gauge\",\"tags\":[]}]"); }
public async Task Should_add_context_when_provided() { // Arrange await using var ms = new MemoryStream(); await using var jsonWriter = new Utf8JsonWriter(ms); var fields = new Dictionary <string, object> { { "key", "value" } }; var tags = new MetricTags("tagkey", "tagvalue"); var timestamp = new DateTime(2017, 1, 1, 1, 1, 1, DateTimeKind.Utc); var point = new DatadogPoint("context", "measurement", fields, tags, new DefaultDatadogMetricJsonWriter(), FlushInterval, timestamp); // Act await point.Write(jsonWriter); await jsonWriter.FlushAsync(); var result = Encoding.UTF8.GetString(ms.ToArray()); // Assert result.Should().Be("{\"metric\":\"context.measurement.key\",\"points\":[[1483232461,0]],\"type\":\"gauge\",\"tags\":[\"tagkey:tagvalue\"]}", "Hosted Metrics request at the moment allow tags array but its not yet used."); }