Parameterized Object Mother in C# as an alternative to Test Data Builder pattern (thanks to named arguments with default values)
public static class AddressObjectMother | |
{ | |
public static Address Create(string street = "", string city = "", PostCode postCode = null) | |
{ | |
if (postCode == null) | |
{ | |
postCode = PostCodeObjectMother.Create(); | |
} | |
return new Address(street, city, postCode); | |
} | |
} |
public static class PostCodeObjectMother | |
{ | |
public static PostCode Create(string postCode = "NL-1000") | |
{ | |
return new PostCode(postCode); | |
} | |
public static PostCode CreateEmpty() | |
{ | |
return new PostCode(); | |
} | |
} |
var address = AddressObjectMother.Create( | |
postCode: PostCodeObjectMother.CreateEmpty() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment