-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced SsnValidator class; returning ValidationResult instead of …
…bool
- Loading branch information
1 parent
398ac26
commit 0ca8ea7
Showing
10 changed files
with
104 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Adia.SsnValidator.Tests | ||
{ | ||
public class SsnValidatorTests | ||
{ | ||
private SsnValidator _validator; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_validator = new SsnValidator(); | ||
} | ||
|
||
[Test] | ||
public void GivenCorrectSwissArguments_ShouldRunSwissSsnValidation() | ||
{ | ||
var result = _validator.Validate("756.4089.0811.50", CountryCode.CH); | ||
Assert.AreEqual(result, ValidationResult.Valid); | ||
} | ||
|
||
[Test] | ||
public void GivenIncorrectCountryCode_ShouldThrowExceptiom() | ||
{ | ||
Assert.Throws<NotSupportedException>(() => _validator.Validate("756.4089.0811.50", (CountryCode) 100)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Adia.SsnValidator.Tests")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Adia.SsnValidator | ||
{ | ||
public class SsnValidator | ||
{ | ||
public ValidationResult Validate(string ssn, CountryCode country) | ||
{ | ||
var factory = new SsnValidatorFactory(); | ||
var validator = factory.Create(country); | ||
return validator.Validate(ssn); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Adia.SsnValidator | ||
{ | ||
public enum ValidationResult | ||
{ | ||
Valid, | ||
InvalidFormat, | ||
InvalidChecksum | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace Adia.SsnValidator.Validators | ||
{ | ||
public interface IValidator | ||
internal interface IValidator | ||
{ | ||
bool Validate(string ssn); | ||
ValidationResult Validate(string ssn); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Changelog | ||
|
||
## 0.1.0 | ||
|
||
* **BREAKING CHANGE** Changed the main validation class to be `SsnValidator`. This is the only publicly available class in the library. | ||
* `SsnValidator.Validate` returns a `ValidationResult` instance that can be used to determine why an SSN is invalid. | ||
|
||
## 0.0.1 | ||
|
||
Initial version with support for Swiss SSN (AHV). |