public void GetAllEntitiesPopulatesCache() { // Arrange IEnumerable <SimpleEntity> entities = new List <SimpleEntity> { new SimpleEntity { Id = 10 }, new SimpleEntity { Id = 11 } }; // Create a repository with a mock dbset, so any queries will be done against the list rather than DB SimpleEntityRepository entityRepository = CreateSimpleEntityRepositoryWithMockDbSet(entities); entityRepository.ClearCache(); // Get entities to populate the cache entityRepository.GetList(); // Re-create the repository with an empty list in the DbSet entityRepository = CreateSimpleEntityRepositoryWithMockDbSet(new List <SimpleEntity>()); // Act // Re-query the repository, we should still get results as the queries should now work against the cache not against the empty DbSet IList <SimpleEntity> results = entityRepository.GetList(); // Assert Assert.IsNotNull(results); //Assert.AreEqual(2, results.Count); }