Alistair
unread,Sep 7, 2010, 11:12:05 PM9/7/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.