Suggestion for TestHelperExtensions

Jun 24, 2010 at 9:41 PM
Edited Jun 24, 2010 at 9:42 PM
I've been following up on you guys for quite some time, great work by the way.

During a little sandboxing with WCHM I've decided to switch the usual extensions methods StubFindAll and StubFindOne that we're used in testing to the following extension methods:

public static IMethodOptions<TDomainObjectType> StubFindOneWithSpecification<TDomainObjectType>(this ILinqRepository<TDomainObjectType> repository, IQueryable<TDomainObjectType> elements, QuerySpecification<TDomainObjectType> specification)
        {
            return repository.Stub(x => x.FindOne(specification)).IgnoreArguments().Return(specification.SatisfyingElementsFrom(elements).SingleOrDefault());
        }

        public static IMethodOptions<IQueryable<TDomainObjectType>> StubFindAllWithSpecification<TDomainObjectType>(this ILinqRepository<TDomainObjectType> repository, IQueryable<TDomainObjectType> elements, QuerySpecification<TDomainObjectType> specification)
        {
            return repository.Stub(x => x.FindAll(specification)).IgnoreArguments().Return(specification.SatisfyingElementsFrom(elements));
        }

So a test that had:

the_tag_repository.StubFindAll().Return(the_matching_tags);

I switchted to:

the_tag_repository.StubFindAllWithSpecification(the_matching_tags,new TagByFirstCharactersOfNameSpecification(the_starting_characters);

The reason for such was I wasn't comfortable with my tests passing but didn't perfoming as I read them (logically) when it came to the specifications.

Is there anything wrong with this approach? (I'm new to TDD and BDD)