/// <summary> /// Create and return a Mocked Person dbSet repository from Generic Repository /// </summary> /// <param name="nbOfAddedRecord">Number of fake Records to add</param> /// <returns>EntityRepository<Person></returns> private EntityRepository <Person> CreateFakeDbSet(int nbOfAddedRecord) { FakeDbSet <Person> FakePeopleDbSet = null; // Create an empty dbSet if (nbOfAddedRecord == 0) { FakePeopleDbSet = new FakeDbSet <Person>(); } else { // Create test records var people = GetFakePeople(nbOfAddedRecord).ToList(); // Create dbSet in memory and populate FakePeopleDbSet = GetFakePeopleDbSet(people); } // Create Mock object and dbSet mock context var MockPeopleContextObject = new Mock <IPeopleContext>(); // the FakeDbSet<Person> peopleDbSet is returned each time the Set Person is executed MockPeopleContextObject.Setup(pc => pc.Set <Person>()).Returns(FakePeopleDbSet); IPeopleContext MockPeopleDbContext = MockPeopleContextObject.Object; // Create repository using Generic Repository class from Mocked DbContext EntityRepository <Person> repository = new EntityRepository <Person>(MockPeopleDbContext); return(repository); }
/// <summary> /// Create Repository from mock dbSet /// </summary> /// <param name="FakeDbSet">Fake dbSet object</param> /// <returns>Created repository</returns> private EntityRepository <Person> CreateRepository(Mock <IPeopleContext> MockdDbContextObject, FakeDbSet <Person> FakeDbSet) { Assert.NotNull(FakeDbSet); Assert.NotNull(MockdDbContextObject); // the FakeDbSet<Person> is returned each time the Set Person is executed MockdDbContextObject.Setup(pc => pc.Set <Person>()).Returns(FakeDbSet); IPeopleContext MockPeopleDbContext = MockdDbContextObject.Object; // Create repository using Generic Repository class from Mocked DbContext EntityRepository <Person> repository = new EntityRepository <Person>(MockPeopleDbContext); return(repository); }
public PeopleService(IPeopleContext peopleContext) { _peopleContext = peopleContext; }
public PersonRepo(IPeopleContext context) { this.context = context; }
public UserService() { _peopleContext = new PeopleContext(); }
public PeopleRepository(IPeopleContext peopleContext) { dataContext = peopleContext; personDbSet = dataContext.People; addressDbSet = dataContext.Address; }
public TestPeopleRepository() { _dbContext = new PeopleContext(); }