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

loresoft / FluentCommand / 22970781217

11 Mar 2026 07:32PM UTC coverage: 56.585% (+0.2%) from 56.372%
22970781217

push

github

pwelter34
Add ParameterJson overloads

1277 of 2823 branches covered (45.24%)

Branch coverage included in aggregate %.

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

64 existing lines in 4 files now uncovered.

3892 of 6312 relevant lines covered (61.66%)

367.61 hits per line

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

66.04
/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="interceptors">The interceptors to apply to each session created from this configuration.</param>
22
    /// <exception cref="ArgumentNullException">The <paramref name="providerFactory"/> is null</exception>
23
    public DataConfiguration(
4✔
24
        DbProviderFactory providerFactory,
4✔
25
        string connectionString,
4✔
26
        IDataCache cache = null,
4✔
27
        IQueryGenerator queryGenerator = null,
4✔
28
        IDataQueryLogger queryLogger = null,
4✔
29
        IEnumerable<IDataInterceptor> interceptors = null)
4✔
30
    {
31
        ProviderFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
4!
32
        ConnectionString = connectionString;
4✔
33
        QueryLogger = queryLogger;
4✔
34
        DataCache = cache;
4✔
35
        QueryGenerator = queryGenerator ?? new SqlServerGenerator();
4!
36
        Interceptors = interceptors ?? [];
4!
37
    }
4✔
38

39
    /// <summary>
40
    /// Gets the database provider factory.
41
    /// </summary>
42
    /// <value>
43
    /// The provider factory.
44
    /// </value>
45
    public virtual DbProviderFactory ProviderFactory { get; }
153✔
46

47
    /// <summary>
48
    /// Gets the database connection string.
49
    /// </summary>
50
    /// <value>
51
    /// The connection string.
52
    /// </value>
53
    public virtual string ConnectionString { get; }
156✔
54

55
    /// <summary>
56
    /// Gets the data command query logger.
57
    /// </summary>
58
    /// <value>
59
    /// The data command query logger.
60
    /// </value>
61
    public IDataQueryLogger QueryLogger { get; }
144✔
62

63
    /// <summary>
64
    /// Gets the data cache manager.
65
    /// </summary>
66
    /// <value>
67
    /// The data cache manager.
68
    /// </value>
69
    public virtual IDataCache DataCache { get; }
144✔
70

71
    /// <summary>
72
    /// Gets the query generator provider.
73
    /// </summary>
74
    /// <value>
75
    /// The query generator provider.
76
    /// </value>
77
    public IQueryGenerator QueryGenerator { get; }
144✔
78

79
    /// <summary>
80
    /// Gets the registered interceptors for this configuration.
81
    /// </summary>
82
    /// <value>
83
    /// The list of <see cref="IDataInterceptor"/> instances applied to each session created from this configuration.
84
    /// </value>
85
    public IEnumerable<IDataInterceptor> Interceptors { get; }
288✔
86

87
    /// <summary>
88
    /// Creates a new data session from this database configuration
89
    /// </summary>
90
    /// <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>
91
    /// <returns>
92
    /// A new <see cref="IDataSession" /> instance.
93
    /// </returns>
94
    public virtual IDataSession CreateSession(string connectionString = null)
95
    {
UNCOV
96
        var connection = CreateConnection(connectionString);
×
UNCOV
97
        return new DataSession(connection, true, DataCache, QueryGenerator, QueryLogger, Interceptors);
×
98
    }
99

100
    /// <summary>
101
    /// Creates a new data session from this database configuration
102
    /// </summary>
103
    /// <param name="transaction">The transaction to create the session with.</param>
104
    /// <returns>
105
    /// A new <see cref="IDataSession" /> instance.
106
    /// </returns>
107
    /// <exception cref="System.ArgumentNullException">transaction is null</exception>
108
    /// <exception cref="System.ArgumentException">The specified transaction doesn't have a vaild connection </exception>
109
    public IDataSession CreateSession(DbTransaction transaction)
110
    {
UNCOV
111
        if (transaction is null)
×
UNCOV
112
            throw new ArgumentNullException(nameof(transaction));
×
113

UNCOV
114
        if (transaction.Connection == null)
×
UNCOV
115
            throw new ArgumentException("The specified transaction doesn't have a vaild connection", nameof(transaction));
×
116

UNCOV
117
        return new DataSession(transaction, false, DataCache, QueryGenerator, QueryLogger, Interceptors);
×
118
    }
119

120
    /// <summary>
121
    /// Creates a new <see cref="DbConnection" /> instance from this database configuration.
122
    /// </summary>
123
    /// <param name="connectionString"></param>
124
    /// <returns>
125
    /// A new <see cref="DbConnection" /> instance.
126
    /// </returns>
127
    /// <exception cref="InvalidOperationException">Database provider factory failed to create a connection object.</exception>
128
    /// <exception cref="ArgumentException">The connection string is invalid</exception>
129
    public virtual DbConnection CreateConnection(string connectionString = null)
130
    {
131
        var connection = ProviderFactory.CreateConnection();
153✔
132
        if (connection == null)
153!
UNCOV
133
            throw new InvalidOperationException("Database provider factory failed to create a connection object.");
×
134

135
        connectionString ??= ConnectionString;
153✔
136
        if (string.IsNullOrEmpty(connectionString))
153!
UNCOV
137
            throw new ArgumentException("The connection string is invalid");
×
138

139
        connection.ConnectionString = connectionString;
153✔
140
        return connection;
153✔
141
    }
142
}
143

144

145
/// <summary>
146
/// The database configuration by discriminator.  Used to register multiple instances of IDataConfiguration.
147
/// </summary>
148
/// <typeparam name="TDiscriminator">The type of the discriminator.</typeparam>
149
/// <seealso cref="FluentCommand.IDataConfiguration" />
150
public class DataConfiguration<TDiscriminator> : DataConfiguration, IDataConfiguration<TDiscriminator>
151
{
152
    /// <summary>
153
    /// Initializes a new instance of the <see cref="DataConfiguration{TDiscriminator}"/> class.
154
    /// </summary>
155
    /// <param name="providerFactory">The database provider factory.</param>
156
    /// <param name="connectionString">The database connection string.</param>
157
    /// <param name="cache">The data cache manager.</param>
158
    /// <param name="queryGenerator">The query generator.</param>
159
    /// <param name="queryLogger">The query command logger.</param>
160
    /// <param name="interceptors">The interceptors to apply during this configuration's lifetime.</param>
161
    public DataConfiguration(
162
        DbProviderFactory providerFactory,
163
        string connectionString,
164
        IDataCache cache = null,
165
        IQueryGenerator queryGenerator = null,
166
        IDataQueryLogger queryLogger = null,
167
        IEnumerable<IDataInterceptor> interceptors = null)
168
        : base(providerFactory, connectionString, cache, queryGenerator, queryLogger, interceptors)
1✔
169
    {
170
    }
1✔
171
}
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