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

Shane32 / PostGrid / 13879948860

16 Mar 2025 04:36AM UTC coverage: 19.013%. First build
13879948860

Pull #1

github

web-flow
Merge 15f9187bd into 945380ab5
Pull Request #1: Update tests

38 of 266 branches covered (14.29%)

Branch coverage included in aggregate %.

11 of 19 new or added lines in 4 files covered. (57.89%)

147 of 707 relevant lines covered (20.79%)

0.31 hits per line

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

22.0
/src/Project/ServiceCollectionExtensions.cs
1
using Microsoft.Extensions.Configuration;
2
using Shane32.PostGrid;
3

4
namespace Microsoft.Extensions.DependencyInjection;
5

6
/// <summary>
7
/// Extension methods for setting up PostGrid services in an <see cref="IServiceCollection"/>.
8
/// </summary>
9
public static class PostGridExtensions
10
{
11
    /// <summary>
12
    /// Adds PostGrid services to the specified <see cref="IServiceCollection"/> using configuration.
13
    /// </summary>
14
    /// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
15
    /// <param name="configuration">The <see cref="IConfiguration"/> containing the PostGrid configuration.</param>
16
    /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
17
    public static IServiceCollection AddPostGrid(this IServiceCollection services, IConfiguration configuration)
18
    {
×
19
        if (services == null)
×
20
            throw new ArgumentNullException(nameof(services));
×
21
        if (configuration == null)
×
22
            throw new ArgumentNullException(nameof(configuration));
×
23

24
        // Configure options from the configuration
NEW
25
        services.Configure<PostGridOptions>(options => {
×
26
            options.ApiKey = configuration["ApiKey"]!;
×
NEW
27

×
28
            var baseUrl = configuration["BaseUrl"];
×
29
            if (baseUrl != null && !string.IsNullOrEmpty(baseUrl))
×
30
                options.BaseUrl = baseUrl;
×
NEW
31

×
32
            if (int.TryParse(configuration["MaxRetryAttempts"], out var maxRetryAttempts))
×
33
                options.MaxRetryAttempts = maxRetryAttempts;
×
NEW
34

×
35
            if (int.TryParse(configuration["DefaultRetryDelayMs"], out var defaultRetryDelayMs))
×
36
                options.DefaultRetryDelayMs = defaultRetryDelayMs;
×
37
        });
×
38

39
        // Add HttpClient
40
        services.AddHttpClient<IPostGridConnection, PostGridConnection>();
×
41

42
        // Add PostGrid service
43
        services.AddTransient<PostGrid>();
×
44

45
        return services;
×
46
    }
×
47

48
    /// <summary>
49
    /// Adds PostGrid services to the specified <see cref="IServiceCollection"/>.
50
    /// </summary>
51
    /// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
52
    /// <param name="configureOptions">A callback to configure the <see cref="PostGridOptions"/>. This is optional.</param>
53
    /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
54
    public static IServiceCollection AddPostGrid(this IServiceCollection services, Action<PostGridOptions>? configureOptions)
55
    {
1✔
56
        if (services == null)
1!
57
            throw new ArgumentNullException(nameof(services));
×
58

59
        // Add options
60
        if (configureOptions != null) {
2!
61
            services.Configure(configureOptions);
1✔
62
        } else {
1✔
63
            // Add empty options to ensure IOptions<PostGridOptions> is available
64
            services.AddOptions<PostGridOptions>();
×
65
        }
×
66

67
        // Add HttpClient
68
        services.AddHttpClient<IPostGridConnection, PostGridConnection>();
1✔
69

70
        // Add PostGrid service
71
        services.AddTransient<PostGrid>();
1✔
72

73
        return services;
1✔
74
    }
1✔
75
}
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