Database Reference
In-Depth Information
public void SaveChanegs()
{
_context.SaveChanges();
}
public List<Schedule> GetActiveSchedulesForTrain(int trainId)
{
var schedules = from r in _context.Schedules
where r.ArrivalDate.Date >= DateTime.Today &&
r.TrainId == trainId
select r;
return schedules.ToList();
}
}
9.
Right-click the solution, and select Add New Project. Add a Test Project to the solution.
Name this new project Tests . Add a reference to System.Data.Entity .
10.
Create a fake object set and fake DbContext so that you can test your business rules in
isolation without interacting with the database. Use the code in Listing 8-16.
Listing 8-16. The Implementation of the Fake Object Set and Fake Object Context
public class FakeDbSet<T> : IDbSet<T>
where T : class
{
HashSet<T> _data;
IQueryable _query;
public FakeDbSet()
{
_data = new HashSet<T>();
_query = _data.AsQueryable();
}
public virtual T Find(params object[] keyValues)
{
throw new NotImplementedException("Derive from FakeDbSet<T> and override Find");
}
public void Add(T item)
{
_data.Add(item);
}
public void Remove(T item)
{
_data.Remove(item);
}
 
Search WWH ::




Custom Search