< Summary

Class:Azure.Data.AppConfiguration.SyncTokenPolicy
Assembly:Azure.Data.AppConfiguration
File(s):C:\Git\azure-sdk-for-net\sdk\appconfiguration\Azure.Data.AppConfiguration\src\SyncTokenPolicy.cs
Covered lines:22
Uncovered lines:0
Coverable lines:22
Total lines:58
Line coverage:100% (22 of 22)
Covered branches:12
Total branches:12
Branch coverage:100% (12 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
OnSendingRequest(...)-100%100%
OnReceivedResponse(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Concurrent;
 5using System.Collections.Generic;
 6using Azure.Core;
 7using Azure.Core.Pipeline;
 8
 9namespace Azure.Data.AppConfiguration
 10{
 11    internal class SyncTokenPolicy : HttpPipelineSynchronousPolicy
 12    {
 13        private const string SyncTokenHeader = "Sync-Token";
 14
 15        private readonly ConcurrentDictionary<string, SyncToken> _syncTokens;
 16
 34417        public SyncTokenPolicy()
 18        {
 34419            _syncTokens = new ConcurrentDictionary<string, SyncToken>();
 34420        }
 21
 22        public override void OnSendingRequest(HttpMessage message)
 23        {
 84024            message.Request.Headers.Remove(SyncTokenHeader);
 264825            foreach (SyncToken token in _syncTokens.Values)
 26            {
 48427                message.Request.Headers.Add(SyncTokenHeader, token.ToString());
 28            }
 84029        }
 30
 31        public override void OnReceivedResponse(HttpMessage message)
 32        {
 84033            if (message.Response.Headers.TryGetValues(SyncTokenHeader, out IEnumerable<string> rawSyncTokens))
 34            {
 245635                foreach (string fullRawToken in rawSyncTokens)
 36                {
 37                    // Handle multiple header values.
 61638                    string[] rawTokens = fullRawToken.Split(',');
 247239                    foreach (string rawToken in rawTokens)
 40                    {
 62041                        if (SyncTokenUtils.TryParse(rawToken, out SyncToken token))
 42                        {
 62043                            _syncTokens.AddOrUpdate(token.Id, token, (key, existing) =>
 62044                            {
 103645                                if (existing.SequenceNumber < token.SequenceNumber)
 62046                                {
 90447                                    return token;
 62048                                }
 62049
 75250                                return existing;
 62051                            });
 52                        }
 53                    }
 54                }
 55            }
 84056        }
 57    }
 58}