2013-10-03

Evolution of a handrolled fake - part 5

As you may know if you followed my blog before; I like to roll my own fake. For interfaces it is pretty straight forward with explicit implementation of the interface and properties with delegates for implementation.

However when I was working on the stream assembly in my toolbox I needed a fake stream for some testing. Stream is an abstract class so implementing method explicitly does not work. Nor did I want to clutter my fake with a bunch of fake handlers for implementation.

So what I did was that I created a nested class in my FakeStream called FakeBehaviors and I named the property Behaviors. That way I can do neat things like:

var fakeStream = new FakeStream();
fakeStream.Behaviors.CanRead = true;

I think it reads pretty neat and is a nice way to keep my fake uncluttered when I work with it. You can find all the code in the toolbox project.

No comments:

Post a Comment