Example #1
0
 public T GetErrorTraceAttribute <T>(string transactionName, TransactionTraceAttributeType attributeType, string parameterName)
 {
     return(GetErrorTraces()
            .Where(trace => trace != null)
            .Where(trace => trace.Path == transactionName || transactionName == null)
            .Where(trace => trace.Attributes != null)
            .Select(trace => trace.Attributes)
            .SelectMany(attributes => FilterAttributesByType(attributes, attributeType))
            .Where(pair => pair.Key == parameterName)
            .Select(pair => pair.Value)
            .OfType <T>()
            .FirstOrDefault());
 }
        public IDictionary <string, object> GetByType(TransactionTraceAttributeType attributeType)
        {
            IDictionary <string, object> attributes;

            switch (attributeType)
            {
            case TransactionTraceAttributeType.Intrinsic:
                attributes = IntrinsicAttributes;
                break;

            case TransactionTraceAttributeType.Agent:
                attributes = AgentAttributes;
                break;

            case TransactionTraceAttributeType.User:
                attributes = UserAttributes;
                break;

            default:
                throw new NotImplementedException();
            }

            return(attributes ?? new Dictionary <string, object>());
        }
Example #3
0
        private static IEnumerable <KeyValuePair <string, object> > FilterAttributesByType(ErrorTraceAttributes attributesCollection, TransactionTraceAttributeType attributeType)
        {
            if (attributesCollection == null)
            {
                return(new Dictionary <string, object>());
            }

            IDictionary <string, object> attributes;

            switch (attributeType)
            {
            case TransactionTraceAttributeType.Intrinsic:
                attributes = attributesCollection.IntrinsicAttributes;
                break;

            case TransactionTraceAttributeType.Agent:
                attributes = attributesCollection.AgentAttributes;
                break;

            case TransactionTraceAttributeType.User:
                attributes = attributesCollection.UserAttributes;
                break;

            default:
                throw new NotImplementedException();
            }

            return(attributes ?? new Dictionary <string, object>());
        }
        public static void TransactionTraceHasAttributes(IEnumerable <string> expectedAttributes, TransactionTraceAttributeType attributeType, TransactionSample sample)
        {
            var succeeded        = true;
            var builder          = new StringBuilder();
            var actualAttributes = sample.TraceData.Attributes.GetByType(attributeType);

            foreach (var expectedAttribute in expectedAttributes)
            {
                if (!actualAttributes.ContainsKey(expectedAttribute))
                {
                    builder.AppendFormat("Attribute named {0} was not found in the transaction sample.", expectedAttribute);
                    builder.AppendLine();
                    succeeded = false;
                }
            }

            Assert.True(succeeded, builder.ToString());
        }
        public static void TransactionTraceHasAttributes(IEnumerable <KeyValuePair <string, string> > expectedAttributes, TransactionTraceAttributeType attributeType, TransactionSample sample)
        {
            var succeeded        = true;
            var builder          = new StringBuilder();
            var actualAttributes = sample.TraceData.Attributes.GetByType(attributeType);

            foreach (var expectedAttribute in expectedAttributes)
            {
                if (!actualAttributes.ContainsKey(expectedAttribute.Key))
                {
                    builder.AppendFormat("Attribute named {0} was not found in the transaction sample.", expectedAttribute);
                    builder.AppendLine();
                    succeeded = false;
                    continue;
                }

                var actualValue = actualAttributes[expectedAttribute.Key] as string;
                if (!actualValue.Equals(expectedAttribute.Value, StringComparison.OrdinalIgnoreCase))
                {
                    builder.AppendFormat("Attribute named {0} in the transaction sample had an unexpected value.  Expected: {1}, Actual: {2}", expectedAttribute.Key, expectedAttribute.Value, actualValue);
                    builder.AppendLine();
                    succeeded = false;
                    continue;
                }
            }

            Assert.True(succeeded, builder.ToString());
        }