public void IsEnabled_WhenNewingupNewSpace_ShouldReturnTrue() { var sut = new MetricSpace("ss"); var result = sut.IsEnabled(); Assert.True(result); }
public void IsEnabled_WhenDisabed_ShouldReturnFasle() { var sut = new MetricSpace("ss"); sut.Disable(); var result = sut.IsEnabled(); Assert.False(result); }
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); }
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>()); }
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); }
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); }
public void IsEnabled_WhenEnableAfterDisable_ShouldBeEnabled() { var sut = new MetricSpace("ss"); sut.IsEnabled(); AssertEnabled(sut); sut.Disable(); AssertDisabled(sut); sut.Enable(); AssertEnabled(sut); }
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]); }
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); }
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]); }
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]); }
/// <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); }
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]); }
private void AssertDisabled(MetricSpace metricSpace) { var result = metricSpace.IsEnabled(); Assert.False(result); }
private void AssertEnabled(MetricSpace metricSpace) { var result = metricSpace.IsEnabled(); Assert.True(result); }