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. »

Speaking at Richmond Code Camp on NHibernate

On October 3rd, I encourage anyone who wants to learn about NHibernate to come to Richmond Code Camp. I will be giving a 100 level talk describing how to get started using it, and what it really is. My initial idea is to create a fairly simple ASP.NET MVC application without persistence (use in memory Lists). And, in an hour, make it 100% persisted with transactions, lazy loading, etc. I am a little concerned it will be hard to teach NHibernate and get it done in an hour, but I am going to go for it. »

PSDefaultVariablizer revisted

A couple of days ago, I had a random post about _PSDefaultVariablizer _because I thought the name was funny. Well, I did some pretty hardcore refactoring of the class, and am pretty happy with the outcome. Overall, I think it is 100x better. Check it out. public class PSDefaultVariablizer<t> where T: class { T innerValue; IList<func<t>> defaultValues; public PSDefaultVariablizer(params Func<t>[] _defaultValues) { defaultValues = _defaultValues.ToList(); defaultValues.Insert(0, () => this.innerValue); } public T Value { get { return defaultValues.Select(v => v.Invoke()) .Where(v => v != null) .FirstOrDefault(); } set { innerValue = value; } } } //I am using it in a cmdlet similar to this [Cmdlet("Some", "Command")] public class SomeCommand : PSCmdlet { private PSDefaultVariablizer<string> someParam; public SomeCommand () { someParam = new PSDefaultVariablizer<string>(() => (string)this.SessionState.PSVariable.GetValue("SomeParam", null)); } [Parameter()] public string SomeParam { get { return someParam.Value; } set { someParam.Value = value; } } } Thought it was cool to use Lamba’s to eliminate an entire dependency. »

PSDefaultVariablizer - I didn't know what else to name it!

public class PSDefaultVariablizer where T: class { string variableName; T innerValue; PSCmdlet cmdlet; public PSDefaultVariablizer(string _variableName, PSCmdlet _cmdlet) : this(_variableName, null, _cmdlet) { } public PSDefaultVariablizer(string _variableName, T _innerValue, PSCmdlet _cmdlet) { variableName = _variableName; innerValue = _innerValue; cmdlet = _cmdlet; } public T Value { get { if(innerValue != null) { return innerValue; } else { return (T)cmdlet.SessionState.PSVariable.GetValue(variableName, null); } } set { innerValue = value; } } } Here is the use case for the class. »

Using Windows Live Writer to publish this post

I downloaded Windows Live Writer today and am using it to publish this post. Why Live Writer and not the Wordpress interface? No real reason. The nice thing about live writer is I get the benefits of using a desktop app instead of a web app. It is faster, can work offline, and HTML editing is a bit easier (yes, I am a web developer but it is nice to work a layer above HTML sometimes). »

Don't let developers sell themselves short

Good developers have a tendency to learn, which creates a problem. Everything they did yesterday, they want to rewrite to be better. They are NEVER content with their code! To make things even harder, most developers are pessimists and always make the current state of any application worse than it really is. While these are actually great traits for their role, it can be easy to let developers sell themselves short and miss working on something great in favor of improving the old. »

First thoughts on Kanban

The project managers, and some of my team leads, have started throwing out the idea of Kanban instead of Scrum. Really, they are wanting to start with Scrumban, where they ease into Kanban and as Rex likes to say, “kick the ends out of Scrum”. One of my teams has started playing with it. Here are my initial thoughts. I don’t feel bad about pushing important things into a sprint that are a high priority. »

Scheduled Tasks in Powershell, Alpha

Scheduled tasks don’t have any good way to be edited in Powershell, at least from what I have seen. The other day I set out to write some scripts to help me out. This isn’t really cleaned up or final (aka I haven’t figured out the best error checking yet and it could use a decent refactoring), but I figured I would go ahead and throw them up here to get some feedback. »

Powershell and Grep

I am running Powershell V2 and needed to look through some log files from a bunch of different servers. Powershell V2 and this article showed me the light. gci -recurse | gc | select-string -context 50 "some string to match" > results.txt The context parameter is a Powershell V2 addition that helps give lines above and below the matched string. Select-String is slowly becoming the grep I need in Windows. »

4 Wikipedia Entry Must Reads

You have probably heard of all these before, but they are simple adages that are hilarious, yet surprisingly true. Enjoy. Parkinson’s Law Peter Principle Hofstadter’s Law Student Syndrome »

Brian Hartsock