Ejemplo n.º 1
0
        public void Join_GetAll_Should_Return_All_Items(ICompoundKeyRepository <User, string, int> repository)
        {
            for (var i = 1; i <= 5; i++)
            {
                var item = new User {
                    Username = "******" + i.ToString(), Age = (i % 2) + 1, ContactTypeId = i == 1 ? 1 : 2
                };
                repository.Add(item);
            }

            var contactTypeRepository = new InMemoryRepository <ContactType, int>();

            contactTypeRepository.Add(new ContactType()
            {
                ContactTypeId = 1, Abbreviation = "T1"
            });
            contactTypeRepository.Add(new ContactType()
            {
                ContactTypeId = 2, Abbreviation = "T2"
            });

            var compositeRepos = repository.Join(contactTypeRepository, c => c.ContactTypeId, ct => ct.ContactTypeId,
                                                 (c, ct) => new { Name = c.Username, TypeAbbrev = ct.Abbreviation });

            var all = compositeRepos.GetAll().ToList();

            all.Count.ShouldBe(5);

            all.Single(c => c.Name == "Test User 1").TypeAbbrev.ShouldBe("T1");
            all.Single(c => c.Name == "Test User 2").TypeAbbrev.ShouldBe("T2");
            all.Single(c => c.Name == "Test User 3").TypeAbbrev.ShouldBe("T2");
            all.Single(c => c.Name == "Test User 4").TypeAbbrev.ShouldBe("T2");
            all.Single(c => c.Name == "Test User 5").TypeAbbrev.ShouldBe("T2");
        }
Ejemplo n.º 2
0
 public IRepositoryQueryable <TResult> Join <TJoinKey, TInner, TResult>(IRepositoryQueryable <TInner> innerRepository, Expression <Func <T, TJoinKey> > outerKeySelector,
                                                                        Expression <Func <TInner, TJoinKey> > innerKeySelector, Expression <Func <T, TInner, TResult> > resultSelector)
     where TInner : class
     where TResult : class
 {
     return(Repository.Join(innerRepository, outerKeySelector, innerKeySelector, resultSelector));
 }