Skip to content

Commit 958ae8d

Browse files
author
James Craig
committed
Renamed some stuff and made the connection information visible from the SQLHelper class.
1 parent 0bf05aa commit 958ae8d

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

src/SQLHelper.DB/HelperClasses/Batch.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Batch : IBatch
3838
/// Constructor
3939
/// </summary>
4040
/// <param name="source">Source info</param>
41-
public Batch(ISource source)
41+
public Batch(IConnection source)
4242
{
4343
Commands = new List<ICommand>();
4444
Source = source;
@@ -62,7 +62,7 @@ public Batch(ISource source)
6262
/// <summary>
6363
/// Connection string
6464
/// </summary>
65-
protected ISource Source { get; set; }
65+
protected IConnection Source { get; set; }
6666

6767
/// <summary>
6868
/// Adds a command to be batched
@@ -283,7 +283,7 @@ private IList<IList<dynamic>> ExecuteCommands()
283283
var Factory = Source.Factory;
284284
using (DbConnection Connection = Factory.CreateConnection())
285285
{
286-
Connection.ConnectionString = Source.Connection;
286+
Connection.ConnectionString = Source.ConnectionString;
287287
using (DbCommand ExecutableCommand = Factory.CreateCommand())
288288
{
289289
SetupCommand(Connection, ExecutableCommand);
@@ -332,7 +332,7 @@ private async Task<IList<IList<dynamic>>> ExecuteCommandsAsync()
332332
var Factory = Source.Factory;
333333
using (DbConnection Connection = Factory.CreateConnection())
334334
{
335-
Connection.ConnectionString = Source.Connection;
335+
Connection.ConnectionString = Source.ConnectionString;
336336
using (DbCommand ExecutableCommand = Factory.CreateCommand())
337337
{
338338
SetupCommand(Connection, ExecutableCommand);
@@ -376,9 +376,9 @@ private void FinalizeCommands(List<IList<dynamic>> ReturnValue)
376376
}
377377
}
378378

379-
private void SetupCommand(DbConnection Connection, DbCommand ExecutableCommand)
379+
private void SetupCommand(DbConnection DatabaseConnection, DbCommand ExecutableCommand)
380380
{
381-
ExecutableCommand.Connection = Connection;
381+
ExecutableCommand.Connection = DatabaseConnection;
382382
ExecutableCommand.CommandType = CommandType.Text;
383383
if (CheckTransaction())
384384
ExecutableCommand.BeginTransaction();

src/SQLHelper.DB/HelperClasses/Source.cs renamed to src/SQLHelper.DB/HelperClasses/Connection.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace SQLHelper.HelperClasses
2424
/// <summary>
2525
/// Data source class
2626
/// </summary>
27-
/// <seealso cref="ISource"/>
28-
public class Source : ISource
27+
/// <seealso cref="IConnection"/>
28+
public class Connection : IConnection
2929
{
3030
/// <summary>
3131
/// Constructor
@@ -36,7 +36,7 @@ public class Source : ISource
3636
/// <param name="name">The name.</param>
3737
/// <param name="sourceType">Type of the source.</param>
3838
/// <param name="parameterPrefix">The parameter prefix.</param>
39-
public Source(IConfiguration configuration, DbProviderFactory factory, string connection, string name, string sourceType = "System.Data.SqlClient",
39+
public Connection(IConfiguration configuration, DbProviderFactory factory, string connection, string name, string sourceType = "System.Data.SqlClient",
4040
string parameterPrefix = "@")
4141
{
4242
Name = string.IsNullOrEmpty(name) ? "Default" : name;
@@ -45,11 +45,11 @@ public Source(IConfiguration configuration, DbProviderFactory factory, string co
4545
var TempConfig = configuration.GetConnectionString(Name);
4646
if (string.IsNullOrEmpty(connection) && TempConfig != null)
4747
{
48-
Connection = TempConfig;
48+
ConnectionString = TempConfig;
4949
}
5050
else
5151
{
52-
Connection = string.IsNullOrEmpty(connection) ? name : connection;
52+
ConnectionString = string.IsNullOrEmpty(connection) ? name : connection;
5353
}
5454
if (string.IsNullOrEmpty(parameterPrefix))
5555
{
@@ -59,7 +59,7 @@ public Source(IConfiguration configuration, DbProviderFactory factory, string co
5959
ParameterPrefix = ":";
6060
else
6161
{
62-
DatabaseName = Regex.Match(Connection, @"Initial Catalog=([^;]*)").Groups[1].Value;
62+
DatabaseName = Regex.Match(ConnectionString, @"Initial Catalog=([^;]*)").Groups[1].Value;
6363
ParameterPrefix = "@";
6464
}
6565
}
@@ -68,15 +68,15 @@ public Source(IConfiguration configuration, DbProviderFactory factory, string co
6868
ParameterPrefix = parameterPrefix;
6969
if (sourceType.Contains("SqlClient"))
7070
{
71-
DatabaseName = Regex.Match(Connection, @"Initial Catalog=([^;]*)").Groups[1].Value;
71+
DatabaseName = Regex.Match(ConnectionString, @"Initial Catalog=([^;]*)").Groups[1].Value;
7272
}
7373
}
7474
}
7575

7676
/// <summary>
7777
/// Connection string
7878
/// </summary>
79-
public string Connection { get; protected set; }
79+
public string ConnectionString { get; protected set; }
8080

8181
/// <summary>
8282
/// Gets the database.

src/SQLHelper.DB/HelperClasses/Interfaces/ISource.cs renamed to src/SQLHelper.DB/HelperClasses/Interfaces/IConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ namespace SQLHelper.HelperClasses.Interfaces
2121
/// <summary>
2222
/// Data source interface
2323
/// </summary>
24-
public interface ISource
24+
public interface IConnection
2525
{
2626
/// <summary>
2727
/// Connection string
2828
/// </summary>
2929
/// <value>The connection.</value>
30-
string Connection { get; }
30+
string ConnectionString { get; }
3131

3232
/// <summary>
3333
/// Gets the database.

src/SQLHelper.DB/SQLHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class SQLHelper
4040
/// <param name="database">The database.</param>
4141
public SQLHelper(IConfiguration configuration, DbProviderFactory factory, string database = "Default")
4242
{
43-
DatabaseSource = new Source(configuration, factory, "", database);
44-
Batch = new Batch(DatabaseSource);
43+
DatabaseConnection = new Connection(configuration, factory, "", database);
44+
Batch = new Batch(DatabaseConnection);
4545
}
4646

4747
/// <summary>
@@ -51,16 +51,16 @@ public SQLHelper(IConfiguration configuration, DbProviderFactory factory, string
5151
public int Count { get { return Batch.CommandCount; } }
5252

5353
/// <summary>
54-
/// Gets the batch.
54+
/// Gets or sets the source.
5555
/// </summary>
56-
/// <value>The batch.</value>
57-
protected IBatch Batch { get; private set; }
56+
/// <value>The source.</value>
57+
public IConnection DatabaseConnection { get; private set; }
5858

5959
/// <summary>
60-
/// Gets or sets the source.
60+
/// Gets the batch.
6161
/// </summary>
62-
/// <value>The source.</value>
63-
protected ISource DatabaseSource { get; private set; }
62+
/// <value>The batch.</value>
63+
protected IBatch Batch { get; private set; }
6464

6565
/// <summary>
6666
/// Adds a command.
@@ -135,7 +135,7 @@ public SQLHelper AddQuery(SQLHelper helper)
135135
/// <returns>This</returns>
136136
public SQLHelper CreateBatch()
137137
{
138-
Batch = new Batch(DatabaseSource);
138+
Batch = new Batch(DatabaseConnection);
139139
return this;
140140
}
141141

test/SQLHelper.Tests/HelperClasses/BatchTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void AddQuery()
1515
var Configuration = new ConfigurationBuilder()
1616
.AddInMemoryCollection()
1717
.Build();
18-
var Instance = new Batch(new Source(Configuration,
18+
var Instance = new Batch(new Connection(Configuration,
1919
SqlClientFactory.Instance,
2020
"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
2121
"DATABASE NAME")
@@ -31,7 +31,7 @@ public void AddQuerys()
3131
var Configuration = new ConfigurationBuilder()
3232
.AddInMemoryCollection()
3333
.Build();
34-
var Instance = new Batch(new Source(Configuration,
34+
var Instance = new Batch(new Connection(Configuration,
3535
SqlClientFactory.Instance,
3636
"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
3737
"DATABASE NAME")
@@ -48,7 +48,7 @@ public void AddQuerysWithParameters()
4848
var Configuration = new ConfigurationBuilder()
4949
.AddInMemoryCollection()
5050
.Build();
51-
var Instance = new Batch(new Source(Configuration,
51+
var Instance = new Batch(new Connection(Configuration,
5252
SqlClientFactory.Instance,
5353
"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
5454
"DATABASE NAME")
@@ -65,7 +65,7 @@ public void AddQueryWithParameters()
6565
var Configuration = new ConfigurationBuilder()
6666
.AddInMemoryCollection()
6767
.Build();
68-
var Instance = new Batch(new Source(Configuration,
68+
var Instance = new Batch(new Connection(Configuration,
6969
SqlClientFactory.Instance,
7070
"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
7171
"DATABASE NAME")
@@ -81,7 +81,7 @@ public void Creation()
8181
var Configuration = new ConfigurationBuilder()
8282
.AddInMemoryCollection()
8383
.Build();
84-
var Instance = new Batch(new Source(Configuration,
84+
var Instance = new Batch(new Connection(Configuration,
8585
SqlClientFactory.Instance,
8686
"Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
8787
"DATABASE NAME")

test/SQLHelper.Tests/HelperClasses/SourceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public void Create()
1414
var Configuration = new ConfigurationBuilder()
1515
.AddInMemoryCollection()
1616
.Build();
17-
var TestItem = new Source(Configuration, SqlClientFactory.Instance, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "DATABASE NAME");
18-
Assert.Equal("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", TestItem.Connection);
17+
var TestItem = new Connection(Configuration, SqlClientFactory.Instance, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "DATABASE NAME");
18+
Assert.Equal("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", TestItem.ConnectionString);
1919
Assert.Equal("TestDatabase", TestItem.DatabaseName);
2020
Assert.Equal(SqlClientFactory.Instance, TestItem.Factory);
2121
Assert.Equal("DATABASE NAME", TestItem.Name);

0 commit comments

Comments
 (0)