public void TestReserveAd() { //Test method 5 times for (int i = 0; i < maxReservations; i++) { ads.ReserveAd(toReserve[i].Id, reservingUser); } //Get the ad's reserver (updated version of otherUser) var testId = toReserve[0].Id; User reserver = DbContextControl.GetNew().Ads.Include("ReservedBy") .FirstOrDefault(a => a.Id == testId).ReservedBy; //Ad.ReservedBy should be changed to represent a user Assert.IsNotNull(reserver); //Check that the user who reserved 5 times has no more reservations try { Assert.IsTrue(reserver.Reservations == 0); } catch (AssertFailedException) { throw new AssertFailedException("User should have 0 reservations left, but he has " + reserver.Reservations + " out of " + maxReservations); } }
public void TestUnreserveAd() { ads.ReserveAd(toReserve[maxReservations].Id, thirdUser); ads.UnreserveAd(toReserve[maxReservations].Id, thirdUser); var testId = toReserve[0].Id; Ad unreservedAd = DbContextControl.GetNew().Ads.Include("ReservedBy") .FirstOrDefault(a => a.Id == testId); User reserver = UserControl.GetInstance().GetUser(thirdUser); //Reservations should still be 0 Assert.IsTrue(reserver.Reservations == maxReservations - 1); //Ad should be unreserved Assert.IsNull(unreservedAd.ReservedBy); }