< Summary

Class:Azure.Core.Shared.EventSourceEventFormatting
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\EventSourceEventFormatting.cs
Covered lines:13
Uncovered lines:6
Coverable lines:19
Total lines:60
Line coverage:68.4% (13 of 19)
Covered branches:7
Total branches:10
Branch coverage:70% (7 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Format(...)-40%25%
ProcessPayloadArray(...)-100%100%
FormatValue(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\EventSourceEventFormatting.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Diagnostics.Tracing;
 5using System.Globalization;
 6using System.Linq;
 7using System.Text;
 8
 9namespace Azure.Core.Shared
 10{
 11    internal static class EventSourceEventFormatting
 12    {
 13        public static string Format(EventWrittenEventArgs eventData)
 14        {
 7556415            var payloadArray = eventData.Payload.ToArray();
 16
 7556417            ProcessPayloadArray(payloadArray);
 18
 7556419            if (eventData.Message != null)
 20            {
 7556421                return string.Format(CultureInfo.InvariantCulture, eventData.Message, payloadArray);
 22            }
 23
 024            var stringBuilder = new StringBuilder();
 025            stringBuilder.Append(eventData.EventName);
 26
 027            for (int i = 0; i < eventData.PayloadNames.Count; i++)
 28            {
 029                stringBuilder.AppendLine();
 030                stringBuilder.Append(eventData.PayloadNames[i]).Append(" = ").Append(payloadArray[i]);
 31            }
 32
 033            return stringBuilder.ToString();
 34        }
 35
 36        private static void ProcessPayloadArray(object[] payloadArray)
 37        {
 72158438            for (int i = 0; i < payloadArray.Length; i++)
 39            {
 28522840                payloadArray[i] = FormatValue(payloadArray[i]);
 41            }
 7556442        }
 43
 44        private static object FormatValue(object o)
 45        {
 28522846            if (o is byte[] bytes)
 47            {
 3248                var stringBuilder = new StringBuilder();
 40049                foreach (byte b in bytes)
 50                {
 16851                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0:X2}", b);
 52                }
 53
 3254                return stringBuilder.ToString();
 55            }
 56
 28519657            return o;
 58        }
 59    }
 60}