Exemple #1
0
        public void AddMetricsToEngine_OneUnscopedMetricNull()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", null,
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));

            Assert.That(metric1, Is.Not.Null);
            var data = metric1.Data;

            Assert.NotNull(data);
            Assert.AreEqual(1, data.Value0);
            Assert.AreEqual(3, data.Value1);
            Assert.AreEqual(2, data.Value2);

            var engine = new MetricStatsCollection();

            metric1.AddMetricsToEngine(engine);

            var stats = engine.ConvertToJsonForSending(_metricNameService);

            foreach (var current in stats)
            {
                Assert.AreEqual("DotNet/name", current.MetricName.Name);
                Assert.AreEqual(null, current.MetricName.Scope);
                var myData = current.Data;
                Assert.AreEqual(1, myData.Value0);
                Assert.AreEqual(3, myData.Value1);
                Assert.AreEqual(2, myData.Value2);
            }
        }
Exemple #2
0
        public void AddMetricsToEngine_OneScopedMetric()
        {
            var metric1 = MetricWireModel.BuildMetric(_metricNameService, "DotNet/name", "scope",
                                                      MetricDataWireModel.BuildTimingData(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2)));

            Assert.That(metric1, Is.Not.Null);
            var data = metric1.Data;

            Assert.NotNull(data);
            Assert.AreEqual(1, data.Value0);
            Assert.AreEqual(3, data.Value1);
            Assert.AreEqual(2, data.Value2);

            var engine = new MetricStatsCollection();

            metric1.AddMetricsToEngine(engine);

            var actual        = engine.ConvertToJsonForSending(_metricNameService);
            var unscopedCount = 0;
            var scopedCount   = 0;
            var theScope      = string.Empty;
            var metricName    = string.Empty;
            MetricDataWireModel scopedData = null;

            foreach (var current in actual)
            {
                if (current.MetricName.Scope == null)
                {
                    unscopedCount++;
                }
                else
                {
                    scopedCount++;
                    theScope   = current.MetricName.Scope;
                    metricName = current.MetricName.Name;
                    scopedData = current.Data;
                }
            }

            Assert.AreEqual(1, scopedCount);
            Assert.AreEqual(0, unscopedCount);
            Assert.AreEqual("scope", theScope);
            Assert.AreEqual("DotNet/name", metricName);
            Assert.IsNotNull(scopedData);
            Assert.AreEqual(1, scopedData.Value0);
            Assert.AreEqual(3, scopedData.Value1);
            Assert.AreEqual(2, scopedData.Value2);
        }