Skip to content

Commit

Permalink
Add option to generate strict VIN (exclusive characters I, O and Q) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer authored Jan 14, 2024
1 parent f6aa3d7 commit 9a30883
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Source/Bogus.Tests/DataSetTests/VehicleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public void cannot_return_vin_bigger_than_17_chars()
vehicle.Vin().Should().HaveLength(17).And.Be("XTVJ5JFU2YBV99999");
}

[Fact]
public void can_get_a_strict_vin_number()
{
vehicle.Vin(true).Should().Be("K3TM1L1NF9Y575714");
}

[Fact]
public void can_get_a_manufacture()
{
Expand Down
20 changes: 16 additions & 4 deletions Source/Bogus/DataSets/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ namespace Bogus.DataSets;
/// </summary>
public class Vehicle : DataSet
{
private const string StrictUpperCase = "ABCDEFGHJKLMNPRSTUVWXYZ";
private const string StrictAlphaNumericUpperCase = Chars.Numbers + StrictUpperCase;

/// <summary>
/// Generate a vehicle identification number (VIN).
/// </summary>
public string Vin()
/// <param name="strict">Limits the acceptable characters to alpha numeric uppercase except I, O and Q.</param>
public string Vin(bool strict = false)
{
var sb = new StringBuilder();

sb.Append(this.Random.String2(10, Chars.AlphaNumericUpperCase));
sb.Append(this.Random.String2(1, Chars.UpperCase));
sb.Append(this.Random.String2(1, Chars.AlphaNumericUpperCase));
var allowedUpperCase = Chars.UpperCase;
var allowedAlphaNumericChars = Chars.AlphaNumericUpperCase;
if (strict)
{
allowedUpperCase = StrictUpperCase;
allowedAlphaNumericChars = StrictAlphaNumericUpperCase;
}

sb.Append(this.Random.String2(10, allowedAlphaNumericChars));
sb.Append(this.Random.String2(1, allowedUpperCase));
sb.Append(this.Random.String2(1, allowedAlphaNumericChars));
sb.Append(this.Random.Number(min: 10000, max: 99999));

return sb.ToString();
Expand Down

0 comments on commit 9a30883

Please sign in to comment.