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");
        }
        public string Assert_that_metric_attribute_is_respected(string propertyName)
        {
            var fakeType     = typeof(MarkedUpFakeQueryType);
            var metricMapper = MetricMapper.TryCreate(fakeType.GetProperty(propertyName));

            return(metricMapper != null ? metricMapper.MetricName : null);
        }
        public void Assert_metric_units_are_stored_by_mapper()
        {
            var mapper = MetricMapper.TryCreate(typeof(FakeTypeWithUnits).GetProperty("RateOfSomething"));

            Assert.That(mapper, Is.Not.Null, "Mapping of FakeTypeWithUnits failed");
            Assert.That(mapper.MetricUnits, Is.EqualTo("[bytes/sec]"), "Units from MetricAttribute not mapped correctly");
        }
        public void Assert_try_create_mapper_gracefully_refuses_invalid_types(string propertyName)
        {
            var propertyInfo = typeof(FakeQueryType).GetProperty(propertyName);

            Assume.That(propertyInfo, Is.Not.Null, "Expected a property name '{0}' on {1}", propertyName, typeof(FakeQueryType).Name);

            var mapper = MetricMapper.TryCreate(propertyInfo);

            Assert.That(mapper, Is.Null, "Should not have mapped {0}", propertyName);
        }
        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);
        }
        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;
        }