@@ -183,9 +183,9 @@ public void ComputeLuhnNumber_ValidRawNumber_ReturnsExpectedLuhnNumber(
183
183
/// </summary>
184
184
/// <param name="expectedResult">The expected validation result</param>
185
185
/// <param name="luhnNumber">Test number inclusive check digit</param>
186
- [ Theory ( DisplayName = "Validates a number containing a check digit " ) ]
186
+ [ Theory ( DisplayName = "Validates a valid Luhn number " ) ]
187
187
[ MemberData ( nameof ( LuhnNumberValidationSet ) , MemberType = typeof ( LuhnTest ) ) ]
188
- public void LuhnNumberValidationTest ( bool expectedResult , string luhnNumber )
188
+ public void IsValidLuhnNumber_ValidLuhnNumber_ReturnsExpectedResult ( bool expectedResult , string luhnNumber )
189
189
{
190
190
Assert . Equal ( expectedResult , luhnNumber . IsValidLuhnNumber ( ) ) ;
191
191
Assert . Equal ( expectedResult , luhnNumber . AsSpan ( ) . IsValidLuhnNumber ( ) ) ;
@@ -197,9 +197,12 @@ public void LuhnNumberValidationTest(bool expectedResult, string luhnNumber)
197
197
/// <param name="expectedResult">Expected validation result</param>
198
198
/// <param name="number">Test number exclusive check digit</param>
199
199
/// <param name="checkDigit">Test Luhn check digit</param>
200
- [ Theory ( DisplayName = "Validates a number with separate check digit between 0 and 9" ) ]
200
+ [ Theory ( DisplayName = "Validates a valid number with separate, valid check digit between 0 and 9" ) ]
201
201
[ MemberData ( nameof ( LuhnCheckDigitValidationSet ) , MemberType = typeof ( LuhnTest ) ) ]
202
- public void LuhnCheckDigitValidationTest ( bool expectedResult , string number , byte checkDigit )
202
+ public void IsValidLuhnCheckDigit_ValidNumberAndCheckDigit_ReturnsExpectedResult (
203
+ bool expectedResult ,
204
+ string number ,
205
+ byte checkDigit )
203
206
{
204
207
Assert . Equal ( expectedResult , checkDigit . IsValidLuhnCheckDigit ( number ) ) ;
205
208
Assert . Equal ( expectedResult , checkDigit . IsValidLuhnCheckDigit ( number . AsSpan ( ) ) ) ;
@@ -212,10 +215,10 @@ public void LuhnCheckDigitValidationTest(bool expectedResult, string number, byt
212
215
/// <param name="invalidNumber">Invalid raw number</param>
213
216
[ Theory ( DisplayName = "Calculates the check digit for an invalid raw number to throw an exception" ) ]
214
217
[ MemberData ( nameof ( InvalidNumbers ) , MemberType = typeof ( LuhnTest ) ) ]
215
- public void ComputeLuhnCheckDigit_InvalidRawNumber_ThrowsArgumentException ( string invalidNumber )
218
+ public void ComputeLuhnCheckDigit_InvalidRawNumber_ThrowsInvalidCharacterException ( string invalidNumber )
216
219
{
217
- Assert . Throws < ArgumentException > ( ( ) => invalidNumber . ComputeLuhnCheckDigit ( ) ) ;
218
- Assert . Throws < ArgumentException > ( ( ) => invalidNumber . AsSpan ( ) . ComputeLuhnCheckDigit ( ) ) ;
220
+ Assert . Throws < InvalidCharacterException > ( ( ) => invalidNumber . ComputeLuhnCheckDigit ( ) ) ;
221
+ Assert . Throws < InvalidCharacterException > ( ( ) => invalidNumber . AsSpan ( ) . ComputeLuhnCheckDigit ( ) ) ;
219
222
}
220
223
221
224
/// <summary>
@@ -225,10 +228,10 @@ public void ComputeLuhnCheckDigit_InvalidRawNumber_ThrowsArgumentException(strin
225
228
/// <param name="invalidNumber">Invalid raw number</param>
226
229
[ Theory ( DisplayName = "Calculates the Luhn number for an invalid raw number to throw an exception" ) ]
227
230
[ MemberData ( nameof ( InvalidNumbers ) , MemberType = typeof ( LuhnTest ) ) ]
228
- public void ComputeLuhnNumber_InvalidRawNumber_ThrowsArgumentException ( string invalidNumber )
231
+ public void ComputeLuhnNumber_InvalidRawNumber_ThrowsInvalidCharacterException ( string invalidNumber )
229
232
{
230
- Assert . Throws < ArgumentException > ( invalidNumber . ComputeLuhnNumber ) ;
231
- Assert . Throws < ArgumentException > ( ( ) => invalidNumber . AsSpan ( ) . ComputeLuhnNumber ( ) ) ;
233
+ Assert . Throws < InvalidCharacterException > ( invalidNumber . ComputeLuhnNumber ) ;
234
+ Assert . Throws < InvalidCharacterException > ( ( ) => invalidNumber . AsSpan ( ) . ComputeLuhnNumber ( ) ) ;
232
235
}
233
236
234
237
/// <summary>
@@ -237,22 +240,23 @@ public void ComputeLuhnNumber_InvalidRawNumber_ThrowsArgumentException(string in
237
240
/// </summary>
238
241
[ Theory ( DisplayName = "Validates an invalid Luhn number (e.g. none-numeric characters) to throw an exception" ) ]
239
242
[ MemberData ( nameof ( InvalidNumbers ) , MemberType = typeof ( LuhnTest ) ) ]
240
- public void LuhnNumberValidationExceptionTest ( string invalidNumber )
243
+ public void IsValidLuhnNumber_InvalidInput_ThrowsInvalidCharacterException ( string invalidNumber )
241
244
{
242
- Assert . Throws < ArgumentException > ( ( ) => invalidNumber . IsValidLuhnNumber ( ) ) ;
243
- Assert . Throws < ArgumentException > ( ( ) => invalidNumber . AsSpan ( ) . IsValidLuhnNumber ( ) ) ;
245
+ Assert . Throws < InvalidCharacterException > ( ( ) => invalidNumber . IsValidLuhnNumber ( ) ) ;
246
+ Assert . Throws < InvalidCharacterException > ( ( ) => invalidNumber . AsSpan ( ) . IsValidLuhnNumber ( ) ) ;
244
247
}
245
248
246
249
/// <summary>
247
- /// Tests whether an exception is thrown when an invalid number and a valid check digit between 0 and 9
248
- /// is passed to the Luhn validation algorithm.
250
+ /// Tests whether an exception is thrown when an invalid number is passed to the Luhn validation algorithm.
249
251
/// </summary>
250
252
[ Theory ( DisplayName = "Validates an invalid number with any check digit between 0 and 9 to throw an exception" ) ]
251
253
[ MemberData ( nameof ( InvalidNumbersAndCheckDigits ) , MemberType = typeof ( LuhnTest ) ) ]
252
- public void NumberValidationExceptionTest ( string invalidNumber , byte checkDigit )
254
+ public void IsValidLuhnCheckDigit_InvalidInput_ThrowsInvalidCharacterException (
255
+ string invalidNumber ,
256
+ byte checkDigit )
253
257
{
254
- Assert . Throws < ArgumentException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber ) ) ;
255
- Assert . Throws < ArgumentException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber . AsSpan ( ) ) ) ;
258
+ Assert . Throws < InvalidCharacterException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber ) ) ;
259
+ Assert . Throws < InvalidCharacterException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber . AsSpan ( ) ) ) ;
256
260
}
257
261
258
262
/// <summary>
@@ -261,7 +265,9 @@ public void NumberValidationExceptionTest(string invalidNumber, byte checkDigit)
261
265
/// </summary>
262
266
[ Theory ( DisplayName = "Validates a number with separate check digit greater than 9 to throw an exception" ) ]
263
267
[ MemberData ( nameof ( NumbersWithInvalidCheckDigits ) , MemberType = typeof ( LuhnTest ) ) ]
264
- public void LuhnCheckDigitValidationExceptionTest ( string invalidNumber , byte checkDigit )
268
+ public void IsValidLuhnCheckDigit_InvalidInput_ThrowsArgumentOutOfRangeException (
269
+ string invalidNumber ,
270
+ byte checkDigit )
265
271
{
266
272
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber ) ) ;
267
273
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => checkDigit . IsValidLuhnCheckDigit ( invalidNumber . AsSpan ( ) ) ) ;
@@ -270,7 +276,7 @@ public void LuhnCheckDigitValidationExceptionTest(string invalidNumber, byte che
270
276
/// <summary>
271
277
/// Test data for AlphaNumericToNumeric method.
272
278
/// </summary>
273
- public static IEnumerable < object [ ] > ConvertAlphaNumericToNumericData =>
279
+ public static IEnumerable < object [ ] > AlphaNumericToNumericData =>
274
280
new List < object [ ] >
275
281
{
276
282
new object [ ] { "A1B2C3" , "101112123" } ,
@@ -287,8 +293,8 @@ public void LuhnCheckDigitValidationExceptionTest(string invalidNumber, byte che
287
293
/// <param name="input">Input string</param>
288
294
/// <param name="expected">Expected output</param>
289
295
[ Theory ( DisplayName = "Converts an alphanumeric string to a numeric string" ) ]
290
- [ MemberData ( nameof ( ConvertAlphaNumericToNumericData ) , MemberType = typeof ( LuhnTest ) ) ]
291
- public void ConvertAlphaNumericToNumeric_ShouldReturnExpectedResult ( string input , string expected )
296
+ [ MemberData ( nameof ( AlphaNumericToNumericData ) , MemberType = typeof ( LuhnTest ) ) ]
297
+ public void AlphaNumericToNumeric_ValidInput_ShouldReturnExpectedResult ( string input , string expected )
292
298
{
293
299
Assert . Equal ( expected , input . AlphaNumericToNumeric ( ) ) ;
294
300
}
@@ -302,9 +308,9 @@ public void ConvertAlphaNumericToNumeric_ShouldReturnExpectedResult(string input
302
308
/// xUnit to check if the expected exception is thrown.
303
309
/// </remarks>
304
310
[ Fact ( DisplayName = "Converts an invalid alphanumeric string to a numeric string to throw an exception" ) ]
305
- public void ConvertAlphaNumericToNumeric_InvalidInput_ThrowsArgumentException ( )
311
+ public void AlphaNumericToNumeric_InvalidInput_ThrowsInvalidCharacterException ( )
306
312
{
307
- Assert . Throws < ArgumentException > ( ( ) => "!@#$%^&*()" . AlphaNumericToNumeric ( ) ) ;
313
+ Assert . Throws < InvalidCharacterException > ( ( ) => "!@#$%^&*()" . AlphaNumericToNumeric ( ) ) ;
308
314
}
309
315
310
316
/// <summary>
@@ -328,7 +334,7 @@ public void ConvertAlphaNumericToNumeric_InvalidInput_ThrowsArgumentException()
328
334
/// <param name="expected">Expected output</param>
329
335
[ Theory ( DisplayName = "Validates a numeric string converted from an alphanumeric string" ) ]
330
336
[ MemberData ( nameof ( IsValidWithConvertData ) , MemberType = typeof ( LuhnTest ) ) ]
331
- public void IsValidWithConvertTest ( string input , bool expected )
337
+ public void IsValidLuhnNumber_WithAlphaNumericToNumeric_ReturnsExpectedCheckDigit ( string input , bool expected )
332
338
{
333
339
Assert . Equal ( expected , input . AlphaNumericToNumeric ( ) . IsValidLuhnNumber ( ) ) ;
334
340
Assert . Equal ( expected , input . AlphaNumericToNumeric ( ) . AsSpan ( ) . IsValidLuhnNumber ( ) ) ;
@@ -366,7 +372,7 @@ public void IsValidWithConvertTest(string input, bool expected)
366
372
/// </remarks>
367
373
[ Theory ( DisplayName = "Calculates the check digit for a valid alphanumeric string" ) ]
368
374
[ MemberData ( nameof ( ComputeLuhnCheckDigitWithConvertData ) , MemberType = typeof ( LuhnTest ) ) ]
369
- public void ComputeLuhnCheckDigit_WithConvertAlphaNumericToNumeric_ReturnsExpectedCheckDigit (
375
+ public void ComputeLuhnCheckDigit_WithAlphaNumericToNumeric_ReturnsExpectedCheckDigit (
370
376
string input ,
371
377
byte expected )
372
378
{
0 commit comments