-
-
Get Method Testing When Database Already Populated
by azamsharp on 5/23/2008 11:10:53 AM
-
I know that unit testing should be performed with a clean database. This is because if you have persisted items then it will interfere with testing. But what if we cannot remove those items from the database and are forced to write tests against an already populated database. One of the main issues are faced when testing for fetching/retrieving operations. Because in that case the items inserted != items retrieved. Here is one hack of doing that kind of testing.
-
[Test]
[RollBack]
public void should_be_able_to_get_all_tutors()
{
var alice = new UserBuilder().New("alice", "alice1234$", "alice@gmail.com")
.AssignRole("Tutor");
var george = new UserBuilder().New("george", "george1234$", "george@gmail.com")
.AssignRole("Tutor");
Assert.AreEqual(2, Math.Abs( 2 - Roles.GetUsersInRole("Tutor").Count()));
}
The Math.Abs makes sure that the value is always positive!
-
Refactor it!
Please log in to refactor the code!
Login