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

loresoft / FluentCommand / 25142891832

30 Apr 2026 01:24AM UTC coverage: 55.101%. First build
25142891832

push

github

pwelter34
Add configurable default command timeout

1421 of 3237 branches covered (43.9%)

Branch coverage included in aggregate %.

23 of 27 new or added lines in 4 files covered. (85.19%)

4158 of 6888 relevant lines covered (60.37%)

314.16 hits per line

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

71.43
/src/FluentCommand/DataConfiguration.cs
1
using System.Data.Common;
2

3
using FluentCommand.Query.Generators;
4

5
namespace FluentCommand;
6

7
/// <summary>
8
/// The database configuration
9
/// </summary>
10
/// <seealso cref="IDataConfiguration" />
11
public class DataConfiguration : IDataConfiguration
12
{
13
    /// <summary>
14
    /// Initializes a new instance of the <see cref="DataConfiguration" /> class.
15
    /// </summary>
16
    /// <param name="providerFactory">The database provider factory.</param>
17
    /// <param name="connectionString">The database connection string.</param>
18
    /// <param name="cache">The data cache manager.</param>
19
    /// <param name="queryGenerator">The query generator.</param>
20
    /// <param name="queryLogger">The query command logger.</param>
21
    /// <param name="commandTimeout">The default command timeout in seconds.</param>
22
    /// <param name="interceptors">The interceptors to apply to each session created from this configuration.</param>
23
    /// <exception cref="ArgumentNullException">The <paramref name="providerFactory"/> is null</exception>
24
    public DataConfiguration(
8✔
25
        DbProviderFactory providerFactory,
8✔
26
        string connectionString,
8✔
27
        IDataCache? cache = null,
8✔
28
        IQueryGenerator? queryGenerator = null,
8✔
29
        IDataQueryLogger? queryLogger = null,
8✔
30
        IEnumerable<IDataInterceptor>? interceptors = null,
8✔
31
        int? commandTimeout = null)
8✔
32
    {
33
        ProviderFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
8!
34
        ConnectionString = connectionString;
8✔
35
        QueryLogger = queryLogger;
8✔
36
        CommandTimeout = commandTimeout;
8✔
37
        DataCache = cache;
8✔
38
        QueryGenerator = queryGenerator ?? new SqlServerGenerator();
8✔
39
        Interceptors = interceptors ?? [];
8✔
40
    }
8✔
41

42
    /// <summary>
43
    /// Gets the database provider factory.
44
    /// </summary>
45
    /// <value>
46
    /// The provider factory.
47
    /// </value>
48
    public virtual DbProviderFactory ProviderFactory { get; }
49

50
    /// <summary>
51
    /// Gets the database connection string.
52
    /// </summary>
53
    /// <value>
54
    /// The connection string.
55
    /// </value>
56
    public virtual string ConnectionString { get; }
57

58
    /// <summary>
59
    /// Gets the data command query logger.
60
    /// </summary>
61
    /// <value>
62
    /// The data command query logger.
63
    /// </value>
64
    public IDataQueryLogger? QueryLogger { get; }
65

66
    /// <summary>
67
    /// Gets the default command timeout in seconds.
68
    /// </summary>
69
    /// <value>
70
    /// The default command timeout in seconds.
71
    /// </value>
72
    public int? CommandTimeout { get; }
73

74
    /// <summary>
75
    /// Gets the data cache manager.
76
    /// </summary>
77
    /// <value>
78
    /// The data cache manager.
79
    /// </value>
80
    public virtual IDataCache? DataCache { get; }
81

82
    /// <summary>
83
    /// Gets the query generator provider.
84
    /// </summary>
85
    /// <value>
86
    /// The query generator provider.
87
    /// </value>
88
    public IQueryGenerator QueryGenerator { get; }
89

90
    /// <summary>
91
    /// Gets the registered interceptors for this configuration.
92
    /// </summary>
93
    /// <value>
94
    /// The list of <see cref="IDataInterceptor"/> instances applied to each session created from this configuration.
95
    /// </value>
96
    public IEnumerable<IDataInterceptor> Interceptors { get; }
97

98
    /// <summary>
99
    /// Creates a new data session from this database configuration
100
    /// </summary>
101
    /// <param name="connectionString">The connection string to use for the session.  If <paramref name="connectionString" /> is <c>null</c>, <see cref="ConnectionString" /> will be used.</param>
102
    /// <returns>
103
    /// A new <see cref="IDataSession" /> instance.
104
    /// </returns>
105
    public virtual IDataSession CreateSession(string? connectionString = null)
106
    {
107
        var connection = CreateConnection(connectionString);
4✔
108
        return new DataSession(connection, true, DataCache, QueryGenerator, QueryLogger, Interceptors, CommandTimeout);
4✔
109
    }
110

111
    /// <summary>
112
    /// Creates a new data session from this database configuration
113
    /// </summary>
114
    /// <param name="transaction">The transaction to create the session with.</param>
115
    /// <returns>
116
    /// A new <see cref="IDataSession" /> instance.
117
    /// </returns>
118
    /// <exception cref="System.ArgumentNullException">transaction is null</exception>
119
    /// <exception cref="System.ArgumentException">The specified transaction doesn't have a vaild connection </exception>
120
    public IDataSession CreateSession(DbTransaction transaction)
121
    {
122
        if (transaction is null)
×
123
            throw new ArgumentNullException(nameof(transaction));
×
124

125
        if (transaction.Connection == null)
×
126
            throw new ArgumentException("The specified transaction doesn't have a vaild connection", nameof(transaction));
×
127

NEW
128
        return new DataSession(transaction, false, DataCache, QueryGenerator, QueryLogger, Interceptors, CommandTimeout);
×
129
    }
130

131
    /// <summary>
132
    /// Creates a new <see cref="DbConnection" /> instance from this database configuration.
133
    /// </summary>
134
    /// <param name="connectionString"></param>
135
    /// <returns>
136
    /// A new <see cref="DbConnection" /> instance.
137
    /// </returns>
138
    /// <exception cref="InvalidOperationException">Database provider factory failed to create a connection object.</exception>
139
    /// <exception cref="ArgumentException">The connection string is invalid</exception>
140
    public virtual DbConnection CreateConnection(string? connectionString = null)
141
    {
142
        var connection = ProviderFactory.CreateConnection();
168✔
143
        if (connection == null)
168!
144
            throw new InvalidOperationException("Database provider factory failed to create a connection object.");
×
145

146
        connectionString ??= ConnectionString;
168✔
147
        if (string.IsNullOrEmpty(connectionString))
168!
148
            throw new ArgumentException("The connection string is invalid");
×
149

150
        connection.ConnectionString = connectionString;
168✔
151
        return connection;
168✔
152
    }
153
}
154

155

156
/// <summary>
157
/// The database configuration by discriminator.  Used to register multiple instances of IDataConfiguration.
158
/// </summary>
159
/// <typeparam name="TDiscriminator">The type of the discriminator.</typeparam>
160
/// <seealso cref="FluentCommand.IDataConfiguration" />
161
public class DataConfiguration<TDiscriminator> : DataConfiguration, IDataConfiguration<TDiscriminator>
162
{
163
    /// <summary>
164
    /// Initializes a new instance of the <see cref="DataConfiguration{TDiscriminator}"/> class.
165
    /// </summary>
166
    /// <param name="providerFactory">The database provider factory.</param>
167
    /// <param name="connectionString">The database connection string.</param>
168
    /// <param name="cache">The data cache manager.</param>
169
    /// <param name="queryGenerator">The query generator.</param>
170
    /// <param name="queryLogger">The query command logger.</param>
171
    /// <param name="commandTimeout">The default command timeout in seconds.</param>
172
    /// <param name="interceptors">The interceptors to apply during this configuration's lifetime.</param>
173
    public DataConfiguration(
174
        DbProviderFactory providerFactory,
175
        string connectionString,
176
        IDataCache? cache = null,
177
        IQueryGenerator? queryGenerator = null,
178
        IDataQueryLogger? queryLogger = null,
179
        IEnumerable<IDataInterceptor>? interceptors = null,
180
        int? commandTimeout = null)
181
        : base(providerFactory, connectionString, cache, queryGenerator, queryLogger, interceptors, commandTimeout)
1✔
182
    {
183
    }
1✔
184
}
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