Hi MrFixxiT,
I haven't had any problems when trying to test them. Take a look at this example..
Code:
[TestFixture]
public class when_determining_the_tax_code_for_an_employee_earning_99_for_the_last_year
{
private IPerson person;
private string result;
[SetUp]
public void given()
{
person = MockRepository.GenerateStub<IPerson>();
person.Stub(x => x.earnings_for_the_last_year).Return(99m);
result = person.calculate_code_rate();
}
[Test]
public void it_should_get_the_tax_code_GHYK9()
{
Assert.That(result, Is.EqualTo("GHYK9"));
}
[Test]
public void it_should_ask_the_employee_for_earnings_for_the_last_year()
{
person.AssertWasCalled(x => x.earnings_for_the_last_year);
}
}
public interface IPerson
{
decimal earnings_for_the_last_year { get; }
}
public static class PersonExtensions
{
public static string calculate_code_rate(this IPerson person)
{
if (person.earnings_for_the_last_year > 100)
return "EK9";
else
return "GHYK9";
}
}
I try and tend to use extension methods sparinly now, mostly use them for infrastructure bits and bobs like the below (which is nice and easy to test) to keep noise out of the code..
Code:
public static class ComparisonExtensions
{
public static bool implements_interface<TInterface>(this object object_to_compare)
{
return typeof (TInterface).IsAssignableFrom(object_to_compare.GetType());
}
public static bool is_type_of<TType>(this object object_to_compare)
{
return object_to_compare.GetType() == typeof(TType);
}
}
Does that help? Please let me know if you want some more info.
Cheers
Scottt