public void CanFindActivePersons() { int countExpected = 1; int countActual = _persons.AsQueryable().Where(GenericEntityQuery <Person> .GetByIsActive(true)).Count(); Assert.Equal(countExpected, countActual); }
public void CanFindByCreatedOn() { int countExpected = 3; int countActual = _persons.AsQueryable().Where(GenericEntityQuery <Person> .GetByCreatedOn(DateTime.Now)).Count(); Assert.Equal(countExpected, countActual); }
public void CanFindById() { int idExpected = 2; Person person = _persons.AsQueryable().Where(GenericEntityQuery <Person> .GetById(idExpected)).SingleOrDefault(); Assert.Equal(idExpected, person.Id); }
public void CanFindByUpdateOn() { int countExpected = 1; DateTime updateOn = DateTime.Now.AddDays(2); int countActual = _persons.AsQueryable <Person>().Where(GenericEntityQuery <Person> .GetByUpdateOn(updateOn)).Count(); Assert.Equal(countExpected, countActual); }
public virtual T SearchById(long id) { return(_entities .Where(GenericEntityQuery <T> .GetById(id)) .SingleOrDefault()); }
public PersonRepositoryTest() { IList <Person> persons = new List <Person>() { new Person("Person A", "*****@*****.**"), new Person("Person B", "*****@*****.**"), new Person("Person C", "*****@*****.**"), }; for (int i = 1; i <= persons.Count(); i++) { persons[i - 1].Id = i; } Mock <IGenericRepository <Person> > mockRepository = new Mock <IGenericRepository <Person> >(); mockRepository .Setup(repository => repository.GetAll()) .Returns(persons); mockRepository .Setup(repository => repository.SearchById(It.IsAny <long>())) .Returns((long id) => persons.AsQueryable() .Where(GenericEntityQuery <Person> .GetById(id)) .SingleOrDefault()); mockRepository .Setup(repository => repository.Add(It.IsAny <Person>())) .Callback <Person>( person => { person.Id = persons.Count() + 1; persons.Add(person); }); mockRepository .Setup(repository => repository.Remove(It.IsAny <Person>())) .Callback <Person>( person => { Person result = persons.AsQueryable() .Where(GenericEntityQuery <Person> .GetById(person.Id)) .SingleOrDefault(); persons.Remove(result); }); mockRepository .Setup(repository => repository.Update(It.IsAny <Person>())) .Callback <Person>( person => { Person result = persons.AsQueryable() .Where(GenericEntityQuery <Person> .GetById(person.Id)) .SingleOrDefault(); result.SetIsActive(person.IsActive); result.SetUpdateOn(person.UpdatedOn); }); _repository = mockRepository.Object; }