public void TryGetValueValidatesArguments() { var dimensions = new Dictionary <string, string>(); var dimensionKey = new DimensionKey(dimensions); Assert.That(() => dimensionKey.TryGetValue(null, out var _), Throws.ArgumentNullException); Assert.That(() => dimensionKey.TryGetValue("", out var _), Throws.ArgumentException); }
protected void ValidateTempDataFeedDimensionKey(DimensionKey dimensionKey, string expectedDimensionA, string expectedDimensionB) { Assert.That(dimensionKey, Is.Not.Null); Assert.That(Count(dimensionKey), Is.EqualTo(2)); Assert.That(dimensionKey.TryGetValue(TempDataFeedDimensionNameA, out string dimensionA)); Assert.That(dimensionKey.TryGetValue(TempDataFeedDimensionNameB, out string dimensionB)); Assert.That(dimensionA, Is.EqualTo(expectedDimensionA)); Assert.That(dimensionB, Is.EqualTo(expectedDimensionB)); }
protected void ValidateSeriesKey(DimensionKey seriesKey) { Assert.That(seriesKey, Is.Not.Null); Assert.That(Count(seriesKey), Is.EqualTo(2)); Assert.That(seriesKey.TryGetValue("city", out string city)); Assert.That(seriesKey.TryGetValue("category", out string category)); Assert.That(city, Is.Not.Null.And.Not.Empty); Assert.That(category, Is.Not.Null.And.Not.Empty); }
protected void ValidateSeriesKey(DimensionKey seriesKey) { Assert.That(seriesKey, Is.Not.Null); Assert.That(Count(seriesKey), Is.EqualTo(2)); Assert.That(seriesKey.TryGetValue("Dim1", out string dim1)); Assert.That(seriesKey.TryGetValue("Dim2", out string dim2)); Assert.That(dim1, Is.Not.Null.And.Not.Empty); Assert.That(dim2, Is.Not.Null.And.Not.Empty); }
public void TryGetValueGetsValues() { var dimensions = new Dictionary <string, string>() { { "name1", "value1" }, { "name2", "value2" } }; var dimensionKey = new DimensionKey(dimensions); Assert.That(dimensionKey.TryGetValue("name1", out string value1)); Assert.That(dimensionKey.TryGetValue("name2", out string value2)); Assert.That(value1, Is.EqualTo("value1")); Assert.That(value2, Is.EqualTo("value2")); }
public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter() { var cityFilter = new List <string>() { "Belo Horizonte", "Chennai", "Hong Kong" }; var categoryFilter = new List <string>() { "__SUM__", "Outdoors" }; MetricsAdvisorClient client = GetMetricsAdvisorClient(); var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime); options.DimensionCombinationsFilter.Add("city", cityFilter); options.DimensionCombinationsFilter.Add("category", categoryFilter); var definitionCount = 0; await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options)) { Assert.That(definition, Is.Not.Null); Assert.That(definition.MetricId, Is.EqualTo(MetricId)); ValidateSeriesKey(definition.SeriesKey); DimensionKey seriesKey = definition.SeriesKey; Assert.That(seriesKey.TryGetValue("city", out string city)); Assert.That(seriesKey.TryGetValue("category", out string category)); Assert.That(cityFilter.Contains(city)); Assert.That(categoryFilter.Contains(category)); if (++definitionCount >= MaximumSamplesCount) { break; } } Assert.That(definitionCount, Is.GreaterThan(0)); }
public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter() { var dim1Filter = new List <string>() { "JPN", "USD", "__SUM__" }; var dim2Filter = new List <string>() { "JP", "US" }; MetricsAdvisorClient client = GetMetricsAdvisorClient(); var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime); options.DimensionCombinationsFilter.Add("Dim1", dim1Filter); options.DimensionCombinationsFilter.Add("Dim2", dim2Filter); var definitionCount = 0; await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options)) { Assert.That(definition, Is.Not.Null); Assert.That(definition.MetricId, Is.EqualTo(MetricId)); ValidateSeriesKey(definition.SeriesKey); DimensionKey seriesKey = definition.SeriesKey; Assert.That(seriesKey.TryGetValue("Dim1", out string region)); Assert.That(seriesKey.TryGetValue("Dim2", out string category)); Assert.That(dim1Filter.Contains(region)); Assert.That(dim2Filter.Contains(category)); if (++definitionCount >= MaximumSamplesCount) { break; } } Assert.That(definitionCount, Is.GreaterThan(0)); }
public void TryGetValueReturnsFalseForMissingValue() { var dimensions = new Dictionary <string, string>() { { "name", "value" } }; var dimensionKey = new DimensionKey(dimensions); Assert.That(dimensionKey.TryGetValue("otherName", out string value), Is.False); Assert.That(value, Is.Null); }
private void ValidateMetricFeedback(MetricFeedback feedback) { Assert.That(feedback, Is.Not.Null); Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty); Assert.That(feedback.MetricId, Is.EqualTo(MetricId)); Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty); DateTimeOffset justNow = Recording.UtcNow.Subtract(TimeSpan.FromMinutes(5)); Assert.That(feedback.CreatedOn, Is.GreaterThan(justNow)); Assert.That(feedback.DimensionFilter, Is.Not.Null); DimensionKey dimensionFilter = feedback.DimensionFilter.DimensionKey; Assert.That(dimensionFilter, Is.Not.Null); Assert.That(Count(dimensionFilter), Is.EqualTo(2)); Assert.That(dimensionFilter.TryGetValue("region", out string region)); Assert.That(dimensionFilter.TryGetValue("category", out string category)); Assert.That(region, Is.EqualTo(ExpectedRegion)); Assert.That(category, Is.EqualTo(ExpectedCategory)); }
private bool AreSame(DimensionKey left, DimensionKey right) { if (left.Dimension.Count != right.Dimension.Count) { return(false); } foreach (KeyValuePair <string, string> kvp in left) { if (!right.TryGetValue(kvp.Key, out string value) || value != kvp.Value) { return(false); } } return(true); }
public async Task GetAllFeedbackWithOptionalFeedbackFilter() { MetricsAdvisorClient client = GetMetricsAdvisorClient(); // The sampling time range was chosen in a way to make sure there'll be feedback returned by the // service call. Changing these values can make this test fail. DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2021-10-01T00:00:00Z"); DateTimeOffset feedbackSamplingEndTime = DateTimeOffset.Parse("2021-11-20T00:00:00Z"); var dimensions = new Dictionary <string, string>() { { "region", "Karachi" } }; var options = new GetAllFeedbackOptions() { Filter = new FeedbackFilter() { DimensionKey = new DimensionKey(dimensions), TimeMode = FeedbackQueryTimeMode.FeedbackCreatedOn, StartsOn = feedbackSamplingStartTime, EndsOn = feedbackSamplingEndTime, FeedbackKind = MetricFeedbackKind.Anomaly } }; var feedbackCount = 0; await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(MetricId, options)) { Assert.That(feedback, Is.Not.Null); Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty); Assert.That(feedback.MetricId, Is.EqualTo(MetricId)); Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty); Assert.That(feedback.CreatedOn, Is.Not.Null); Assert.That(feedback.CreatedOn, Is.GreaterThanOrEqualTo(feedbackSamplingStartTime)); Assert.That(feedback.CreatedOn, Is.LessThanOrEqualTo(feedbackSamplingEndTime)); Assert.That(feedback.DimensionFilter, Is.Not.Null); DimensionKey dimensionKeyFilter = feedback.DimensionFilter.DimensionKey; Assert.That(dimensionKeyFilter, Is.Not.Null); ValidateGroupKey(dimensionKeyFilter); Assert.That(dimensionKeyFilter.TryGetValue("region", out string region)); Assert.That(region, Is.EqualTo("Karachi")); Assert.That(feedback.FeedbackKind, Is.EqualTo(MetricFeedbackKind.Anomaly)); var anomalyFeedback = feedback as MetricAnomalyFeedback; Assert.That(anomalyFeedback, Is.Not.Null); Assert.That(anomalyFeedback.AnomalyValue, Is.Not.EqualTo(default(AnomalyValue))); if (++feedbackCount >= MaximumSamplesCount) { break; } } Assert.That(feedbackCount, Is.GreaterThan(0)); }