public static void Main()
BankAccountNumberHappyTest("12-1234-1234567", "12", "1234", "1234567");
BankAccountNumberNegativeTest("I-AM-NOT-A-VALID-ACCOUNT");
static void BankAccountNumberHappyTest(string input, string expectedBank, string expectedBranch, string expectedStem, string? expectedFormatted = null)
var expectedFormattedString = expectedFormatted ?? input;
Console.WriteLine($"Happy Test: {input} (expects: {expectedBank}, {expectedBranch}, {expectedStem}, {expectedFormattedString})");
var actual = BankAccountNumber.ParseBankAccountNumber(input);
actual.Should().BeEquivalentTo(expected);
actual.ToString().Should().Be(expectedFormattedString);
Console.WriteLine("PASS.\n");
Console.WriteLine("FAIL: " + e.Message);
static void BankAccountNumberNegativeTest(string input)
Console.WriteLine($"Negative Test: {input}");
BankAccountNumber.ParseBankAccountNumber(input);
Console.WriteLine("FAIL: expectedFormatException");
catch(FormatException e) {
var expectedMessage = $"FacilityNumb is not in format 00 - 0000 - 0000000 - 00 - 000. Got '{input}'";
if(e.Message != expectedMessage)
Console.WriteLine($"FAIL: expected FormatException to have message \"{expectedMessage}\", but got \"{e.Message}\"");
Console.WriteLine("PASS.\n");
Console.WriteLine("FAIL: expected FormatException, but got " + e);
Console.WriteLine($"{pass} / {pass + fail} tests passed.\n");
Console.WriteLine(fail == 0 ? "SUCCESS!" : "FAILURE!");
public class BankAccountNumber
protected BankAccountNumber() {}
public string Bank => "12";
public string Branch => "1234";
public string Stem => "1234567";
public static BankAccountNumber ParseBankAccountNumber(string formattedBankAccountNumber)
return new BankAccountNumber();
public override string ToString() {
return "12-1234-1234567";
public class FacilityNumber : BankAccountNumber
private FacilityNumber() : base() {}
public string Suffix => throw new NotImplementedException();
public string PaymentNumber => throw new NotImplementedException();
public static FacilityNumber ParseFacilityNumber(string formattedFacilityNumber)
throw new NotImplementedException();