public void WhenRetrievingPetSummary_Success() { _petApiClient.GetAllPerson().Returns(_inputPersonPetData); var personPetReadService = new PersonPetReadService(_petApiClient); var summaryResult = personPetReadService.GetCategorizePets(PetType.Cat); Assert.IsTrue(summaryResult != null); Assert.AreEqual(summaryResult.Count, 2); Assert.AreEqual(summaryResult.Count(p => p.GenderType == Enum.GetName(typeof(GenderType), GenderType.Male)), 1); Assert.AreEqual(summaryResult.Count(p => p.GenderType == Enum.GetName(typeof(GenderType), GenderType.Female)), 1); Assert.AreEqual(summaryResult.Where(p => p.GenderType == Enum.GetName(typeof(GenderType), GenderType.Male)).SelectMany(q => q.Pets).Count(), 4); Assert.AreEqual(summaryResult.Where(p => p.GenderType == Enum.GetName(typeof(GenderType), GenderType.Female)).SelectMany(q => q.Pets).Count(), 3); }
public IEnumerable <GenderPetCategoryDto> GetFilteredDataByPetType(PetType petType) { return(_petApiClient.GetAllPerson() .Where(p => p.Pets != null && p.Pets.Any(pp => pp.GetPetType() == petType)) .GroupBy(p => p.GetGenderType()) .Select(group => new GenderPetCategoryDto { GenderType = group.Key, Pets = group.ToList() .SelectMany(p => p.Pets) .Where(q => q.GetPetType() == petType) .Select(q => q.BasicConvertTo <PetDto>()).ToList() })); }