• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentRest / 13399786835

18 Feb 2025 08:48PM UTC coverage: 57.756% (-0.4%) from 58.107%
13399786835

push

github

pwelter34
add support for nullable, minor cleanup, improve UrlBuilder

293 of 646 branches covered (45.36%)

Branch coverage included in aggregate %.

238 of 380 new or added lines in 20 files covered. (62.63%)

3 existing lines in 3 files now uncovered.

824 of 1288 relevant lines covered (63.98%)

56.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.9
/src/FluentRest/RequestExtensions.cs
1
using System.Text;
2

3
namespace FluentRest;
4

5
/// <summary>
6
/// Extension methods for requests
7
/// </summary>
8
public static class RequestExtensions
9
{
10
    /// <summary>
11
    /// Set the bearer authorization token header. Authorization: Bearer abcdef
12
    /// </summary>
13
    /// <typeparam name="TBuilder">The type of the builder.</typeparam>
14
    /// <param name="builder">The builder to add header to.</param>
15
    /// <param name="token">The bearer authorization token.</param>
16
    /// <returns>A fluent request builder.</returns>
17
    public static TBuilder BearerToken<TBuilder>(this TBuilder builder, string? token)
18
         where TBuilder : QueryBuilder<TBuilder>
19
    {
20
        if (builder is null)
4!
NEW
21
            throw new ArgumentNullException(nameof(builder));
×
22

23
        builder.Header(h => h.Authorization("Bearer", token));
8✔
24

25
        return builder;
4✔
26
    }
27

28
    /// <summary>
29
    /// Set basic authorization header from the specified username and password. Authorization: Basic abcdef
30
    /// </summary>
31
    /// <typeparam name="TBuilder">The type of the builder.</typeparam>
32
    /// <param name="builder">The builder to add header to.</param>
33
    /// <param name="username">The username.</param>
34
    /// <param name="password">The password.</param>
35
    /// <returns>A fluent request builder.</returns>
36
    public static TBuilder BasicAuthorization<TBuilder>(this TBuilder builder, string username, string password)
37
        where TBuilder : QueryBuilder<TBuilder>
38
    {
39
        if (builder is null)
4!
NEW
40
            throw new ArgumentNullException(nameof(builder));
×
41
        if (string.IsNullOrEmpty(username))
4!
NEW
42
            throw new ArgumentException($"'{nameof(username)}' cannot be null or empty.", nameof(username));
×
43
        if (string.IsNullOrEmpty(password))
4!
NEW
44
            throw new ArgumentException($"'{nameof(password)}' cannot be null or empty.", nameof(password));
×
45

46
        string value = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
4✔
47
        builder.Header(h => h.Authorization("Basic", value));
8✔
48

49
        return builder;
4✔
50
    }
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc