Skip to content

Instantly share code, notes, and snippets.

@zsoldosp
Created October 29, 2012 12:10
Show Gist options
  • Save zsoldosp/3973209 to your computer and use it in GitHub Desktop.
Save zsoldosp/3973209 to your computer and use it in GitHub Desktop.
// re: for http://codemanship.co.uk/parlezuml/blog/?postid=1149
// original code, called from inside the method:
Customer customer = DataRepository.GetCustomer(customerId);
// to enable the creation of the regression suite,
// I extract the implementation of DataRepository.GetCustomer into its own methpd
class DataRepository {
public static Customer GetCustomer(customerId) {
return DataRepository.getCustomer(customerId);
}
private static Customer getCustomer(customerId) {
return ...
}
}
// now I change the public static method into a Func<Customer, int> property and
// initialize it to the private method
class DataRepository {
public static Func<Customer, int> GetCustomer = DataRepository.getCustomer;
private static Customer GetCustomer(customerId) {
return ...
}
}
// now I can write the tests using this "StubRepository" implementation
public class StubRepository
{
private readonly Customer customer;
public StubRepository(Customer customer)
{
this.customer = customer;
DataRepository.getCustomer = customerId => customer;
}
}
// once I have the desired regression suite, I just refactor the internals properly to a similar
// implemnetation to Jason Gorman's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment