Database Reference
In-Depth Information
public IDbSet<Schedule> Schedules
{
get { return schedules; }
}
public IDbSet<Reservation> Reservations
{
get { return reservations; }
}
public int SaveChanges()
{
foreach (var schedule in Schedules.Cast<IValidate>())
{
schedule.Validate(ChangeAction.Insert);
}
foreach (var reservation in Reservations.Cast<IValidate>())
{
reservation.Validate(ChangeAction.Insert);
}
return 1;
}
public void Dispose()
{
}
}
11.
We don't want to test against our real database, so we need to create a fake DbContext that
simulates the DbContext with in-memory collections acting as our data store. Add the unit
test code in Listing 8-17 to the Tests project.
Listing 8-17. The Unit Tests for Our Tests Project
[TestClass]
public class ReservationTest: IDisposable
{
private IReservationContext _context;
[TestInitialize]
public void TestSetup()
{
var train = new Train { TrainId = 1, TrainName = "Polar Express" };
var schedule = new Schedule { ScheduleId = 1, Train = train,
ArrivalDate = DateTime.Now,
DepartureDate = DateTime.Today,
LeavesFrom = "Dallas",
ArrivesAt = "New York" };
var reservation = new Reservation { ReservationId = 1,
Passenger = "Phil Marlowe",
Schedule = schedule };
_context = new FakeReservationContext();
var repository = new ReservationRepository(_context);
 
Search WWH ::




Custom Search