< Summary

Class:Azure.Data.AppConfiguration.SyncTokenUtils
Assembly:Azure.Data.AppConfiguration
File(s):C:\Git\azure-sdk-for-net\sdk\appconfiguration\Azure.Data.AppConfiguration\src\SyncTokenUtils.cs
Covered lines:35
Uncovered lines:3
Coverable lines:38
Total lines:103
Line coverage:92.1% (35 of 38)
Covered branches:23
Total branches:26
Branch coverage:88.4% (23 of 26)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
TryParse(...)-92.11%88.46%

File(s)

C:\Git\azure-sdk-for-net\sdk\appconfiguration\Azure.Data.AppConfiguration\src\SyncTokenUtils.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Globalization;
 5
 6namespace Azure.Data.AppConfiguration
 7{
 8    internal class SyncTokenUtils
 9    {
 10        // Sync-Token Syntax: <id>=<value>;sn=<sn>
 11        internal static bool TryParse(string value, out SyncToken result)
 12        {
 62413            result = new SyncToken();
 14
 62415            if (string.IsNullOrEmpty(value))
 16            {
 017                return false;
 18            }
 19
 62420            string tokenId = null;
 62421            string tokenValue = null;
 62422            long sequenceNumber = 0;
 23
 62424            int pos = 0;
 62425            string name = null;
 62426            string val = null;
 27
 4379228            for (int i = 0; i < value.Length; i++)
 29            {
 2127230                char ch = value[i];
 31
 2127232                if (name == null)
 33                {
 760034                    if (ch == '=')
 35                    {
 124836                        name = value.Substring(pos, i - pos);
 124837                        pos = i + 1;
 38
 124839                        continue;
 40                    }
 41                }
 42
 2002443                if (ch == ';' || i == value.Length - 1)
 44                {
 45                    //
 46                    // Done with the current name-value pair
 124847                    if (i == value.Length - 1)
 48                    {
 62449                        i++;
 50                    }
 51
 124852                    string fragment = value.Substring(pos, i - pos);
 53
 124854                    if (name != null)
 55                    {
 124856                        val = fragment;
 57                    }
 58                    else
 59                    {
 060                        name = fragment;
 61                    }
 62
 124863                    name = name.Trim();
 64
 65                    //
 66                    // Sequence Number
 124867                    if (name == "sn")
 68                    {
 62469                        if (!long.TryParse(val, NumberStyles.None, CultureInfo.InvariantCulture, out sequenceNumber))
 70                        {
 071                            return false;
 72                        }
 73                    }
 74                    //
 75                    // id-value
 62476                    else if (tokenId == null)
 77                    {
 62478                        tokenValue = val;
 62479                        tokenId = name;
 80                    }
 81
 82                    //
 83                    // Reset current
 124884                    name = null;
 124885                    val = null;
 86
 124887                    pos = i + 1;
 88                }
 89            }
 90
 91            //
 92            // Validate
 62493            bool success = false;
 62494            if (!(tokenId == null || tokenValue == null))
 95            {
 62496                result = new SyncToken(tokenId, tokenValue, sequenceNumber);
 62497                success = true;
 98            }
 99
 624100            return success;
 101        }
 102    }
 103}

Methods/Properties

TryParse(...)