Exemple #1
0
        public void Timestamps_must_be_UTC()
        {
            var writer = new LineProtocolWriter().Measurement("my_measurement").Field("value", 23);

            var ex = Assert.Throws <ArgumentException>(() => writer.Timestamp(DateTime.Now));

            Assert.Equal("Timestamps must be specified as UTC\r\nParameter name: value", ex.Message);
        }
        public void Will_throw_if_wrong_precision_used(Precision precision)
        {
            var writer = new LineProtocolWriter(precision);

            var timestamp = TimeSpan.FromTicks(1);

            writer.Measurement("foo").Field("bar", 1f);

            Assert.Throws <ArgumentOutOfRangeException>(() => writer.Timestamp(timestamp));
        }
        public void Cannot_write_tag_after_field_written()
        {
            var writer = new LineProtocolWriter();

            writer.Measurement("my_measurement").Field("value", 1);

            var ex = Assert.Throws <InvalidOperationException>(() => writer.Tag("foo", "bar"));

            Assert.Equal("Cannot write tag \"foo\" as field(s) already written for current line.", ex.Message);
            Assert.Equal("FieldWritten", ex.Data["Position"]);

            writer.Timestamp(123456);

            ex = Assert.Throws <InvalidOperationException>(() => writer.Tag("foo", "bar"));
            Assert.Equal("TimestampWritten", ex.Data["Position"]);
        }
        public void Cannot_write_timestamp_when_no_field_written()
        {
            var writer = new LineProtocolWriter();

            var ex = Assert.Throws <InvalidOperationException>(() => writer.Timestamp(123456));

            Assert.Equal("Cannot write timestamp as no measurement name written.", ex.Message);
            Assert.Equal("NothingWritten", ex.Data["Position"]);

            writer.Measurement("my_measurement");

            ex = Assert.Throws <InvalidOperationException>(() => writer.Timestamp(123456));
            Assert.Equal("Cannot write timestamp as no field written for current measurement.", ex.Message);
            Assert.Equal("MeasurementWritten", ex.Data["Position"]);

            writer.Tag("foo", "bar");

            ex = Assert.Throws <InvalidOperationException>(() => writer.Timestamp(123456));
            Assert.Equal("TagWritten", ex.Data["Position"]);

            Assert.Throws <InvalidOperationException>(() => writer.Timestamp(TimeSpan.FromDays(3045)));
            Assert.Throws <InvalidOperationException>(() => writer.Timestamp(DateTime.UtcNow));
            Assert.Throws <InvalidOperationException>(() => writer.Timestamp(DateTimeOffset.Now));
        }