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 HostedMetricsPoint(null, "measurement", fields, MetricTags.Empty, new DefaultHostedMetricsPointTextWriter(), FlushInterval, timestamp); // Act jsonWriter.WriteStartArray(); point.Write(jsonWriter); jsonWriter.WriteEndArray(); await jsonWriter.FlushAsync(); var result = Encoding.UTF8.GetString(ms.ToArray()); // Assert result.Should().Be("[{\"name\":\"measurement.field1key\",\"metric\":\"measurement.field1key\",\"value\":0,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]},{\"name\":\"measurement.field2key\",\"metric\":\"measurement.field2key\",\"value\":2,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]},{\"name\":\"measurement.field3key\",\"metric\":\"measurement.field3key\",\"value\":0,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]}]"); }
public void Can_format_payload_correctly() { // Arrange var sb = new StringBuilder(); var textWriter = new JsonTextWriter(new StringWriter(sb)); var fields = new Dictionary <string, object> { { "key", "value" } }; var timestamp = new DateTime(2017, 1, 1, 1, 1, 1, DateTimeKind.Utc); var point = new HostedMetricsPoint(null, "measurement", fields, MetricTags.Empty, new DefaultHostedMetricsPointTextWriter(), FlushInterval, timestamp); // Act point.Write(textWriter); var result = sb.ToString(); // Assert result.Should().Be("{\"name\":\"measurement.key\",\"metric\":\"measurement.key\",\"value\":0.0,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]}"); }
public void Should_add_context_when_provided() { // Arrange var sb = new StringBuilder(); var textWriter = new JsonTextWriter(new StringWriter(sb)); 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 HostedMetricsPoint("context", "measurement", fields, tags, new DefaultHostedMetricsPointTextWriter(), FlushInterval, timestamp); // Act point.Write(textWriter); var result = sb.ToString(); // Assert result.Should().Be("{\"name\":\"context.measurement.tagkey.tagvalue.key\",\"metric\":\"context.measurement.tagkey.tagvalue.key\",\"value\":0.0,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]}", "Hosted Metrics request at the moment allow tags array but its not yet used."); }
public void Can_format_payload_with_tags_correctly() { // Arrange var sb = new StringBuilder(); var textWriter = new JsonTextWriter(new StringWriter(sb)); 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 HostedMetricsPoint(null, "measurement", fields, tags, new DefaultHostedMetricsPointTextWriter(), timestamp); // Act point.Write(textWriter); var result = sb.ToString(); // Assert result.Should() .Be("[{\"name\":\"measurement.tagkey.tagvalue.key\",\"metric\":\"measurement.tagkey.tagvalue.key\",\"value\":\"value\",\"interval\":1,\"unit\":\"\",\"time\":\"1483232461\",\"tags\":[]}]", "Hosted Metrics request at the moment allow tags array but its not yet used."); }
public void Can_format_payload_with_multiple_fields_correctly() { // Arrange var sb = new StringBuilder(); var textWriter = new JsonTextWriter(new StringWriter(sb)); 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 HostedMetricsPoint(null, "measurement", fields, MetricTags.Empty, new DefaultHostedMetricsPointTextWriter(), timestamp); // Act point.Write(textWriter); var result = sb.ToString(); // Assert result.Should().Be("[{\"name\":\"measurement.field1key\",\"metric\":\"measurement.field1key\",\"value\":\"field1value\",\"interval\":1,\"unit\":\"\",\"time\":\"1483232461\",\"tags\":[]},{\"name\":\"measurement.field2key\",\"metric\":\"measurement.field2key\",\"value\":\"2\",\"interval\":1,\"unit\":\"\",\"time\":\"1483232461\",\"tags\":[]},{\"name\":\"measurement.field3key\",\"metric\":\"measurement.field3key\",\"value\":\"f\",\"interval\":1,\"unit\":\"\",\"time\":\"1483232461\",\"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 HostedMetricsPoint("context", "measurement", fields, tags, new DefaultHostedMetricsPointTextWriter(), FlushInterval, timestamp); // Act point.Write(jsonWriter); await jsonWriter.FlushAsync(); var result = Encoding.UTF8.GetString(ms.ToArray()); // Assert result.Should().Be("{\"name\":\"context.measurement.tagkey.tagvalue.key\",\"metric\":\"context.measurement.tagkey.tagvalue.key\",\"value\":0,\"interval\":10,\"mtype\":\"gauge\",\"unit\":\"\",\"time\":1483232461,\"tags\":[]}", "Hosted Metrics request at the moment allow tags array but its not yet used."); }