Пример #1
0
        public void MetricSpace_WhenCombiningKeys_ShouldMatchPattern()
        {
            var sut = new MetricSpace(Key1);

            var metricInfo = new MetricInfo();

            sut.Meter(Key2).Send(metricInfo);

            var result = metricInfo.Key;

            Assert.Equal($"{Key1}.{Key2}", result);
        }
Пример #2
0
        public void MetricSpace_WhenUsingDifferntDelimiter_ShouldMatchPattern()
        {
            const string delimiter = ";";

            var sut = new MetricSpace(Key1);

            sut.Options.KeysDelimiter = delimiter;

            var metricInfo = new MetricInfo();

            sut.Meter(Key2).Send(metricInfo);

            var result = metricInfo.Key;

            Assert.Equal($"{Key1}{delimiter}{Key2}", result);
        }
Пример #3
0
        public void ActionConditionalTimeScope_WhenConditionIsFalse_ShouldNotSendExecutionTime()
        {
            var sut = new MetricSpace("s");

            var metricReporter = Substitute.For <IMetricReporter>();

            sut.AddReporter(metricReporter);

            var meter = sut.Meter("x");

            var info = new MetricInfo();

            info.Data.Add("some-value", "value");

            meter.ConditionalTimeScope(info, () => { }, () => false, DurationKey);

            metricReporter.DidNotReceive().Report(Arg.Any <MetricInfo>());
        }
Пример #4
0
        public void TimeScope_WhenUsingTimeScopeAction_ShouldSendExecutionTime()
        {
            var sut = new MetricSpace("s");

            var recorder = new ReportsRecorder();

            sut.AddReporter(recorder);

            var meter = sut.Meter("x");

            var info = new MetricInfo();

            info.Data.Add("some-value", "value");

            meter.TimeScope(info, () => { }, DurationKey);

            Assert.Contains(DurationKey, recorder.Last.Data.Keys);
            Assert.IsType <TimeSpan>(recorder.Last.Data[DurationKey]);
        }
Пример #5
0
        public void ConditionalTimeScope_WhenConditionIsTrue_ShouldSendExecutionTime()
        {
            var sut = new MetricSpace("s");

            var recorder = new ReportsRecorder();

            sut.AddReporter(recorder);

            var meter = sut.Meter("x");

            var info = new MetricInfo();

            info.Data.Add("some-value", "value");

            using (meter.ConditionalTimeScope(info, () => true, DurationKey))
            {
            }

            Assert.Contains(DurationKey, recorder.Last.Data.Keys);
            Assert.IsType <TimeSpan>(recorder.Last.Data[DurationKey]);
        }