arschr wrote:
You would unit test your code (methods and objects) without external dependencies. So you might unit test (assert) that the predicate expression you built had 1 predicate, had a equals predicate, had a value of a certain value, based on the test values passed to the predicate generating method.
So if my code was refactored to this:
public class UserSearchService : IDisposable
{
private IDataAccessAdapter _adapter;
/// <summary>
/// Initializes a new instance of the UserSearchService class.
/// </summary>
/// <param name="adapter"></param>
public UserSearchService(IDataAccessAdapter adapter)
{
_adapter = adapter;
}
public IEnumerable<UserEntity> GetUserCollection(IPredicateExpression filter)
{
EntityCollection<UserEntity> users = new EntityCollection<UserEntity>();
IRelationPredicateBucket bucket = new RelationPredicateBucket(filter);
_adapter.FetchEntityCollection(users, bucket, 0, null, null, null, 0, 0);
return users;
}
public IPredicate BuildSearchPredicate(keywords)
{
keywords = String.Format("%{0}%", keywords);
IPredicate filter = new PredicateExpression(UserFields.UserName % keywords);
filter.AddWithOr(UserFields.FirstName % keywords);
filter.AddWithOr(UserFields.LastName % keywords);
return filter;
}
public void Dispose()
{
if (_adapter != null)
_adapter.Dispose();
}
}
I can unit test BuildSearchPredicate to make sure the IPredicateExpression has 3 filters and the keywords gets build property, but that doesn't allow me to test GetUserCollection.
Is there no way to test GetUserCollection as a unit test vs integration test?
Story I would like to test:
UserStory wrote:
If I search for the keyword, "Joe", the form will return users that have joe in the Username, FirstName and LastName fields.
Is this an integration test because of the dependency on the database?
Roy Osherove (author of "The Art of Unit Testing") has a good discussion about this on the latest Hanselminutes podcast.
I listened to the podcast too