예제 #1
0
        public void APISavesToStorageBySettingThenAdding()
        {
            // Define a 'stringListMetric' string list metric, which will be stored in "store1".
            var stringListMetric = new Private.StringListMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "string_list_metric",
                sendInPings: new string[] { "store1" }
                );

            // Record two lists using set and add.
            stringListMetric.Set(new string[] { "value1", "value2", "value3" });

            // Check that data was properly recorded.
            var snapshot = stringListMetric.TestGetValue();

            Assert.Equal(3, snapshot.Length);
            Assert.True(stringListMetric.TestHasValue());
            Assert.Equal("value1", snapshot[0]);
            Assert.Equal("value2", snapshot[1]);
            Assert.Equal("value3", snapshot[2]);

            // Use Add() to see that the list is appended to.
            stringListMetric.Add("added1");
            // Check that data was properly recorded.
            var snapshot2 = stringListMetric.TestGetValue();

            Assert.Equal(4, snapshot2.Length);
            Assert.True(stringListMetric.TestHasValue());
            Assert.Equal("value1", snapshot2[0]);
            Assert.Equal("value2", snapshot2[1]);
            Assert.Equal("value3", snapshot2[2]);
            Assert.Equal("added1", snapshot2[3]);
        }
예제 #2
0
        public void TestGetValueThrows()
        {
            var stringListMetric = new Private.StringListMetricType(
                disabled: true,
                category: "telemetry",
                lifetime: Private.Lifetime.Application,
                name: "string_list_metric",
                sendInPings: new string[] { "store1" }
                );

            Assert.Throws <NullReferenceException>(() => stringListMetric.TestGetValue());
        }
예제 #3
0
        public void APISavesToSecondaryPings()
        {
            // Define a 'stringListMetric' string list metric, which will be stored in "store1".
            var stringListMetric = new Private.StringListMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "string_list_metric",
                sendInPings: new string[] { "store1", "store2" }
                );

            // Record two lists using Add() and Set().
            stringListMetric.Add("value1");
            stringListMetric.Add("value2");
            stringListMetric.Add("value3");

            // Check that data was properly recorded in the second ping.
            Assert.True(stringListMetric.TestHasValue("store2"));
            var snapshot = stringListMetric.TestGetValue("store2");

            Assert.Equal(3, snapshot.Length);
            Assert.Equal("value1", snapshot[0]);
            Assert.Equal("value2", snapshot[1]);
            Assert.Equal("value3", snapshot[2]);

            // Use Set() to see that the first list is replaced by the new list.
            stringListMetric.Set(new string[] { "other1", "other2", "other3" });
            // Check that data was properly recorded in the second ping.
            Assert.True(stringListMetric.TestHasValue("store2"));
            var snapshot2 = stringListMetric.TestGetValue("store2");

            Assert.Equal(3, snapshot2.Length);
            Assert.Equal("other1", snapshot2[0]);
            Assert.Equal("other2", snapshot2[1]);
            Assert.Equal("other3", snapshot2[2]);
        }
예제 #4
0
        public void LongStringListsAreTruncated()
        {
            // Define a 'stringListMetric' string list metric, which will be stored in "store1".
            var stringListMetric = new Private.StringListMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Private.Lifetime.Application,
                name: "string_list_metric",
                sendInPings: new string[] { "store1" }
                );

            for (int x = 0; x <= 20; x++)
            {
                stringListMetric.Add("value" + x);
            }

            var snapshot = stringListMetric.TestGetValue("store1");

            Assert.Equal(20, snapshot.Length);

            Assert.Equal(1, stringListMetric.TestGetNumRecordedErrors(ErrorType.InvalidValue));
        }