Beispiel #1
0
        public async Task should_return_bad_request_when_endpoint_is_already_in_room()
        {
            var endpointWithDefenceAdvocate = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate             = TestConference.GetParticipants().First(x =>
                                                                                     x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                                       StringComparison.CurrentCultureIgnoreCase));

            var room = new ConsultationRoom(TestConference.Id, "Label", VideoApi.Domain.Enums.VirtualCourtRoomType.Participant, false);

            room.AddEndpoint(new RoomEndpoint(Guid.NewGuid()));
            QueryHandlerMock.Setup(x => x.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(It.IsAny <GetConsultationRoomByIdQuery>())).ReturnsAsync(room);

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithDefenceAdvocate.Id,
                RequestedById = defenceAdvocate.Id,
                RoomLabel     = "Label"
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            var actionResult = result.As <BadRequestObjectResult>();

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be("Room already has an active endpoint");
        }
Beispiel #2
0
        public async Task Should_return_error_when_consultation_accepted_but_no_room_is_available()
        {
            var conferenceId = TestConference.Id;
            var requestedBy  = TestConference.GetParticipants()[2];
            var requestedFor = TestConference.GetParticipants()[3];

            VideoPlatformServiceMock
            .Setup(x => x.StartPrivateConsultationAsync(TestConference, requestedBy, requestedFor))
            .ThrowsAsync(new DomainRuleException("Unavailable room", "No consultation rooms available"));

            // make sure no rooms are available
            TestConference.Participants[1].UpdateCurrentRoom(RoomType.ConsultationRoom1);
            TestConference.Participants[4].UpdateCurrentRoom(RoomType.ConsultationRoom2);

            var answer = ConsultationAnswer.Accepted;

            var request = new ConsultationRequest
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = requestedFor.Id,
                Answer       = answer
            };

            var result = await Controller.HandleConsultationRequestAsync(request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            ((SerializableError)typedResult.Value).ContainsKeyAndErrorMessage("ConsultationRoom", "No consultation room available");
            VideoPlatformServiceMock.Verify(x =>
                                            x.StartPrivateConsultationAsync(TestConference, requestedBy, requestedFor), Times.Once);
            VideoPlatformServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_remove_given_participants_from_conference()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[1];

            await Controller.RemoveParticipantFromConferenceAsync(conferenceId, participant.Id);

            MockQueryHandler.Verify(m => m.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>(It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            MockCommandHandler.Verify(c =>
                                      c.Handle(It.Is <RemoveParticipantsFromConferenceCommand>(x => x.Participants[0].Id == participant.Id)), Times.Once);
        }
Beispiel #4
0
        public async Task Should_save_heartbeat()
        {
            var conferenceId  = TestConference.Id;
            var participantId = TestConference.GetParticipants()[1].Id;

            var result = await Controller.SaveHeartbeatDataForParticipantAsync(conferenceId, participantId, new AddHeartbeatRequest());

            MockCommandHandler.Verify(c => c.Handle(It.IsAny <SaveHeartbeatCommand>()), Times.Once);

            result.Should().NotBeNull();
            result.Should().BeAssignableTo <NoContentResult>();
        }
        public async Task Should_update_given_participants_details()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[1];


            var result = await Controller.UpdateParticipantDetailsAsync(conferenceId, participant.Id, _updateParticipantRequest);

            MockCommandHandler.Verify(c => c.Handle(It.IsAny <UpdateParticipantDetailsCommand>()), Times.Once);

            var typedResult = (NoContentResult)result;

            typedResult.Should().NotBeNull();
        }
        public async Task Should_return_badrequest_when_participant_current_room_is_not_consultation_room_type()
        {
            var conferenceId = TestConference.Id;
            var request      = TestConference.GetParticipants()[2];

            var leaveConsultationRequest = new LeaveConsultationRequest
            {
                ConferenceId  = conferenceId,
                ParticipantId = request.Id
            };

            var result = await Controller.LeaveConsultationAsync(leaveConsultationRequest);

            result.Should().BeOfType <BadRequestObjectResult>();
        }
Beispiel #7
0
        private StartConsultationRequest InitConsultationRequestForJudge()
        {
            if (TestConference.Participants == null)
            {
                Assert.Fail("No participants found in conference");
            }

            return(new StartConsultationRequest
            {
                ConferenceId = TestConference.Id,
                RequestedBy = TestConference.GetParticipants().First(x =>
                                                                     x.UserRole.Equals(UserRole.Judge)).Id,
                RoomType = Contract.Enums.VirtualCourtRoomType.JudgeJOH
            });
        }
        public async Task Should_leave_private_consultation_with_valid_conference_and_room_type()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[1];

            var leaveConsultationRequest = new LeaveConsultationRequest {
                ConferenceId  = conferenceId,
                ParticipantId = participant.Id
            };

            await Controller.LeaveConsultationAsync(leaveConsultationRequest);

            QueryHandlerMock.Verify(q => q.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>(It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            ConsultationServiceMock.Verify(v => v.LeaveConsultationAsync(TestConference.Id, leaveConsultationRequest.ParticipantId, participant.GetCurrentRoom(), RoomType.WaitingRoom.ToString()), Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
Beispiel #9
0
        public async Task Should_leave_private_consultation_with_valid_conference_and_room_type()
        {
            var conferenceId = TestConference.Id;
            var request      = TestConference.GetParticipants()[1];

            var leaveConsultationRequest = new LeaveConsultationRequest {
                ConferenceId  = conferenceId,
                ParticipantId = request.Id
            };

            await Controller.LeavePrivateConsultationAsync(leaveConsultationRequest);

            QueryHandlerMock.Verify(q => q.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>(It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            VideoPlatformServiceMock.Verify(v => v.StopPrivateConsultationAsync(TestConference, RoomType.ConsultationRoom1), Times.Once);
            VideoPlatformServiceMock.VerifyNoOtherCalls();
        }
Beispiel #10
0
        public async Task should_add_username_to_command_when_provided()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[1];

            _updateParticipantRequest.Username = "******";


            var result = await Controller.UpdateParticipantDetailsAsync(conferenceId, participant.Id, _updateParticipantRequest);

            MockCommandHandler.Verify(c => c.Handle(It.Is <UpdateParticipantDetailsCommand>(c => c.Username == _updateParticipantRequest.Username)), Times.Once);

            var typedResult = (NoContentResult)result;

            typedResult.Should().NotBeNull();
        }
        private StartConsultationRequest RequestBuilder()
        {
            if (TestConference.Participants == null)
            {
                Assert.Fail("No participants found in conference");
            }

            _testConsultationRoom = new ConsultationRoom(TestConference.Id, "JohRoom1", VirtualCourtRoomType.JudgeJOH.MapToDomainEnum(), false);

            return(new StartConsultationRequest
            {
                ConferenceId = TestConference.Id,
                RequestedBy = TestConference.GetParticipants().First(x =>
                                                                     x.UserRole.MapToContractEnum().Equals(UserRole.Judge)).Id,
                RoomType = VirtualCourtRoomType.JudgeJOH
            });
        }
Beispiel #12
0
        public async Task Should_return_nocontent_when_participant_current_room_is_not_consultation_room_type()
        {
            var conferenceId = TestConference.Id;
            var request      = TestConference.GetParticipants()[2];

            var leaveConsultationRequest = new LeaveConsultationRequest
            {
                ConferenceId  = conferenceId,
                ParticipantId = request.Id
            };

            var result = await Controller.LeavePrivateConsultationAsync(leaveConsultationRequest);

            var typedResult = (NoContentResult)result;

            typedResult.Should().NotBeNull();
        }
Beispiel #13
0
        public async Task should_return_ok_when_judge_invites()
        {
            // Arrange
            var endpointWithoutDefenceAdvocate = TestConference.GetEndpoints().First(x => string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var requestedByJudge = TestConference.GetParticipants().First(x => x.UserRole == VideoApi.Domain.Enums.UserRole.Judge);
            var request          = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithoutDefenceAdvocate.Id,
                RequestedById = requestedByJudge.Id,
                RoomLabel     = "NewRoom_NotInDb"
            };

            // Act
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            // Assert
            result.Should().BeOfType <OkResult>();
        }
Beispiel #14
0
        public async Task should_return_accepted_when_endpoint_is_linked_with_defence_advocate()
        {
            var endpointWithDefenceAdvocate = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate             = TestConference.GetParticipants().First(x =>
                                                                                     x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                                       StringComparison.CurrentCultureIgnoreCase));

            var request = new EndpointConsultationRequest()
            {
                ConferenceId      = TestConference.Id,
                EndpointId        = endpointWithDefenceAdvocate.Id,
                DefenceAdvocateId = defenceAdvocate.Id
            };
            var result = await Controller.StartPrivateConsultationWithEndpointAsync(request);

            var actionResult = result.As <AcceptedResult>();

            actionResult.Should().NotBeNull();
        }
Beispiel #15
0
        public async Task should_return_unauthorised_when_endpoint_is_not_linked_with_defence_advocate()
        {
            var endpointWithDefenceAdvocate = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate             = TestConference.GetParticipants().First(x =>
                                                                                     !x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                                        StringComparison.CurrentCultureIgnoreCase) && x.UserRole != VideoApi.Domain.Enums.UserRole.Judge);

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithDefenceAdvocate.Id,
                RequestedById = defenceAdvocate.Id
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            var actionResult = result.As <UnauthorizedObjectResult>();

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be("Defence advocate is not allowed to speak to requested endpoint");
        }
        public async Task Should_return_notfound_when_no_room_label_provided()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];
            var requestedBy  = TestConference.GetParticipants()[2].Id;
            var request      = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedFor = participant.Id,
                RequestedBy  = requestedBy,
                RoomLabel    = "",
                Answer       = ConsultationAnswer.Rejected
            };

            var result = await Controller.RespondToConsultationRequestAsync(request);

            var typedResult = (NotFoundResult)result;

            typedResult.Should().NotBeNull();
        }
Beispiel #17
0
        public async Task should_return_unauthorised_when_endpoint_does_not_have_defence_advocate()
        {
            var endpointWithDefenceAdvocate    = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var endpointWithoutDefenceAdvocate = TestConference.GetEndpoints().First(x => string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate = TestConference.GetParticipants().First(x =>
                                                                         x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                           StringComparison.CurrentCultureIgnoreCase));

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithoutDefenceAdvocate.Id,
                RequestedById = defenceAdvocate.Id
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            var actionResult = result.As <UnauthorizedObjectResult>();

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be("Endpoint does not have a defence advocate linked");
        }
        public async Task Should_return_notfound_when_no_requested_for_participant_is_found()
        {
            var conferenceId = TestConference.Id;
            var requestedFor = TestConference.GetParticipants()[3];

            var answer = ConsultationAnswer.Accepted;

            var request = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedBy  = Guid.NewGuid(),
                RequestedFor = requestedFor.Id,
                Answer       = answer
            };

            var result = await Controller.RespondToConsultationRequestAsync(request);

            var typedResult = (NotFoundResult)result;

            typedResult.Should().NotBeNull();
        }
        public async Task Should_not_transfer_participant_when_consultation_is_not_accepted()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];

            var roomFrom = participant.GetCurrentRoom();
            var request  = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedFor = participant.Id,
                RoomLabel    = "ConsultationRoom",
                Answer       = ConsultationAnswer.Rejected
            };

            await Controller.RespondToConsultationRequestAsync(request);

            ConsultationServiceMock.Verify(x =>
                                           x.LeaveConsultationAsync(conferenceId, participant.Id, roomFrom, request.RoomLabel),
                                           Times.Never);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_transfer_participant_when_consultation_is_accepted()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];
            var requestedBy  = TestConference.GetParticipants()[1];

            var request = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = participant.Id,
                RoomLabel    = "ConsultationRoom",
                Answer       = ConsultationAnswer.Accepted
            };

            await Controller.RespondToConsultationRequestAsync(request);

            ConsultationServiceMock.Verify(x => x.ParticipantTransferToRoomAsync(conferenceId, participant.Id, request.RoomLabel),
                                           Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_not_transfer_participant_when_consultation_is_not_accepted()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];

            var roomFrom = participant.CurrentRoom.Value;
            var request  = new AdminConsultationRequest
            {
                ConferenceId     = conferenceId,
                ParticipantId    = participant.Id,
                ConsultationRoom = RoomType.ConsultationRoom1,
                Answer           = ConsultationAnswer.Rejected
            };

            await Controller.RespondToAdminConsultationRequestAsync(request);

            VideoPlatformServiceMock.Verify(x =>
                                            x.TransferParticipantAsync(conferenceId, participant.Id, roomFrom, request.ConsultationRoom),
                                            Times.Never);
            VideoPlatformServiceMock.VerifyNoOtherCalls();
        }
Beispiel #22
0
        public async Task should_return_ok_when_endpoint_is_linked_with_defence_advocate()
        {
            var endpointWithDefenceAdvocate = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate             = TestConference.GetParticipants().First(x =>
                                                                                     x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                                       StringComparison.CurrentCultureIgnoreCase));

            var room = new ConsultationRoom(TestConference.Id, "Label", VideoApi.Domain.Enums.VirtualCourtRoomType.Participant, false);

            QueryHandlerMock.Setup(x => x.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(It.IsAny <GetConsultationRoomByIdQuery>())).ReturnsAsync(room);

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithDefenceAdvocate.Id,
                RequestedById = defenceAdvocate.Id,
                RoomLabel     = "Label"
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            result.Should().BeOfType <OkResult>();
        }
Beispiel #23
0
        public async Task Should_raise_notification_to_requester_and_admin_when_consultation_is_accepted()
        {
            var conferenceId = TestConference.Id;
            var requestedBy  = TestConference.GetParticipants()[2];
            var requestedFor = TestConference.GetParticipants()[3];

            var answer = ConsultationAnswer.Accepted;

            var request = new ConsultationRequest
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = requestedFor.Id,
                Answer       = answer
            };

            await Controller.HandleConsultationRequestAsync(request);

            CommandHandlerMock.Verify(x => x.Handle(It.Is <SaveEventCommand>(s => s.Reason == $"Consultation with {requestedFor.DisplayName}")), Times.Once);
            VideoPlatformServiceMock.Verify(x =>
                                            x.StartPrivateConsultationAsync(TestConference, requestedBy, requestedFor), Times.Once);
            VideoPlatformServiceMock.VerifyNoOtherCalls();
        }
Beispiel #24
0
        public async Task should_return_not_found_when_endpoint_is_requested_to_not_found_room()
        {
            var endpointWithDefenceAdvocate = TestConference.GetEndpoints().First(x => !string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var defenceAdvocate             = TestConference.GetParticipants().First(x =>
                                                                                     x.Username.Equals(endpointWithDefenceAdvocate.DefenceAdvocate,
                                                                                                       StringComparison.CurrentCultureIgnoreCase));

            QueryHandlerMock.Setup(x => x.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(It.IsAny <GetConsultationRoomByIdQuery>())).ReturnsAsync(null as ConsultationRoom);

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithDefenceAdvocate.Id,
                RequestedById = defenceAdvocate.Id,
                RoomLabel     = "Label"
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

            var actionResult = result.As <NotFoundObjectResult>();

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be($"Unable to find room {request.RoomLabel}");
        }
Beispiel #25
0
        public async Task Should_get_heartbeatResponses()
        {
            var conferenceId  = TestConference.Id;
            var participantId = TestConference.GetParticipants()[1].Id;


            var result = await Controller.GetHeartbeatDataForParticipantAsync(conferenceId, participantId);

            MockQueryHandler.Verify(m => m.Handle <GetHeartbeatsFromTimePointQuery, IList <Heartbeat> >(It.IsAny <GetHeartbeatsFromTimePointQuery>()), Times.Once);

            result.Should().NotBeNull();
            result.Should().BeAssignableTo <OkObjectResult>();
            var responses = result.As <OkObjectResult>().Value.As <IEnumerable <ParticipantHeartbeatResponse> >().ToList();

            responses.Should().NotBeNull().And.NotBeEmpty().And.NotContainNulls();
            var heartbeatResponse = responses.First().As <ParticipantHeartbeatResponse>();

            heartbeatResponse.BrowserName.Should().Be("chrome");
            heartbeatResponse.BrowserVersion.Should().Be("1");
            heartbeatResponse.RecentPacketLoss.Should().Be(8);
            heartbeatResponse.OperatingSystem.Should().Be("Mac OS X");
            heartbeatResponse.OperatingSystemVersion.Should().Be("10.15.7");
        }
        public async Task Should_raise_notification_to_requester_and_admin_when_consultation_is_accepted()
        {
            var conferenceId = TestConference.Id;
            var requestedBy  = TestConference.GetParticipants()[2];
            var requestedFor = TestConference.GetParticipants()[3];

            var answer = ConsultationAnswer.Accepted;

            var request = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = requestedFor.Id,
                Answer       = answer,
                RoomLabel    = "Room1"
            };

            await Controller.RespondToConsultationRequestAsync(request);

            CommandHandlerMock.Verify(x => x.Handle(It.Is <SaveEventCommand>(s => s.Reason == $"Adding {requestedFor.DisplayName} to {request.RoomLabel}")), Times.Once);
            ConsultationServiceMock.Verify(x =>
                                           x.ParticipantTransferToRoomAsync(TestConference.Id, requestedFor.Id, "Room1"), Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }