Saturday, December 19, 2009

Configuring any call to an object

I’ve just updated the way to configure any call to faked objects in FakeItEasy, the syntax is new and also you can now configure return values.

Let’s say you have an interface providing localized text resources like this:

public interface ILocalizedResources
{
    string SomeText { get; }
    string SomeOtherText { get; }
}

When you fake this interface any of the properties would return null when not configured but you might have several tests that are dependant on that the values are non null strings but still you don’t want to have to configure each individual property in the set up of you fixture. Now you can do exactly that:

var resources = A.Fake<ILocalizedResources>();
Any.CallTo(resources).WithReturnType<string>().Returns("");

Of course you can still configure any call to do anything you want just as before, for example:

var resources = A.Fake<ILocalizedResources>();
Any.CallTo(resources).Throws(new Exception());

 

Technorati-taggar: ,,,,,,

1 comment: