Toran Billups
Toran Billups

Reputation: 27399

Any point in writing integration tests for a repository w/ NHibernate?

I recently spent a great deal of time pulling out a stored procedure back-end and replaced it with a NHiberante base repository. One test per repository was nice in the stored procedure version because I could verify my stored procedures worked and the class that mapped the returned data to my objects did it's job.

But after I got this up and running with NHibernate I thought to myself "is this really needed?". After all, NHibernate has unit tests all its own to make sure the session knows how to do dirty tracking/mapping work/etc

Am I missing something here or should I toss these tests that offer no real value?

(sample of a repository I would exercise during this integration test)

public class UserRepository : NHibernateRepository<User>, IUserRepository
{
    public UserRepository() : base()
    {
    }

    public void DeleteUser(User User)
    {
        base.Delete(User);
    }

    public User GetUserById(int id)
    {
        return base.Retrieve(id);
    }

    public IQueryable<User> GetUserCollection()
    {
        return base.RetrieveAll();
    }

    public void SaveUser(User User)
    {
        base.Save(User);
    }
}

Upvotes: 0

Views: 169

Answers (2)

John Rayner
John Rayner

Reputation: 3535

You should also put in some 'Ghost Buster' style tests for your mappings.

Upvotes: 2

Paco
Paco

Reputation: 8381

At minimum, you should know that your mapping is working. That is possible by creating some simple tests for delete and save.

Upvotes: 3

Related Questions