Last active
April 20, 2020 18:27
-
-
Save pellared/a31b6955af5c61a56a277a50606c3410 to your computer and use it in GitHub Desktop.
Parameterized Object Mother in C# as an alternative to Test Data Builder pattern (thanks to named arguments with default values)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class PostCodeObjectMother | |
{ | |
public static PostCode Create(string postCode = "NL-1000") | |
{ | |
return new PostCode(postCode); | |
} | |
public static PostCode CreateEmpty() | |
{ | |
return new PostCode(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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