Skip to content

Instantly share code, notes, and snippets.

@kaldas
Last active February 22, 2017 15:34
Show Gist options
  • Save kaldas/559454d9daea1d5598863684a2d67c2f to your computer and use it in GitHub Desktop.
Save kaldas/559454d9daea1d5598863684a2d67c2f to your computer and use it in GitHub Desktop.
[TestFixture]
public class IdVerificationTests
{
[Test,TestCaseSource(typeof(IdVerificationTestFactory), nameof(IdVerificationTestFactory.ItShouldVerifyTheseCustomers))]
public void Should_verify_customer_identity(Customer customer, Country country,
bool responseCode)
{
given_an_idverification_request(customer, country);
when_idverification_is_requested();
then_it_should_have_verified_customer(responseCode);
}
}
public class IdVerificationTestFactory
{
public static IEnumerable ItShouldVerifyTheseCustomers
{
get
{
foreach (var customer in CustomerRepository.GetAllVerifiableCustomers())
{
var country = CountryRepository.GetCountry(customer.AddressAlpha2IsoCountryCode);
yield return new TestCaseBuilder()
.ItShouldReturnTrue()
.WithCustomer(customer)
.FromCountry(country)
.Build();
}
}
}
}
public class TestCaseBuilder
{
private Customer _customer;
private Country _country;
private string _testName;
private bool _expectedValue;
public TestCaseBuilder ItShouldReturnTrue()
{
_expectedValue = true;
_testName = "It_should_return_true";
return this;
}
public TestCaseBuilder ItShouldReturnFalse()
{
_expectedValue = false;
_testName = "It_should_return_false";
return this;
}
public TestCaseBuilder WithCustomer(Customer customer)
{
_customer = customer;
_testName += "_for_customer_" + customer.FirstName;
return this;
}
public TestCaseBuilder FromCountry(Country country)
{
_country = country;
_testName += "_for_country_" + country.Alpha2IsoCountryCode;
return this;
}
public TestCaseData Build()
{
return new TestCaseData(_customer, _country, _expectedValue).SetName(_testName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment