public async Task ShouldUpdateKeeperAtGetAll() { var repo = new EntityRepository(_dbContext, _idsKeeper); var customers = await repo.GetAllAsync <Customer>(); Assert.That(customers, Is.Not.Empty); Assert.That(_idsKeeper.Get <Customer>(), Is.EquivalentTo(customers.Select(c => c.Id))); }
public async Task <IList <T> > LoadAllAsync <T>() where T : EntityBase { var trackedIdsWithOutAdded = _dbContext.ChangeTracker .Entries <T>() .Where(e => e.State != EntityState.Added) .Select(e => e.Entity.Id).ToHashSet(); var tracked = _dbContext.ChangeTracker .Entries <T>() .Select(e => e.Entity).ToList(); if (trackedIdsWithOutAdded.Count != 0 && _idsKeeper.Get <T>().SetEquals(trackedIdsWithOutAdded)) { return(tracked); } var toTrack = await _dbContext.Set <T>() .Where(c => !trackedIdsWithOutAdded.Contains(c.Id)) .ToListAsync(); tracked.AddRange(toTrack); _idsKeeper.Update <T>(tracked.Select(e => e.Id).ToHashSet()); return(tracked); }