Skip to content

Commit 503ca6f

Browse files
committed
Updated exception texts, methods descriptions, consolidated params' names and minor code tidying
1 parent 9cdafc6 commit 503ca6f

File tree

15 files changed

+65
-90
lines changed

15 files changed

+65
-90
lines changed

QueryBuilder.Tests/GeneralTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void CompilerSpecificLimit()
291291
var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql };
292292
var c = Compilers.Compile(engines, query);
293293

294-
Assert.Equal(2, query.GetComponents("limit").Count());
294+
Assert.Equal(2, query.GetComponents("limit").Count);
295295
Assert.Equal("SELECT TOP (5) * FROM [mytable]", c[EngineCodes.SqlServer].ToString());
296296
Assert.Equal("SELECT * FROM \"mytable\" LIMIT 10", c[EngineCodes.PostgreSql].ToString());
297297
Assert.Equal("SELECT * FROM `mytable`", c[EngineCodes.MySql].ToString());
@@ -319,7 +319,7 @@ public void CompilerSpecificOffset()
319319
var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql };
320320
var c = Compilers.Compile(engines, query);
321321

322-
Assert.Equal(2, query.GetComponents("offset").Count());
322+
Assert.Equal(2, query.GetComponents("offset").Count);
323323
Assert.Equal("SELECT * FROM `mytable` LIMIT 18446744073709551615 OFFSET 5", c[EngineCodes.MySql].ToString());
324324
Assert.Equal("SELECT * FROM \"mytable\" OFFSET 10", c[EngineCodes.PostgreSql].ToString());
325325
Assert.Equal("SELECT * FROM [mytable]", c[EngineCodes.SqlServer].ToString());

QueryBuilder.Tests/InfrastructureTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void ShouldThrowIfInvalidEngineCode()
4747
[Fact]
4848
public void ShouldThrowIfAnyEngineCodesAreInvalid()
4949
{
50-
var codes = new[] {EngineCodes.SqlServer, "123", EngineCodes.MySql, "abc"};
50+
var codes = new[] { EngineCodes.SqlServer, "123", EngineCodes.MySql, "abc" };
5151
Assert.Throws<InvalidOperationException>(() => Compilers.Compile(codes, new Query()));
5252
}
5353
}

QueryBuilder/Base.Where.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public Q WhereExists(Query query)
526526
{
527527
if (!query.HasComponent("from"))
528528
{
529-
throw new ArgumentException("'FromClause' cannot be empty if used inside a 'WhereExists' condition");
529+
throw new ArgumentException($"'{nameof(FromClause)}' cannot be empty if used inside a '{nameof(WhereExists)}' condition");
530530
}
531531

532532
// remove unneeded components
@@ -573,8 +573,6 @@ public Q OrWhereNotExists(Func<Query, Query> callback)
573573
return Or().Not().WhereExists(callback);
574574
}
575575

576-
577-
578576
#region date
579577
public Q WhereDatePart(string part, string column, string op, object value)
580578
{
@@ -691,6 +689,5 @@ public Q OrWhereNotTime(string column, object value)
691689
}
692690

693691
#endregion
694-
695692
}
696693
}

QueryBuilder/BaseQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public Q SetParent(AbstractQuery parent)
4545
{
4646
if (this == parent)
4747
{
48-
throw new ArgumentException("Cannot set the same query as a parent of itself");
48+
throw new ArgumentException($"Cannot set the same {nameof(AbstractQuery)} as a parent of itself");
4949
}
5050

5151
this.Parent = parent;

QueryBuilder/Clauses/ConditionClause.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public string EscapeCharacter
4848
if (string.IsNullOrWhiteSpace(value))
4949
value = null;
5050
else if (value.Length > 1)
51-
throw new ArgumentOutOfRangeException("The EscapeCharacter can only contain a single character!");
51+
throw new ArgumentOutOfRangeException($"The {nameof(EscapeCharacter)} can only contain a single character!");
5252
escapeCharacter = value;
5353
}
5454
}

QueryBuilder/ColumnAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ public ColumnAttribute(string name)
1212
{
1313
if (string.IsNullOrEmpty(name))
1414
{
15-
throw new ArgumentNullException("Name parameter is required");
15+
throw new ArgumentNullException(nameof(name));
1616
}
1717

1818
Name = name;
1919
}
20-
2120
}
2221

23-
2422
/// <summary>
2523
/// This class is used as metadata on a property to determine if it is a primary key
2624
/// </summary>

QueryBuilder/Compilers/ConditionsCompilerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private MethodInfo FindMethodInfo(Type clauseType, string methodName)
4040

4141
if (methodInfo == null)
4242
{
43-
throw new Exception($"Failed to locate a compiler for {methodName}.");
43+
throw new Exception($"Failed to locate a compiler for '{methodName}'.");
4444
}
4545

4646
if (clauseType.IsConstructedGenericType && methodInfo.GetGenericArguments().Any())

QueryBuilder/Compilers/SqliteCompiler.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCond
4343
var value = Parameter(ctx, condition.Value);
4444

4545
var formatMap = new Dictionary<string, string> {
46-
{"date", "%Y-%m-%d"},
47-
{"time", "%H:%M:%S"},
48-
{"year", "%Y"},
49-
{"month", "%m"},
50-
{"day", "%d"},
51-
{"hour", "%H"},
52-
{"minute", "%M"},
46+
{ "date", "%Y-%m-%d" },
47+
{ "time", "%H:%M:%S" },
48+
{ "year", "%Y" },
49+
{ "month", "%m" },
50+
{ "day", "%d" },
51+
{ "hour", "%H" },
52+
{ "minute", "%M" },
5353
};
5454

5555
if (!formatMap.ContainsKey(condition.Part))
@@ -66,6 +66,5 @@ protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCond
6666

6767
return sql;
6868
}
69-
7069
}
7170
}

QueryBuilder/Query.Having.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public Query HavingExists(Query query)
488488
{
489489
if (!query.HasComponent("from"))
490490
{
491-
throw new ArgumentException("'FromClause' cannot be empty if used inside a 'HavingExists' condition");
491+
throw new ArgumentException($"{nameof(FromClause)} cannot be empty if used inside a {nameof(HavingExists)} condition");
492492
}
493493

494494
// simplify the query as much as possible

QueryBuilder/Query.Insert.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public partial class Query
99
{
1010
public Query AsInsert(object data, bool returnId = false)
1111
{
12-
var dictionary = BuildKeyValuePairsFromObject(data);
12+
var propertiesKeyValues = BuildKeyValuePairsFromObject(data);
1313

14-
return AsInsert(dictionary, returnId);
14+
return AsInsert(propertiesKeyValues, returnId);
1515
}
1616

1717
public Query AsInsert(IEnumerable<string> columns, IEnumerable<object> values)
@@ -21,12 +21,12 @@ public Query AsInsert(IEnumerable<string> columns, IEnumerable<object> values)
2121

2222
if ((columnsList?.Count ?? 0) == 0 || (valuesList?.Count ?? 0) == 0)
2323
{
24-
throw new InvalidOperationException("Columns and Values cannot be null or empty");
24+
throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty");
2525
}
2626

2727
if (columnsList.Count != valuesList.Count)
2828
{
29-
throw new InvalidOperationException("Columns count should be equal to Values count");
29+
throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty");
3030
}
3131

3232
Method = "insert";
@@ -40,19 +40,19 @@ public Query AsInsert(IEnumerable<string> columns, IEnumerable<object> values)
4040
return this;
4141
}
4242

43-
public Query AsInsert(IEnumerable<KeyValuePair<string, object>> data, bool returnId = false)
43+
public Query AsInsert(IEnumerable<KeyValuePair<string, object>> values, bool returnId = false)
4444
{
45-
if (data == null || data.Any() == false)
45+
if (values == null || values.Any() == false)
4646
{
47-
throw new InvalidOperationException("Values dictionary cannot be null or empty");
47+
throw new InvalidOperationException($"{values} argument cannot be null or empty");
4848
}
4949

5050
Method = "insert";
5151

5252
ClearComponent("insert").AddComponent("insert", new InsertClause
5353
{
54-
Columns = data.Select(x=>x.Key).ToList(),
55-
Values = data.Select(x => x.Value).ToList(),
54+
Columns = values.Select(x=>x.Key).ToList(),
55+
Values = values.Select(x => x.Value).ToList(),
5656
ReturnId = returnId,
5757
});
5858

@@ -63,16 +63,16 @@ public Query AsInsert(IEnumerable<KeyValuePair<string, object>> data, bool retur
6363
/// Produces insert multi records
6464
/// </summary>
6565
/// <param name="columns"></param>
66-
/// <param name="valuesCollection"></param>
66+
/// <param name="rowsValues"></param>
6767
/// <returns></returns>
68-
public Query AsInsert(IEnumerable<string> columns, IEnumerable<IEnumerable<object>> valuesCollection)
68+
public Query AsInsert(IEnumerable<string> columns, IEnumerable<IEnumerable<object>> rowsValues)
6969
{
7070
var columnsList = columns?.ToList();
71-
var valuesCollectionList = valuesCollection?.ToList();
71+
var valuesCollectionList = rowsValues?.ToList();
7272

7373
if ((columnsList?.Count ?? 0) == 0 || (valuesCollectionList?.Count ?? 0) == 0)
7474
{
75-
throw new InvalidOperationException("Columns and valuesCollection cannot be null or empty");
75+
throw new InvalidOperationException($"{nameof(columns)} and {nameof(rowsValues)} cannot be null or empty");
7676
}
7777

7878
Method = "insert";
@@ -84,7 +84,7 @@ public Query AsInsert(IEnumerable<string> columns, IEnumerable<IEnumerable<objec
8484
var valuesList = values.ToList();
8585
if (columnsList.Count != valuesList.Count)
8686
{
87-
throw new InvalidOperationException("Columns count should be equal to each Values count");
87+
throw new InvalidOperationException($"{nameof(columns)} count should be equal to each {nameof(rowsValues)} entry count");
8888
}
8989

9090
AddComponent("insert", new InsertClause
@@ -115,6 +115,5 @@ public Query AsInsert(IEnumerable<string> columns, Query query)
115115

116116
return this;
117117
}
118-
119118
}
120119
}

0 commit comments

Comments
 (0)