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

abatar1 / Environment.Setup / 14742006635

29 Apr 2025 09:49PM UTC coverage: 51.515% (-2.5%) from 53.968%
14742006635

push

github

abatar1
minor API improvements

8 of 20 branches covered (40.0%)

Branch coverage included in aggregate %.

0 of 6 new or added lines in 1 file covered. (0.0%)

60 of 112 relevant lines covered (53.57%)

1.38 hits per line

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

60.0
/src/Environment.Setup/EnvironmentConfigurationBuilder.cs
1
using System;
2
using System.Collections.Generic;
3

4
namespace Environment.Setup;
5

6
public sealed class EnvironmentConfigurationBuilder(IServiceProvider serviceProvider, Dictionary<Type, EnvironmentConfigurationState> states)
3✔
7
{
8
    internal Dictionary<Type, EnvironmentConfigurationState> States { get; } = states;
9✔
9
    
10
    internal readonly IServiceProvider ServiceProvider = serviceProvider;
3✔
11

12
    /// <summary>
13
    /// Configures the specified environment entity by invoking the provided entity enricher.
14
    /// </summary>
15
    /// <typeparam name="TEnvironmentConfiguration">The type of the environment configuration to be set up.</typeparam>
16
    /// <param name="entityEnricher">An action that provides configuration details for the environment entity.</param>
17
    /// <returns>An instance of <see cref="EnvironmentConfigurationConcreteBuilder"/> representing the configuration context for the specified environment entity.</returns>
18
    public EnvironmentConfigurationConcreteBuilder Configure<TEnvironmentConfiguration>(
19
        Action<EnvironmentConfigurationBuilder<TEnvironmentConfiguration>> entityEnricher)
20
        where TEnvironmentConfiguration : class, IEnvironmentConfiguration
21
    {
22
        var entity = Activator.CreateInstance<TEnvironmentConfiguration>();
2✔
23
        
24
        var builder = new EnvironmentConfigurationBuilder<TEnvironmentConfiguration>(ServiceProvider, entity);
2✔
25
        entityEnricher.Invoke(builder);
2✔
26
        
27
        var enricher = builder.Build();
2✔
28
        
29
        TryAddEntity(enricher);
2✔
30
        
31
        return new EnvironmentConfigurationConcreteBuilder(typeof(TEnvironmentConfiguration), this);
2✔
32
    }
33

34
    /// <summary>
35
    /// Configures the specified environment configuration by invoking the provided entity enricher.
36
    /// </summary>
37
    /// <typeparam name="TEnvironmentConfiguration">The type of the environment configuration to be configured.</typeparam>
38
    /// <param name="entityEnricher">An action that configures the environment entity using the service provider and a configuration builder.</param>
39
    /// <returns>An instance of <see cref="EnvironmentConfigurationConcreteBuilder"/> representing the configuration context for the specified environment entity.</returns>
40
    public EnvironmentConfigurationConcreteBuilder Configure<TEnvironmentConfiguration>(
41
        Action<IServiceProvider, EnvironmentConfigurationBuilder<TEnvironmentConfiguration>> entityEnricher)
42
        where TEnvironmentConfiguration : class, IEnvironmentConfiguration
43
    {
NEW
44
        var entity = Activator.CreateInstance<TEnvironmentConfiguration>();
×
45
        
NEW
46
        var builder = new EnvironmentConfigurationBuilder<TEnvironmentConfiguration>(ServiceProvider, entity);
×
NEW
47
        entityEnricher.Invoke(ServiceProvider, builder);
×
48
        
NEW
49
        var enricher = builder.Build();
×
50
        
NEW
51
        TryAddEntity(enricher);
×
52
        
NEW
53
        return new EnvironmentConfigurationConcreteBuilder(typeof(TEnvironmentConfiguration), this);
×
54
    }
55

56
    private void TryAddEntity<TEnvironmentConfiguration>(Func<TEnvironmentConfiguration> configurationEnricher)
57
        where TEnvironmentConfiguration : class, IEnvironmentConfiguration
58
    {
59
        try
60
        {
61
            States.Add(typeof(TEnvironmentConfiguration), new EnvironmentConfigurationState(configurationEnricher, false));
2✔
62
        }
2✔
63
        catch (Exception e)
×
64
        {
65
            throw new EnvironmentSetupException($"Entity of type {typeof(TEnvironmentConfiguration).FullName} already registered", e);
×
66
        }
67
    }
2✔
68
}
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

© 2026 Coveralls, Inc