public async Task NotifyConsultationResponseAsync(Conference conference, string roomLabel, Guid requestedForId, ConsultationAnswer answer) { var endpoint = conference.Endpoints.FirstOrDefault(e => e.Id == requestedForId); if (endpoint != null) { await PublishResponseMessage(conference, roomLabel, endpoint.Id, answer); return; } var participantFor = conference.Participants.First(x => x.Id == requestedForId); await _consultationResponseTracker.UpdateConsultationResponse(conference, participantFor.Id, answer); var haveAllAccepted = await _consultationResponseTracker.HaveAllParticipantsAccepted(conference, participantFor.Id); if (answer == ConsultationAnswer.Accepted && !haveAllAccepted) { return; } await PublishResponseMessage(conference, roomLabel, participantFor.Id, answer); if (participantFor.LinkedParticipants.Any()) { await NotifyLinkedParticipantsOfConsultationResponseAsync(conference, participantFor, roomLabel, answer); } if (answer == ConsultationAnswer.Transferring && participantFor.LinkedParticipants.Any()) { await _consultationResponseTracker.ClearResponses(conference, requestedForId); } }
public async Task should_send_message_to_other_party_when_all_linked_participant_respond_accept() { // arrange var linkedParticipant = _conference.Participants.First(x => !x.IsJudge() && x.LinkedParticipants.Any()); var linked = _conference.Participants .Where(p => linkedParticipant.LinkedParticipants.Select(x => x.LinkedId).Contains(p.Id)).ToList(); var roomLabel = "ConsultationRoom1"; var answer = ConsultationAnswer.Accepted; foreach (var lParticipant in linked) { await _consultationResponseTracker.UpdateConsultationResponse(_conference, lParticipant.Id, ConsultationAnswer.Accepted); } // act await _sut.NotifyConsultationResponseAsync(_conference, roomLabel, linkedParticipant.Id, answer); // assert _mocker.Mock <IEventHubClient>() .Verify( x => x.ConsultationRequestResponseMessage(_conference.Id, roomLabel, linkedParticipant.Id, answer), Times.Exactly(_conference.Participants.Count)); foreach (var lParticipant in linked) { _mocker.Mock <IEventHubClient>().Verify( x => x.ConsultationRequestResponseMessage(_conference.Id, roomLabel, lParticipant.Id, answer), Times.Exactly(_conference.Participants.Count)); } var room = _conference.CivilianRooms.First(x => x.Participants.Contains(linkedParticipant.Id)); var cache = _dictionaryCache.GetCache(); cache.ContainsKey(room.Id).Should().BeTrue(); var accepted = cache[room.Id]; accepted.Should().Contain(linkedParticipant.Id); accepted.Should().Contain(linked.Select(p => p.Id)); }