public void InfluxBatch_FormatsTo_LineProtocol() { var testNow = new DateTime(2016, 6, 1, 0, 0, 0, DateTimeKind.Utc); var testTags = TagTestCases.Select(tc => tc.Tag); var testFields = FieldTestCases.Select(tc => tc.Field); var precision = InfluxConfig.Default.Precision; var expTime = InfluxLineProtocol.FormatTimestamp(testNow, precision); // test with empty batch InfluxBatch batch = new InfluxBatch(); batch.ToLineProtocol(precision).Should().BeEmpty(); // test with single record batch.Add(new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) })); batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(@"test_name,tag1=value1 field1=123456i"); batch.Clear(); // test with multiple records batch.Add(new InfluxRecord("test_name1", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) })); batch.Add(new InfluxRecord("test_name2", new[] { new InfluxTag("tag2", "value2") }, new[] { new InfluxField("field2", 234561) })); batch.Add(new InfluxRecord("test_name3", new[] { new InfluxTag("tag3", "value3") }, new[] { new InfluxField("field3", 345612) }, testNow)); batch.Add(new InfluxRecord("test_name4", new[] { new InfluxTag("tag4", "value4") }, new[] { new InfluxField("field4", 456123) }, testNow)); batch.Add(new InfluxRecord("test_name5", new[] { new InfluxTag("tag5", "value5") }, new[] { new InfluxField("field5", 561234) }, testNow)); String expOutput = String.Join("\n", $@"test_name1,tag1=value1 field1=123456i", $@"test_name2,tag2=value2 field2=234561i", $@"test_name3,tag3=value3 field3=345612i {expTime}", $@"test_name4,tag4=value4 field4=456123i {expTime}", $@"test_name5,tag5=value5 field5=561234i {expTime}" ); batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(expOutput); }
public void InfluxRecord_FormatsTo_LineProtocol() { // test values var testNow = new DateTime(2016, 6, 1, 0, 0, 0, DateTimeKind.Utc); var testTags = TagTestCases.Select(tc => tc.Tag); var testFields = FieldTestCases.Select(tc => tc.Field); var precision = InfluxConfig.Default.Precision; // expected values String expTime = InfluxLineProtocol.FormatTimestamp(testNow, precision); String expTags = String.Join(",", TagTestCases.Select(tc => tc.Output)); String expFields = String.Join(",", FieldTestCases.Select(tc => tc.Output)); String expOutput = String.Format("test_name,{0} {1} {2}", expTags, expFields, expTime); // assert line values match expected new InfluxRecord("name spaces", new[] { new InfluxField("field1", 123456) }) .ToLineProtocol(precision).Should().Be(@"name\ spaces field1=123456i"); new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) }) .ToLineProtocol(precision).Should().Be(@"test_name,tag1=value1 field1=123456i"); new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1"), new InfluxTag("tag2", "value2") }, new[] { new InfluxField("field1", 123456), new InfluxField("field2", true) }) .ToLineProtocol(precision).Should().Be(@"test_name,tag1=value1,tag2=value2 field1=123456i,field2=True"); new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", "test string") }, testNow) .ToLineProtocol(precision).Should().Be($@"test_name,tag1=value1 field1=""test string"" {expTime}"); new InfluxRecord("test_name", testTags, testFields, testNow) .ToLineProtocol(precision).Should().Be(expOutput); }