public void GetDimensionValuesValidatesArguments()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            Assert.That(() => client.GetDimensionValuesAsync(null, "dimensionName"), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValuesAsync("", "dimensionName"), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetDimensionValuesAsync("metricId", null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValuesAsync("metricId", ""), Throws.InstanceOf <ArgumentException>());

            Assert.That(() => client.GetDimensionValues(null, "dimensionName"), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValues("", "dimensionName"), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetDimensionValues("metricId", null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValues("metricId", ""), Throws.InstanceOf <ArgumentException>());
        }
Beispiel #2
0
        public async Task GetDimensionValuesWithOptionalDimensionFilter()
        {
            const string dimensionName = "city";
            const string filter        = "ba";

            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            var options = new GetDimensionValuesOptions()
            {
                DimensionValueToFilter = filter
            };

            var valueCount = 0;

            await foreach (string value in client.GetDimensionValuesAsync(MetricId, dimensionName, options))
            {
                Assert.That(value, Is.Not.Null.And.Not.Empty);
                Assert.That(value.ToLowerInvariant().Contains(filter));

                if (++valueCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(valueCount, Is.GreaterThan(0));
        }
Beispiel #3
0
        public void GetDimensionValuesValidatesArguments()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            Assert.That(() => client.GetDimensionValuesAsync(null, "dimensionName"), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValuesAsync("", "dimensionName"), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetDimensionValuesAsync("metricId", "dimensionName"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
            Assert.That(() => client.GetDimensionValuesAsync(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValuesAsync(FakeGuid, ""), Throws.InstanceOf <ArgumentException>());

            Assert.That(() => client.GetDimensionValues(null, "dimensionName"), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValues("", "dimensionName"), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetDimensionValues("metricId", "dimensionName"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
            Assert.That(() => client.GetDimensionValues(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetDimensionValues(FakeGuid, ""), Throws.InstanceOf <ArgumentException>());
        }
        public async Task GetDimensionValuesAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var client = new MetricsAdvisorClient(new Uri(endpoint), credential);

            string metricId = MetricId;

            string dimensionName = "city";
            var    options       = new GetDimensionValuesOptions()
            {
                TopCount = 10
            };

            Console.WriteLine($"The dimension '{dimensionName}' can assume the following values (limited to 10):");

            int dimensionValueCount = 0;

            await foreach (string dimensionValue in client.GetDimensionValuesAsync(metricId, dimensionName, options))
            {
                Console.WriteLine($"  {dimensionValue}");

                // Print at most 10 values.
                if (++dimensionValueCount >= 10)
                {
                    break;
                }
            }
        }
Beispiel #5
0
        public void GetDimensionValuesRespectsTheCancellationToken()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            IAsyncEnumerator <string> asyncEnumerator = client.GetDimensionValuesAsync(FakeGuid, "dimensionName", cancellationToken: cancellationSource.Token).GetAsyncEnumerator();

            Assert.That(async() => await asyncEnumerator.MoveNextAsync(), Throws.InstanceOf <OperationCanceledException>());

            IEnumerator <string> enumerator = client.GetDimensionValues(FakeGuid, "dimensionName", cancellationToken: cancellationSource.Token).GetEnumerator();

            Assert.That(() => enumerator.MoveNext(), Throws.InstanceOf <OperationCanceledException>());
        }
Beispiel #6
0
        public async Task GetDimensionValuesWithMinimumSetup(bool useTokenCredential)
        {
            const string dimensionName = "city";

            MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);

            var valueCount = 0;

            await foreach (string value in client.GetDimensionValuesAsync(MetricId, dimensionName))
            {
                Assert.That(value, Is.Not.Null.And.Not.Empty);

                if (++valueCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(valueCount, Is.GreaterThan(0));
        }