Really nerdy chat room

Here is an excerpt from my team’s chat room today: (4:31:42 PM) brian.hartsock: i saw a good blog post on how to reuse moq verification steps somewhere (4:31:43 PM) brian.hartsock: http://blog.brianhartsock.com/2009/09/01/using-extension-methods-to-clean-up-mocks-moq/ (4:31:45 PM) brian.hartsock: oh there it is :) (4:34:39 PM) kendall: I don’t know…is self-promotion allowed in the group chat room? ;-) (4:37:40 PM) kevin: I promote myself to Supreme Ruler. (4:40:46 PM) jake: as long as you don’t »

Brian Hartsock on #MoQ,

Using Extension Methods to clean up Mocks (MoQ)

Mock’s can quickly become an ugly beast. They require lots of complex setup and verification. I have had good luck with using extension methods to simplify the complexity. Assume we have the following code to implement our data layer on top of some ReST API. public interface IWebClient { string DownloadString(string url); string UploadValues(string method, string address, NameValueCollection data); } public class WebClientWrapper : IWebClient { private WebClient client; public WebClientWrapper() { client = new WebClient(); } public string DownloadString(string url) { return client.DownloadString(url); } public string UploadValues(string method, string address, NameValueCollection data) { return Encoding.UTF8.GetString(client.UploadValues(address, method, data)); } } In the business/domain layer, we have a class that uses IWebClient to get some information from the API. »