Exemple #1
0
        public void CanGetMetricQueryResult()
        {
            var metadata = new Dictionary <string, string> {
                { "metadatatest1", "metadatatest2" }
            };
            var metricValue     = MonitorQueryModelFactory.MetricValue(new DateTimeOffset(new DateTime(10)));
            var metricValueList = new List <MetricValue>()
            {
                metricValue
            };
            MetricTimeSeriesElement metricTimeSeriesElement = MonitorQueryModelFactory.MetricTimeSeriesElement(metadata, metricValueList);

            Assert.IsNotNull(metricTimeSeriesElement);
            Assert.AreEqual(1, metricTimeSeriesElement.Metadata.Count);
            var firstElement = metricTimeSeriesElement.Metadata.First();

            Assert.AreEqual("metadatatest1", firstElement.Key);
            Assert.AreEqual("metadatatest2", firstElement.Value);
            Assert.AreEqual(1, metricTimeSeriesElement.Values.Count);
            Assert.AreEqual(new DateTimeOffset(new DateTime(10)), metricTimeSeriesElement.Values[0].TimeStamp);
            IEnumerable <MetricTimeSeriesElement> metricTimeSeriesElements = new[] { metricTimeSeriesElement };

            MetricUnit metricUnit = new MetricUnit("test");

            Assert.IsNotNull(metricUnit);
            Assert.AreEqual("test", metricUnit.ToString());

            MetricResult metricResult = MonitorQueryModelFactory.MetricResult("https://management.azure.gov", "type", "name", metricUnit, metricTimeSeriesElements);

            Assert.IsNotNull(metricResult);
            Assert.AreEqual(null, metricResult.Description);
            Assert.AreEqual(null, metricResult.Error.Code);
            Assert.AreEqual(null, metricResult.Error.Message);
            Assert.AreEqual("https://management.azure.gov", metricResult.Id);
            Assert.AreEqual("name", metricResult.Name);
            Assert.AreEqual("type", metricResult.ResourceType);
            Assert.AreEqual(1, metricResult.TimeSeries.Count);
            Assert.AreEqual("test", metricResult.Unit.ToString());
            IEnumerable <MetricResult> metricResults = new[] { metricResult };

            MetricsQueryResult metricsQueryResult = MonitorQueryModelFactory.MetricsQueryResult(null, TimeSpan.FromMinutes(3).ToString(), null, "namespace", "eastus", metricResults.ToList());

            Assert.AreEqual(null, metricsQueryResult.Cost);
            Assert.AreEqual(null, metricsQueryResult.Granularity);
            Assert.AreEqual(1, metricsQueryResult.Metrics.Count);
            Assert.AreEqual(null, metricsQueryResult.Metrics[0].Description);
            Assert.AreEqual(null, metricsQueryResult.Metrics[0].Error.Code);
            Assert.AreEqual(null, metricsQueryResult.Metrics[0].Error.Message);
            Assert.AreEqual("https://management.azure.gov", metricsQueryResult.Metrics[0].Id);
            Assert.AreEqual("name", metricsQueryResult.Metrics[0].Name);
            Assert.AreEqual("type", metricsQueryResult.Metrics[0].ResourceType);
            Assert.AreEqual("namespace", metricsQueryResult.Namespace);
            Assert.AreEqual("eastus", metricsQueryResult.ResourceRegion);
            Assert.IsNotNull(metricsQueryResult);
        }
Exemple #2
0
        /// <summary>
        /// New Metric Weight measurement from <paramref name="value"/> in <paramref name="unit"/>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="unit"></param>
        public MetricWeight(double value, MetricUnit unit)
        {
            _picograms = _nanograms = _micrograms = _milligrams = _grams = _kilograms = _megagrams = 0;

            switch (unit)
            {
            case MetricUnit.Grams:
            {
                BaseValue = value;
                break;
            }

            case MetricUnit.Kilogram:
            {
                Kilograms = value;
                break;
            }

            case MetricUnit.Megagram:
            case MetricUnit.Tonne:
            {
                Megagrams = value;
                break;
            }

            case MetricUnit.Microgram:
            {
                Micrograms = value;
                break;
            }

            case MetricUnit.Milligram:
            {
                Milligrams = value;
                break;
            }

            case MetricUnit.Nanogram:
            {
                Nanograms = value;
                break;
            }

            case MetricUnit.Picogram:
            {
                Picograms = value;
                break;
            }

            default:
            {
                throw new UnknownConversionException($"IoT Library Exception! Someone forgot to add '{unit.ToString()}' to the constructor!");
            }
            }
        }