Skip to content

Commit bbc25b1

Browse files
committed
Document. Minor refactor.
1 parent 20a3487 commit bbc25b1

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

PSql.Tests/Tests.Unit/NewSqlContextCommandTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ public void ServerName_Override_Valid(string expression, string? value)
172172

173173
public static IEnumerable<Case> InvalidPortCases = new[]
174174
{
175-
new Case("''", @"Cannot validate argument on parameter 'ServerPort'. The value ""0"" is not a positive number."),
176-
new Case("0", @"Cannot validate argument on parameter 'ServerPort'. The value ""0"" is not a positive number."),
175+
new Case("''", @"Cannot validate argument on parameter 'ServerPort'. The value ""0"" is not a number between 1 and 65535, inclusive."),
176+
new Case("0", @"Cannot validate argument on parameter 'ServerPort'. The value ""0"" is not a number between 1 and 65535, inclusive."),
177177
new Case("-1", @"Cannot bind parameter 'ServerPort'. Cannot convert value """ + @"-1"" to type ""System.UInt16"". Error: ""Value was either too large or too small for a UInt16."""),
178178
new Case("65536", @"Cannot bind parameter 'ServerPort'. Cannot convert value """ + @"65536"" to type ""System.UInt16"". Error: ""Value was either too large or too small for a UInt16.""")
179179
};
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
// Copyright Subatomix Research Inc.
22
// SPDX-License-Identifier: MIT
33

4-
// TODO: Document
5-
#pragma warning disable CS1591
6-
74
namespace PSql;
85

6+
/// <summary>
7+
/// Validates that a parameter is either <see langword="null"/> or a positive
8+
/// <see langword="ushort"/> value.
9+
/// </summary>
10+
/// <remarks>
11+
/// Valid values range from <c>1</c> to <c>65535</c>.
12+
/// </remarks>
913
public class ValidateNullOrPositiveUInt16Attribute : ValidateArgumentsAttribute
1014
{
11-
protected override void Validate(object arg, EngineIntrinsics engine)
15+
/// <inheritdoc/>
16+
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
1217
{
13-
if (arg is null)
18+
// NOTE: 'arguments' is a single argument, despite the plural name.
19+
20+
if (arguments is null)
1421
return;
1522

16-
if (arg is PSObject psObject)
17-
arg = psObject.BaseObject;
23+
if (arguments is PSObject psObject)
24+
arguments = psObject.BaseObject;
1825

19-
var value = LanguagePrimitives.ConvertTo<ushort>(arg);
26+
var value = LanguagePrimitives.ConvertTo<ushort>(arguments);
2027

2128
if (value < 1)
2229
throw new ValidationMetadataException(string.Format(
23-
@"The value ""{0}"" is not a positive number.", arg
30+
@"The value ""{0}"" is not a number between 1 and 65535, inclusive.", arguments
2431
));
2532
}
2633
}
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
// Copyright Subatomix Research Inc.
22
// SPDX-License-Identifier: MIT
33

4-
// TODO: Document
5-
#pragma warning disable CS1591
6-
74
namespace PSql;
85

6+
/// <summary>
7+
/// Validates that a parameter is either <see langword="null"/> or a valid
8+
/// timeout value.
9+
/// </summary>
10+
/// <remarks>
11+
/// Valid timeouts range from <c>00:00:00</c> to <c>24855.03:14:07</c>.
12+
/// </remarks>
913
public class ValidateNullOrTimeoutAttribute : ValidateArgumentsAttribute
1014
{
1115
private const long
12-
MinValueTicks = 0L,
13-
MaxValueTicks = 2147483647_0000000L;
16+
MinValueTicks = 0 * TimeSpan.TicksPerSecond, // 00:00:00
17+
MaxValueTicks = int.MaxValue * TimeSpan.TicksPerSecond; // 24855.03:14:07
1418

15-
protected override void Validate(object arg, EngineIntrinsics engine)
19+
/// <inheritdoc/>
20+
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
1621
{
17-
if (arg is null)
22+
// NOTE: 'arguments' is a single argument, despite the plural name.
23+
24+
if (arguments is null)
1825
return;
1926

20-
if (arg is PSObject psObject)
21-
arg = psObject.BaseObject;
27+
if (arguments is PSObject psObject)
28+
arguments = psObject.BaseObject;
2229

23-
var value = LanguagePrimitives.ConvertTo<TimeSpan>(arg);
30+
var value = LanguagePrimitives.ConvertTo<TimeSpan>(arguments);
2431
var ticks = value.Ticks;
2532

2633
if (ticks < MinValueTicks)
2734
throw new ValidationMetadataException(string.Format(
28-
@"The value ""{0}"" is negative. Negative timeouts are not supported.", arg
35+
@"The value ""{0}"" is negative. Negative timeouts are not supported.", arguments
2936
));
3037

3138
if (ticks > MaxValueTicks)
3239
throw new ValidationMetadataException(string.Format(
33-
@"The value ""{0}"" exceeds the maximum supported timeout, 24855.03:14:07.", arg
40+
@"The value ""{0}"" exceeds the maximum supported timeout, 24855.03:14:07.", arguments
3441
));
3542
}
3643
}

0 commit comments

Comments
 (0)