Esempio n. 1
0
        public void APISavesToSecondaryPings()
        {
            // Define a 'datetimeMetric' datetime metric, which will be stored in "store1" and "store2"
            var datetimeMetric = new Private.DatetimeMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "datetime_metric",
                sendInPings: new string[] { "store1", "store2" },
                timeUnit: TimeUnit.Second
                );

            const string displayName  = "(UTC-06:00) Central Time (US & Canada)";
            const string standardName = "Central Standard Time";
            var          offset       = new TimeSpan(-06, 00, 00);
            var          timeZone     = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName);
            var          value        = new DateTimeOffset(2010, 11, 29, 18, 3, 35, timeZone.BaseUtcOffset);

            datetimeMetric.Set(value);

            // Check that data was properly recorded.
            Assert.True(datetimeMetric.TestHasValue("store1"));
            Assert.Equal(value, datetimeMetric.TestGetValue("store1"));
            Assert.True(datetimeMetric.TestHasValue("store2"));
            Assert.Equal(value, datetimeMetric.TestGetValue("store2"));
        }
Esempio n. 2
0
        public void SettingDateAndReadingResultsInTheSame()
        {
            var datetimeMetric = new Private.DatetimeMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "datetime_metric",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Millisecond
                );

            var unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            var now       = new DateTime(DateTime.Now.Ticks);

            datetimeMetric.Set(now);
            Assert.Equal(Math.Floor((now.ToUniversalTime() - unixStart).TotalSeconds),
                         datetimeMetric.TestGetValue().ToUnixTimeSeconds());
        }