private async Task <IEnumerable <ParticipantFeedbackVM> > GetFeedbacksForEvent(int eventId, string ParticipantType) { List <ParticipantFeedbackVM> fbVM = new List <ParticipantFeedbackVM>(); var allFeedbacks = await _participantFbRepository.GetAll(); //List<string> participatedEmails = allFeedbacks.Where(x => x.EventId == eventId).Select(x=>x.Email).ToList(); var distinctEmails = allFeedbacks.GroupBy(test => test.Email) .Select(grp => grp.First()); foreach (var email in distinctEmails) { ParticipantFeedbackVM pfbVM = new ParticipantFeedbackVM(); pfbVM.Feedback = new List <string>(); var fbs = allFeedbacks.Where(x => x.Email == email.Email && x.ParticipantType == ParticipantType).Select(x => x.Answer).ToList(); foreach (var fb in fbs) { // Answer answer = new Answer(); // answer.Ans = fb.ToString(); pfbVM.Feedback.Add(fb); } if (pfbVM.Feedback.Count > 0) { fbVM.Add(pfbVM); } } return(fbVM); }
public async Task GetunregisteredFbAsync_ShouldReturnunregisteredFb_unregisteredFbExists() { int id = 1; List <ParticipantFeedbackVM> feedbackVMs = new List <ParticipantFeedbackVM>(); ParticipantFeedbackVM feedback = new ParticipantFeedbackVM(); List <string> fbNames = new List <string>(); fbNames.Add("Incorrectly registered"); feedback.Feedback = fbNames; feedbackVMs.Add(feedback); _feedbackRepository.Setup(x => x.GetUnregisteredFeedbacksForEvent(id)).ReturnsAsync(feedbackVMs); IEnumerable <ParticipantFeedbackVM> result = await feedbackController.GetUnregisteredFeedbacks(id); Assert.IsNotEmpty(result); }