< Summary

Class:Microsoft.Azure.Batch.Conventions.Files.Utilities.UrlUtils
Assembly:Microsoft.Azure.Batch.Conventions.Files
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch.Conventions.Files\src\Utilities\UrlUtils.cs
Covered lines:14
Uncovered lines:0
Coverable lines:14
Total lines:58
Line coverage:100% (14 of 14)
Covered branches:6
Total branches:6
Branch coverage:100% (6 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetUrlValueSegment(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch.Conventions.Files\src\Utilities\UrlUtils.cs

#LineLine coverage
 1// Copyright (c) Microsoft and contributors.  All rights reserved.
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6// http://www.apache.org/licenses/LICENSE-2.0
 7//
 8// Unless required by applicable law or agreed to in writing, software
 9// distributed under the License is distributed on an "AS IS" BASIS,
 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11//
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15using System;
 16using System.Collections.Generic;
 17using System.Linq;
 18using System.Text;
 19using System.Threading.Tasks;
 20
 21namespace Microsoft.Azure.Batch.Conventions.Files.Utilities
 22{
 23    internal static class UrlUtils
 24    {
 25        internal static string GetUrlValueSegment(string url, string containerSegment)
 26        {
 1027            Validate.IsNotNullOrEmpty(url, nameof(url));
 828            Validate.IsNotNullOrEmpty(containerSegment, nameof(containerSegment));
 29
 30            Uri uri;
 631            if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
 32            {
 233                throw new ArgumentException("url must be a valid absolute URI", nameof(url));
 34            }
 35
 436            var segments = uri.Segments
 2337                              .Select(s => s.Trim('/'))
 438                              .ToList();
 39
 1940            var containerSegmentIndex = segments.FindIndex(s => String.Equals(containerSegment, s, StringComparison.Ordi
 41
 42            // If the containerSegment is not present, or is the last segment, then there
 43            // is no value.
 444            if (containerSegmentIndex < 0)
 45            {
 146                return null;
 47            }
 348            if (containerSegmentIndex == segments.Count - 1)
 49            {
 150                return null;
 51            }
 52
 253            var valueSegmentIndex = containerSegmentIndex + 1;
 54
 255            return segments[valueSegmentIndex];
 56        }
 57    }
 58}

Methods/Properties

GetUrlValueSegment(...)