-
Notifications
You must be signed in to change notification settings - Fork 33
Test helpers
Martijn Bodeman edited this page Jun 7, 2023
·
8 revisions
Use the IbanGenerator
class to generate random IBAN's. The IBAN's generated will adhere to the country specific rules and have valid check digits. While the IBAN produced will pass validation, it may not be an actual valid bank account and - for obvious reasons - should ONLY be used for testing purposes.
If you are instead looking for a way to 'build' an IBAN from a BBAN, have a look here.
There are a few ways to generate an IBAN:
public class TestClass
{
[Fact]
public void MyTest()
{
var generator = new IbanGenerator();
Iban iban = generator.Generate("NL");
// Act
// use the generated IBAN...
}
}
public class TestClass
{
[Fact]
public void MyTest()
{
var generator = new IbanGenerator(new IbanRegistry { /* custom providers */ });
Iban iban = generator.Generate("NL");
}
}
At runtime, when using one of the DI integration packages, you can also request an instance of IIbanGenerator
.
public class MyClass
{
public MyClass(IIbanGenerator generator)
{
_generator = generator;
}
public void Hello()
{
Iban iban = _generator.Generate("NL")
}
}
Check out this fiddle for a working example.