Пример #1
0
        public void IsEnabled_WhenNewingupNewSpace_ShouldReturnTrue()
        {
            var sut = new MetricSpace("ss");

            var result = sut.IsEnabled();

            Assert.True(result);
        }
Пример #2
0
        public void IsEnabled_WhenDisabed_ShouldReturnFasle()
        {
            var sut = new MetricSpace("ss");

            sut.Disable();

            var result = sut.IsEnabled();

            Assert.False(result);
        }
Пример #3
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);
        }
Пример #4
0
        public void DataMeterActionConditionalTimeScope_WhenConditionIsFalse_ShouldNotSendExecutionTime()
        {
            var sut = new MetricSpace("s");

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

            sut.AddReporter(metricReporter);

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

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

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

            metricReporter.DidNotReceive().Report(Arg.Any <MetricInfo>());
        }
Пример #5
0
        public void MetricSpace_WhenReplcingKeyFormater_ShouldMatchPattern()
        {
            var space = new MetricSpace(Key1);

            space.Options.KeyFormater = new TestFormatter();

            var sut = space.Space(Key2);

            var metricInfo = new MetricInfo();

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

            var result = metricInfo.Key;

            Assert.Equal(TestFormatter.Key, result);
        }
Пример #6
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);
        }
Пример #7
0
        public void IsEnabled_WhenEnableAfterDisable_ShouldBeEnabled()
        {
            var sut = new MetricSpace("ss");

            sut.IsEnabled();

            AssertEnabled(sut);

            sut.Disable();

            AssertDisabled(sut);

            sut.Enable();

            AssertEnabled(sut);
        }
Пример #8
0
        public void DataMemberActionConditionalTimeScope_WhenConditionIsTrue_ShouldSendExecutionTime()
        {
            var sut = new MetricSpace("s");

            var recorder = new ReportsRecorder();

            sut.AddReporter(recorder);

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

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

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

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

            var testClock = new TestClock();

            sut.Options.SystemClock = testClock;

            var currentTime = new DateTime(2000, 1, 1);

            testClock.TestTime = currentTime;

            sut.Suspend(TimeSpan.FromHours(1));

            var result = sut.IsEnabled();

            Assert.False(result);
        }
Пример #10
0
        public void DateMeterTimeScope_WhenUsingTimeScope_ShouldSendExecutionTime()
        {
            var sut = new MetricSpace("s");

            var recorder = new ReportsRecorder();

            sut.AddReporter(recorder);

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

            meter.AddData("some-value", "value");

            using (meter.TimeScope(DurationKey))
            {
            }

            Assert.Contains(DurationKey, recorder.Last.Data.Keys);
            Assert.IsType <double>(recorder.Last.Data[DurationKey]);
        }
Пример #11
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]);
        }
Пример #12
0
        /// <summary>
        /// Convert an enum MetricSpace to it's corresponding MetricConstraint.
        /// </summary>
        /// <param name="metric"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static MetricConstraint.MetricConstraint Process(MetricSpace metric, CitySettings settings)
        {
            MetricConstraint.MetricConstraint m = null;

            switch (metric)
            {
            case MetricSpace.EUCLIDEAN:
                m = new EuclideanConstraint(settings);
                break;

            case MetricSpace.MANHATTAN:
                m = new ManhattanConstraint(settings);
                break;

            case MetricSpace.GRID:
                m = new GridConstraint(settings);
                break;
            }
            return(m);
        }
Пример #13
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]);
        }
Пример #14
0
        private void AssertDisabled(MetricSpace metricSpace)
        {
            var result = metricSpace.IsEnabled();

            Assert.False(result);
        }
Пример #15
0
        private void AssertEnabled(MetricSpace metricSpace)
        {
            var result = metricSpace.IsEnabled();

            Assert.True(result);
        }