private static void ConvertToValueMetric(QueryContext queryContext, string metricName, PropertyInfo propertyInfo, object result)
 {
     // If the query result is a bigint, an exception is thrown when attempting to make it an decimal.
     var potentiallyLargeValue = Convert.ToInt64(propertyInfo.GetValue(result, null));
     if (potentiallyLargeValue >= decimal.MaxValue)
     {
         // Best we can do when the value is > decimal.MaxValue
         queryContext.AddMetric(metricName, decimal.MaxValue);
     }
     else
     {
         var value = Convert.ToDecimal(potentiallyLargeValue);
         queryContext.AddMetric(metricName, value);
     }
 }
 private static void AddValueMetric(QueryContext queryContext, string metricName, PropertyInfo propertyInfo, object result)
 {
     queryContext.AddMetric(metricName, (decimal) propertyInfo.GetValue(result, null));
 }
 public void AddMetric(QueryContext queryContext, object result)
 {
     var metricName = queryContext.FormatMetricKey(result, MetricName, MetricUnits);
     _metricSetter(queryContext, metricName, _propertyInfo, result);
 }
 public void AddMetrics(QueryContext context)
 {
     context.Results.ForEach(r => _metricMappers.ForEach(m => m.AddMetric(context, r)));
 }
        private static ComponentData CreateComponentDataForFake(object fake, string propertyName)
        {
            var componentData = new ComponentData();

            var query = new SqlQuery(fake.GetType(), new SqlServerQueryAttribute(null, "Fake"), null, "");
            var queryContext = new QueryContext(query) {ComponentData = componentData,};

            var metricMapper = new MetricMapper(fake.GetType().GetProperty(propertyName));

            metricMapper.AddMetric(queryContext, fake);
            return componentData;
        }
        public void Assert_try_create_mapper_handles_decimal_correctly()
        {
            var fake = new FakeQueryType {Decimal = 12.3m};

            var componentData = new ComponentData();

            var query = new SqlQuery(fake.GetType(), new SqlServerQueryAttribute(null, "Fake"), null, "");
            var queryContext = new QueryContext(query) {ComponentData = componentData,};

            var mapper = MetricMapper.TryCreate(fake.GetType().GetProperty("Decimal"));
            Assert.That(mapper, Is.Not.Null, "Mapping Decimal failed");

            mapper.AddMetric(queryContext, fake);

            const string metricKey = "Fake/Decimal";
            Assert.That(componentData.Metrics.ContainsKey(metricKey), "Expected metric with correct name to be added");

            var condition = componentData.Metrics[metricKey];
            Assert.That(condition, Is.EqualTo(fake.Decimal), "Metric not mapped correctly");
        }