test repository class best practices

1 view
Skip to first unread message

Alistair

unread,
Sep 7, 2010, 11:12:05 PM9/7/10
to S#arp Architecture
Hi,

I wish to test my UserRepository class but am not sure of the best
way. Here is the best I have managed.

public class UserRepositoryTests : DatabaseRepositoryTestsBase
{
private IUserRepository repos = new UserRepository();

[TestFixtureSetUp]
public void Init()
{

HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
}

[Test]
public void CanCreateUser()
{
User newUser = CreateTransientUser(); //get dummy user

repos.SaveOrUpdate(newUser);

Assert.IsNotNull(newUser);

NHibernateSession.Current.Flush();

User fromDBUser = repos.Get(newUser.Id);

Assert.IsNotNull(fromDBUser);

Assert.That(newUser.Id, Is.EqualTo(fromDBUser.Id));
Assert.That(newUser.UserName,
Is.EqualTo(fromDBUser.UserName));

repos.Delete(newUser);
}
}

Does this code look ok?

Note that I have to call Flush, otherwise it won't pick up errors such
as user.Username not being specified, even though it is set as [Not
Null] in the entity with NHibernate validator.
Reply all
Reply to author
Forward
0 new messages