コード例 #1
0
        public static void ErrorEventHasAttributes(IEnumerable <string> expectedAttributes, EventAttributeType attributeType, ErrorEventEvents errorEvent)
        {
            var succeeded        = true;
            var builder          = new StringBuilder();
            var actualAttributes = new List <string>();

            switch (attributeType)
            {
            case EventAttributeType.Agent:
                actualAttributes = errorEvent.AgentAttributes.Keys.ToList();
                break;

            case EventAttributeType.Intrinsic:
                actualAttributes = errorEvent.IntrinsicAttributes.Keys.ToList();
                break;

            case EventAttributeType.User:
                actualAttributes = errorEvent.UserAttributes.Keys.ToList();
                break;
            }

            foreach (var expectedAttribute in expectedAttributes)
            {
                if (!actualAttributes.Contains(expectedAttribute))
                {
                    builder.AppendFormat("Attribute name {0} was not found in error event", expectedAttribute);
                    builder.AppendLine();
                    succeeded = false;
                }
            }

            Assert.True(succeeded, builder.ToString());
        }
コード例 #2
0
        public static void ErrorEventDoesNotHaveAttributes(IEnumerable <string> unexpectedAttributes, EventAttributeType attributeType, ErrorEventEvents errorEvent)
        {
            var succeeded = true;
            var builder   = new StringBuilder();
            IDictionary <string, object> actualAttributes = null;

            switch (attributeType)
            {
            case EventAttributeType.Agent:
                actualAttributes = errorEvent.AgentAttributes;
                break;

            case EventAttributeType.Intrinsic:
                actualAttributes = errorEvent.IntrinsicAttributes;
                break;

            case EventAttributeType.User:
                actualAttributes = errorEvent.UserAttributes;
                break;
            }

            foreach (var unexpectedAttribute in unexpectedAttributes)
            {
                if (actualAttributes.ContainsKey(unexpectedAttribute))
                {
                    builder.AppendFormat("Attribute named {0} was found in the error event but it should not have been.", unexpectedAttribute);
                    builder.AppendLine();
                    succeeded = false;
                }
            }

            Assert.True(succeeded, builder.ToString());
        }
コード例 #3
0
        public static void ErrorEventHasAttributes(IEnumerable <KeyValuePair <string, string> > expectedAttributes, EventAttributeType attributeType, ErrorEventEvents errorEvent)
        {
            var succeeded = true;
            var builder   = new StringBuilder();
            IDictionary <string, object> actualAttributes = null;

            switch (attributeType)
            {
            case EventAttributeType.Agent:
                actualAttributes = errorEvent.AgentAttributes;
                break;

            case EventAttributeType.Intrinsic:
                actualAttributes = errorEvent.IntrinsicAttributes;
                break;

            case EventAttributeType.User:
                actualAttributes = errorEvent.UserAttributes;
                break;
            }

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

                var actualValue = actualAttributes[expectedAttribute.Key] as string;

                if (actualValue == null && actualAttributes[expectedAttribute.Key].GetType() == typeof(bool))
                {
                    actualValue = actualAttributes[expectedAttribute.Key].ToString().ToLowerInvariant();
                }

                if (actualValue != expectedAttribute.Value)
                {
                    builder.AppendFormat("Attribute named {0} in the error event had an unexpected value.  Expected: {1}, Actual: {2}", expectedAttribute.Key, expectedAttribute.Value, actualValue);
                    builder.AppendLine();
                    succeeded = false;
                    continue;
                }
            }

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