如何使用 moq 框架为域驱动设计架构中的存储库层编写单元测试?我的存储库类如下。
public class ContactRepository : Repository<Contact, int, ContactsDb>, IContactRepository
{
public ContactRepository(IUnitOfWork unitOfWork, IObjectContextFactory objectContextFactory)
: base(unitOfWork, objectContextFactory) { }
public IEnumerable<Contact> FindAll()
{
var predicate = PredicateBuilder.True<ContactsDb>();
//IEnumerable<ContactsDb> contacts = findContactsSummary(predicate);
IEnumerable<ContactsDb> contacts = ObjectContextFactory.Create().Contacts
.Include(c => c.Addresses).Include(c => c.Communication).Include(c => c.ContactEmails)
.Include(c => c.ContactPhones).Include(c => c.Image).Where(c => !c.IsDeleted);
foreach (ContactsDb dc in contacts)
{
if (dc.ContactType == ContactType.Person)
yield return Mapper.Map<ContactsDb, Person>(dc);
else
yield return Mapper.Map<ContactsDb, Company>(dc);
}
}
在这个存储库类中,哪些被模拟了?请举一些例子。