Ejemplo n.º 1
0
        public void shouldReturnFromRestPetAPI()
        {
            var result = repository.GetOwnersFromRest();

            Assert.AreEqual(6, result.Count);
            Assert.AreEqual(2, result[0].Pets.Count);
        }
Ejemplo n.º 2
0
        public Dictionary <string, List <string> > GetPetsByGender(string petType)
        {
            var petOwners = petRepository.GetOwnersFromRest();

            //flat map the list and considered the pets are null
            var qry = petOwners.Where(x => x.Pets != null)
                      .SelectMany(x => x.Pets, (a, b) => new { Gender = a.Gender, PetName = b.Name, Type = b.Type })
                      .Where(t => t.Type == petType)
                      .OrderBy(y => y.PetName)
                      .ToList();

            //group the data and conver to dictionary
            var ret = qry.GroupBy(x => x.Gender)
                      .ToDictionary(grp => grp.Key, grp => grp.Select(x => x.PetName).ToList());

            return(ret);
        }