< Summary

Information
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 45
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SetTimeout(...)100%11100%
GetTimeout(...)100%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Http/Extensions/HttpRequestExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="HttpRequestExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Net.Http;
 9
 10#pragma warning disable IDE0130 // Namespace does not match folder structure
 11namespace MyNet.Http;
 12#pragma warning restore IDE0130 // Namespace does not match folder structure
 13
 14public static class HttpRequestExtensions
 15{
 16    private const string TimeoutPropertyKey = "RequestTimeout";
 17
 18    extension(HttpRequestMessage request)
 19    {
 20        /// <summary>
 21        /// Sets a timeout for the HTTP request by storing it in the request's options. This allows for per-request time
 22        /// </summary>
 23        /// <param name="timeout">The timeout duration for the request.</param>
 24        /// <exception cref="ArgumentNullException">Thrown if the request is null.</exception>
 25        public void SetTimeout(TimeSpan? timeout)
 26        {
 627            ArgumentNullException.ThrowIfNull(request);
 28
 329            request.Options.Set(new HttpRequestOptionsKey<TimeSpan?>(TimeoutPropertyKey), timeout);
 330        }
 31
 32        /// <summary>
 33        /// Retrieves the timeout value for the HTTP request from its options. If no timeout is set, it returns null. Th
 34        /// </summary>
 35        /// <returns>The timeout duration for the request, or null if no timeout is set.</returns>
 36        /// <exception cref="ArgumentNullException">Thrown if the request is null.</exception>
 37        public TimeSpan? GetTimeout()
 38        {
 2139            ArgumentNullException.ThrowIfNull(request);
 40
 2141            return request.Options.TryGetValue(new HttpRequestOptionsKey<TimeSpan?>(TimeoutPropertyKey), out var value) 
 42        }
 43    }
 44}
 45