Example #1
0
        public void CountShouldNotUpdateMetricIfDeltaIsLessOrEqualThanZero()
        {
            //Arrange
            var counters   = new ConcurrentDictionary <string, Counter>();
            var cache      = new InMemoryMetricsCache(counters);
            var metricsLog = new InMemoryMetricsLog(null, cache);

            //Act
            metricsLog.Count("counter_test", 0);
            metricsLog.Count("counter_test", -1);

            //Assert
            Counter counter = cache.GetCount("counter_test");

            Assert.IsNull(counter);
        }
Example #2
0
        public void CountShouldUpdateMetricWhenExisting()
        {
            //Arrange
            var counters   = new ConcurrentDictionary <string, Counter>();
            var cache      = new InMemoryMetricsCache(counters);
            var metricsLog = new InMemoryMetricsLog(null, cache);

            //Act
            metricsLog.Count("counter_test", 150);
            metricsLog.Count("counter_test", 10);

            //Assert
            Counter counter = cache.GetCount("counter_test");

            Assert.AreEqual(2, counter.GetCount());
            Assert.AreEqual(160, counter.GetDelta());
        }
Example #3
0
        public void SendCountMetricsSuccessfully()
        {
            //Arrange
            var counters             = new ConcurrentDictionary <string, Counter>();
            var metricsApiClientMock = new Mock <IMetricsSdkApiClient>();
            var cache      = new InMemoryMetricsCache(counters);
            var metricsLog = new InMemoryMetricsLog(metricsApiClientMock.Object, cache, 1);

            //Act
            metricsLog.Count("counter_test", 150);

            //Assert
            metricsApiClientMock.Verify(x => x.SendCountMetrics(It.IsAny <string>()));
        }
Example #4
0
        public void CountShouldNotAddMetricIfNoNameSpecified()
        {
            //Arrange
            var counters   = new ConcurrentDictionary <string, Counter>();
            var cache      = new InMemoryMetricsCache(counters);
            var metricsLog = new InMemoryMetricsLog(null, cache);

            //Act
            metricsLog.Count("", 1);

            //Assert
            Counter counter = cache.GetCount("");

            Assert.IsNull(counter);
        }