public void APISavesToStorage()
        {
            Private.CounterMetricType counterMetric = new Private.CounterMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "counter_metric",
                sendInPings: new string[] { "store1" }
                );

            Assert.False(counterMetric.TestHasValue());

            // Add to the counter a couple of times with a little delay.  The first call will check
            // calling add() without parameters to test increment by 1.
            counterMetric.Add();

            // Check that the count was incremented and properly recorded.
            Assert.True(counterMetric.TestHasValue());
            Assert.Equal(1, counterMetric.TestGetValue());

            counterMetric.Add(10);
            // Check that count was incremented and properly recorded.  This second call will check
            // calling add() with 10 to test increment by other amount
            Assert.True(counterMetric.TestHasValue());
            Assert.Equal(11, counterMetric.TestGetValue());
        }
 public void TestGetValueThrows()
 {
     Private.CounterMetricType counterMetric = new Private.CounterMetricType(
         category: "telemetry",
         disabled: true,
         lifetime: Private.Lifetime.Application,
         name: "counter_metric",
         sendInPings: new string[] { "store1" }
         );
     Assert.Throws <NullReferenceException>(() => counterMetric.TestGetValue());
 }
        public void DisabledCountersMustNotRecordData()
        {
            Private.CounterMetricType counterMetric = new Private.CounterMetricType(
                category: "telemetry",
                disabled: true,
                lifetime: Private.Lifetime.Application,
                name: "counter_metric",
                sendInPings: new string[] { "store1" }
                );

            // Attempt to store the counter.
            counterMetric.Add();
            // Check that nothing was recorded.
            Assert.False(counterMetric.TestHasValue(), "Counters must not be recorded if they are disabled");
        }
        public void NegativeValuesAreNotCounted()
        {
            Private.CounterMetricType counterMetric = new Private.CounterMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Private.Lifetime.Application,
                name: "counter_metric",
                sendInPings: new string[] { "store1" }
                );

            // Increment to 1 (initial value)
            counterMetric.Add();

            // Check that the count was incremented
            Assert.True(counterMetric.TestHasValue("store1"));
            Assert.Equal(1, counterMetric.TestGetValue("store1"));

            counterMetric.Add(-10);
            // Check that count was NOT incremented.
            Assert.True(counterMetric.TestHasValue("store1"));
            Assert.Equal(1, counterMetric.TestGetValue("store1"));
            Assert.Equal(1, counterMetric.TestGetNumRecordedErrors(ErrorType.InvalidValue));
        }