Ejemplo n.º 1
0
        public void Constructor_InitialisesProperties_MetricNameOnly()
        {
            var attr = new InstrumentAttribute("Test Metric Name");

            Assert.AreEqual("Test Metric Name", attr.MetricName);
            Assert.IsFalse(attr.IncludeCompilerGeneratedCode);
            Assert.IsFalse(attr.IncludeCompilerGeneratedCodeSet);
        }
Ejemplo n.º 2
0
        public void GetEffectiveInstrumentationContext_PrioritisesEarlierContextValues_ForScopesProperty()
        {
            var first = new InstrumentAttribute { Scopes = InstrumentationScopes.Methods };
            var second = new InstrumentAttribute { Scopes = InstrumentationScopes.Constructors };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second);

            Assert.AreEqual(InstrumentationScopes.Methods, effective.Scopes);
        }
Ejemplo n.º 3
0
        public void GetEffectiveInstrumentationContext_PrioritisesEarlierContextValues_ForMetricProperty()
        {
            var first = new InstrumentAttribute { Metric = Metric.Scoped };
            var second = new InstrumentAttribute { Metric = Metric.Both };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second);

            Assert.AreEqual(Metric.Scoped, effective.Metric);
        }
Ejemplo n.º 4
0
        public void GetEffectiveInstrumentationContext_PrioritisesEarlierContextValues_ForMetricNameProperty()
        {
            var first = new InstrumentAttribute { MetricName = "Metric name 1" };
            var second = new InstrumentAttribute { MetricName = "Metric name 2" };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second);

            Assert.AreEqual("Metric name 1", effective.MetricName);
        }
Ejemplo n.º 5
0
        public void GetEffectiveInstrumentationContext_PrioritisesEarlierContextValues_ForIncludeCompilerGeneratedCodeProperty()
        {
            var first = new InstrumentAttribute { IncludeCompilerGeneratedCode = true };
            var second = new InstrumentAttribute { IncludeCompilerGeneratedCode = false };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second);

            Assert.IsTrue(effective.IncludeCompilerGeneratedCode);
        }
Ejemplo n.º 6
0
        public void GetEffectiveInstrumentationContext_PrioritisesFirstNonNullContextValue_ForMetricNameProperty()
        {
            var first = new InstrumentAttribute { MetricName = null };
            var second = new InstrumentAttribute { MetricName = "Metric name 2" };
            var third = new InstrumentAttribute { MetricName = "Metric name 3" };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second, third);

            Assert.AreEqual("Metric name 2", effective.MetricName);
        }
Ejemplo n.º 7
0
        public void PropertiesTest()
        {
            var attr = new InstrumentAttribute() { Metric = Metric.Scoped, MetricName = "Test Metric Name", IncludeCompilerGeneratedCode = false };

            Assert.AreEqual(Metric.Scoped, attr.Metric);
            Assert.AreEqual("Test Metric Name", attr.MetricName);
            Assert.IsTrue(attr.IncludeCompilerGeneratedCodeSet);
            Assert.IsFalse(attr.IncludeCompilerGeneratedCode);

            attr.IncludeCompilerGeneratedCode = true;
            Assert.IsTrue(attr.IncludeCompilerGeneratedCodeSet);
            Assert.IsTrue(attr.IncludeCompilerGeneratedCode);
        }
Ejemplo n.º 8
0
        public void GetEffectiveInstrumentationContext_ReturnsContextEquivalentToSupplied_IfOnlyOneNonNullContextSuppliedWithNullsBefore()
        {
            var attr = new InstrumentAttribute { IncludeCompilerGeneratedCode = true, Metric = Metric.Scoped, MetricName = "Metric name", Scopes = InstrumentationScopes.All };
            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(null, null, attr);

            Assert.IsTrue(EqualityHelper.AreObjectsEquivalentByPublicProperties(attr, effective, false));
        }
Ejemplo n.º 9
0
        public void GetEffectiveInstrumentationContext_PrioritisesFirstSpecifiedContextValues_ForMetricProperty()
        {
            var first = new InstrumentAttribute { Metric = Metric.Unspecified };
            var second = new InstrumentAttribute { Metric = Metric.Both };
            var third = new InstrumentAttribute { Metric = Metric.Unscoped };

            var effective = InstrumentAttribute.GetEffectiveInstrumentationContext(first, second, third);

            Assert.AreEqual(Metric.Both, effective.Metric);
        }
 protected virtual InstrumentationTarget GetInstrumentationTarget(IMethodDetails method, InstrumentAttribute context)
 {
     return(new InstrumentationTarget(method, context.MetricName, context.Name, context.TransactionNamingPriority, context.Metric));
 }
        public virtual IEnumerable <InstrumentationTarget> GetInstrumentationSet(string assemblyPath, InstrumentAttribute context, Predicate <ITypeDetails> typeFilter)
        {
            var toReturn = new List <InstrumentationTarget>();

            _logger.InfoFormat("Processing assembly {0}", assemblyPath);

            if (typeFilter == null)
            {
                typeFilter = x => true;
            }

            var allTypes = this.GetTypes(assemblyPath).Where(x => x.IsClass && !x.IsNested && typeFilter(x));

            _logger.DebugFormat("Found {0} types", allTypes.Count());

            InstrumentAttribute assyContext = null;

            if (allTypes.Any())
            {
                assyContext = allTypes.First().Assembly.InstrumentationContext;
            }

            foreach (var t in allTypes)
            {
                toReturn.AddRange(GetInstrumentationSet(t, InstrumentAttribute.GetEffectiveInstrumentationContext(assyContext, context)));
            }

            return(toReturn);
        }