< Summary

Information
Class: dotnet_etcd.DependencyInjection.EtcdClientOptionsValidator
Assembly: dotnet-etcd
File(s): /home/runner/work/dotnet-etcd/dotnet-etcd/dotnet-etcd/DependencyInjection/EtcdClientOptionsValidator.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 42
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ValidateOptions(...)100%1212100%

File(s)

/home/runner/work/dotnet-etcd/dotnet-etcd/dotnet-etcd/DependencyInjection/EtcdClientOptionsValidator.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5
 6namespace dotnet_etcd.DependencyInjection;
 7
 8/// <summary>
 9///     Validates etcd client options.
 10/// </summary>
 11internal static class EtcdClientOptionsValidator
 12{
 13    /// <summary>
 14    ///     Validates the specified options.
 15    /// </summary>
 16    /// <param name="options">The options to validate.</param>
 17    /// <exception cref="ArgumentNullException">Thrown if options is null.</exception>
 18    /// <exception cref="ArgumentException">Thrown if options is invalid.</exception>
 19    public static void ValidateOptions(EtcdClientOptions options)
 2020    {
 2021        ArgumentNullException.ThrowIfNull(options);
 22
 1923        if (string.IsNullOrWhiteSpace(options.ConnectionString))
 224        {
 225            throw new ArgumentException("ConnectionString must be provided", nameof(options));
 26        }
 27
 28        // Validate port is in a valid range
 1729        if (options.Port is <= 0 or > 65535)
 330        {
 331            throw new ArgumentException($"Port must be between 1 and 65535, but was {options.Port}", nameof(options));
 32        }
 33
 34        // Validate server name if using static hosts format
 1435        if (options.ConnectionString.StartsWith("static://", StringComparison.OrdinalIgnoreCase) &&
 1436            string.IsNullOrWhiteSpace(options.ServerName))
 237        {
 238            throw new ArgumentException("ServerName must be provided when using static:// connection string format",
 239                nameof(options));
 40        }
 1241    }
 42}