Esempio n. 1
0
        public async Task should_update_participant_to_disconnected_from_virtual_room()
        {
            // Arrange conference with participant in consultation room
            var seededConference = await TestDataManager.SeedConference();

            _newConferenceIds.Add(seededConference.Id);
            var consultationRoom = new ConsultationRoom(seededConference.Id, $"JudgeConsultationRoom{DateTime.UtcNow.Ticks}",
                                                        VirtualCourtRoomType.JudgeJOH, false);

            var room = await TestDataManager.SeedRoom(consultationRoom);

            var newRoomId = room.Id;

            var pat1 = seededConference.Participants[0].Id;
            await TestDataManager.SeedRoomWithRoomParticipant(newRoomId, new RoomParticipant(pat1));

            // Act
            var command =
                new UpdateParticipantStatusAndRoomCommand(seededConference.Id, pat1, ParticipantState.Disconnected, null,
                                                          null);
            await _handler.Handle(command);

            // Assert
            var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(seededConference.Id));

            var updatedParticipant = updatedConference.GetParticipants().Single(x => x.Id == pat1);

            updatedParticipant.State.Should().Be(ParticipantState.Disconnected);
            updatedParticipant.CurrentRoom.Should().BeNull();
            updatedParticipant.CurrentConsultationRoom.Should().BeNull();
        }
Esempio n. 2
0
        public async Task Should_update_participant_status_and_virtual_room()
        {
            var seededConference = await TestDataManager.SeedConference();

            _newConferenceIds.Add(seededConference.Id);
            var consultationRoom = new ConsultationRoom(seededConference.Id, $"JudgeConsultationRoom{DateTime.UtcNow.Ticks}",
                                                        VirtualCourtRoomType.JudgeJOH, false);
            var seededRoom = await TestDataManager.SeedRoom(consultationRoom);

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            TestContext.WriteLine($"New seeded room id: {seededRoom.Id}");
            var participant = seededConference.GetParticipants().First(p => p.IsJudge());
            const ParticipantState state = ParticipantState.InConsultation;

            var beforeState = participant.GetCurrentStatus();

            var command = new UpdateParticipantStatusAndRoomCommand(seededConference.Id, participant.Id, state, null, seededRoom.Label);
            await _handler.Handle(command);

            var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(seededConference.Id));

            var updatedParticipant = updatedConference.GetParticipants().Single(x => x.Username == participant.Username);
            var afterState         = updatedParticipant.GetCurrentStatus();

            afterState.Should().NotBe(beforeState);
            afterState.ParticipantState.Should().Be(state);
            updatedParticipant.CurrentRoom.Should().BeNull();
            updatedParticipant.CurrentConsultationRoom.Label.Should().Be(seededRoom.Label);
        }
Esempio n. 3
0
        public async Task Should_send_available_message_to_participants_and_service_bus_when_participant_joins()
        {
            var conference          = TestConference;
            var participantForEvent = conference.GetParticipants().First(x => x.UserRole == UserRole.Individual);

            var callbackEvent = new CallbackEvent
            {
                EventType     = EventType.Joined,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TimeStampUtc  = DateTime.UtcNow
            };
            var updateStatusCommand = new UpdateParticipantStatusAndRoomCommand(conference.Id, participantForEvent.Id,
                                                                                ParticipantState.Available, RoomType.WaitingRoom);

            CommandHandlerMock.Setup(x => x.Handle(updateStatusCommand));

            await _sut.HandleAsync(callbackEvent);

            CommandHandlerMock.Verify(
                x => x.Handle(It.Is <UpdateParticipantStatusAndRoomCommand>(command =>
                                                                            command.ConferenceId == conference.Id &&
                                                                            command.ParticipantId == participantForEvent.Id &&
                                                                            command.ParticipantState == ParticipantState.Available &&
                                                                            command.Room == RoomType.WaitingRoom)), Times.Once);
        }
Esempio n. 4
0
        protected override Task PublishStatusAsync(CallbackEvent callbackEvent)
        {
            var participantState = ParticipantState.Available;
            var room             = RoomType.WaitingRoom;
            var command          = new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantState, room);

            return(CommandHandler.Handle(command));
        }
        public void Should_throw_conference_not_found_exception_when_conference_does_not_exist()
        {
            var conferenceId  = Guid.NewGuid();
            var participantId = Guid.NewGuid();
            var state         = ParticipantState.InConsultation;
            var room          = RoomType.ConsultationRoom1;

            var command = new UpdateParticipantStatusAndRoomCommand(conferenceId, participantId, state, room);

            Assert.ThrowsAsync <ConferenceNotFoundException>(() => _handler.Handle(command));
        }
Esempio n. 6
0
 protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
 {
     foreach (var participant in SourceParticipantRoom.RoomParticipants)
     {
         var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent);
         var command           =
             new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, participant.ParticipantId, participantStatus,
                                                       callbackEvent.TransferTo, callbackEvent.TransferredToRoomLabel);
         await CommandHandler.Handle(command);
     }
 }
        protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
        {
            var participantState         = ParticipantState.Available;
            var room                     = RoomType.WaitingRoom;
            var updateParticipantCommand = new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id,
                                                                                     participantState, room, null);
            await CommandHandler.Handle(updateParticipantCommand);

            var addParticipantToRoomCommand =
                new AddParticipantToParticipantRoomCommand(SourceParticipantRoom.Id, SourceParticipant.Id);
            await CommandHandler.Handle(addParticipantToRoomCommand);
        }
Esempio n. 8
0
        private async Task PublishParticipantDisconnectMessage()
        {
            var participantState = ParticipantState.Disconnected;
            var command          =
                new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantState,
                                                          null);
            await CommandHandler.Handle(command);

            if (SourceConference.State != ConferenceState.Closed)
            {
                await AddDisconnectedTask();
            }
        }
Esempio n. 9
0
        public async Task Should_send_disconnect_messages_to_participants_and_service_bus_on_participant_disconnect()
        {
            var conference          = TestConference;
            var participantForEvent = conference.GetParticipants().First(x => x.UserRole == UserRole.Individual);
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.Disconnected,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                ConferenceId  = conference.Id,
                Reason        = "Unexpected drop",
                TimeStampUtc  = DateTime.UtcNow
            };
            var updateStatusCommand = new UpdateParticipantStatusAndRoomCommand(conference.Id, participantForEvent.Id,
                                                                                ParticipantState.Disconnected, null);

            CommandHandlerMock.Setup(x => x.Handle(updateStatusCommand));

            var addParticipantDisconnectedTask =
                new AddTaskCommand(conference.Id, conference.Id, "Disconnected", TaskType.Participant);

            CommandHandlerMock.Setup(x => x.Handle(addParticipantDisconnectedTask));

            await _sut.HandleAsync(callbackEvent);


            CommandHandlerMock.Verify(
                x => x.Handle(It.Is <UpdateParticipantStatusAndRoomCommand>(command =>
                                                                            command.ConferenceId == conference.Id &&
                                                                            command.ParticipantId == participantForEvent.Id &&
                                                                            command.ParticipantState == ParticipantState.Disconnected &&
                                                                            command.Room == null)), Times.Once);

            CommandHandlerMock.Verify(
                x => x.Handle(It.Is <AddTaskCommand>(command =>
                                                     command.ConferenceId == conference.Id &&
                                                     command.OriginId == participantForEvent.Id &&
                                                     command.TaskType == TaskType.Participant)), Times.Once);

            CommandHandlerMock.Verify(
                x => x.Handle(It.Is <AddTaskCommand>(command =>
                                                     command.ConferenceId == conference.Id &&
                                                     command.OriginId == conference.Id &&
                                                     command.TaskType == TaskType.Hearing)), Times.Never);

            CommandHandlerMock.Verify(
                x => x.Handle(It.Is <AddTaskCommand>(command =>
                                                     command.ConferenceId == participantForEvent.Id &&
                                                     command.OriginId == participantForEvent.Id &&
                                                     command.TaskType == TaskType.Judge)), Times.Never);
        }
        public async Task Should_throw_participant_not_found_exception_when_participant_does_not_exist()
        {
            var seededConference = await TestDataManager.SeedConference();

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceId = seededConference.Id;
            var participantId = Guid.NewGuid();
            var state         = ParticipantState.InConsultation;
            var room          = RoomType.ConsultationRoom1;

            var command = new UpdateParticipantStatusAndRoomCommand(_newConferenceId, participantId, state, room);

            Assert.ThrowsAsync <ParticipantNotFoundException>(() => _handler.Handle(command));
        }
Esempio n. 11
0
        protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
        {
            var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent);

            var command =
                new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantStatus,
                                                          callbackEvent.TransferTo);
            await CommandHandler.Handle(command);

            if (participantStatus == ParticipantState.InConsultation)
            {
                _roomReservationService.RemoveRoomReservation(SourceConference.Id, (RoomType)callbackEvent.TransferTo);
            }
        }
Esempio n. 12
0
        public async Task should_not_throw_room_not_found_exception_when_updating_participant_to_InConsultation()
        {
            var seededConference = await TestDataManager.SeedConference();

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceIds.Add(seededConference.Id);
            var participant = seededConference.GetParticipants().First();
            const ParticipantState state = ParticipantState.Disconnected;

            var command = new UpdateParticipantStatusAndRoomCommand(seededConference.Id, participant.Id, state, null, null);
            await _handler.Handle(command);

            var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(seededConference.Id));

            var updatedParticipant = updatedConference.GetParticipants().Single(x => x.Username == participant.Username);
            var afterState         = updatedParticipant.GetCurrentStatus();

            afterState.ParticipantState.Should().Be(state);
        }
Esempio n. 13
0
        [Test] public async Task should_add_participant_into_a_room_when_static_room_label__provided_but_returns_null()
        {
            var seededConference = await TestDataManager.SeedConference();

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceIds.Add(seededConference.Id);
            var participant = seededConference.GetParticipants().First();
            const ParticipantState state           = ParticipantState.InConsultation;
            const string           staticRoomlabel = "ConsultationRoom1";

            var command = new UpdateParticipantStatusAndRoomCommand(seededConference.Id, participant.Id, state, null, staticRoomlabel);
            await _handler.Handle(command);

            var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(seededConference.Id));

            var updatedParticipant = updatedConference.GetParticipants().Single(x => x.Username == participant.Username);
            var afterState         = updatedParticipant.GetCurrentStatus();

            afterState.ParticipantState.Should().Be(state);
            updatedParticipant.CurrentRoom.Should().BeNull();
            updatedParticipant.CurrentConsultationRoom.Label.Should().Be(staticRoomlabel);
        }
Esempio n. 14
0
        protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
        {
            var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent);

            var command =
                new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantStatus,
                                                          callbackEvent.TransferTo, callbackEvent.TransferredToRoomLabel);

            await CommandHandler.Handle(command);

            if (!callbackEvent.TransferredFromRoomLabel.ToLower().Contains("consultation") || callbackEvent.TransferTo == RoomType.HearingRoom)
            {
                return;
            }

            var roomQuery = new GetConsultationRoomByIdQuery(SourceConference.Id, callbackEvent.TransferredFromRoomLabel);
            var room      = await QueryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery);

            if (room == null)
            {
                _logger.LogError("Unable to find room {roomLabel} in conference {conferenceId}", callbackEvent.TransferredFromRoomLabel, SourceConference.Id);
            }
            else if (room.Status == RoomStatus.Live && !room.RoomParticipants.Any())
            {
                foreach (var endpoint in room.RoomEndpoints)
                {
                    await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString());
                }
            }
            else if (room.RoomEndpoints.Any())
            {
                var participantsEndpoints = SourceConference.GetEndpoints().Where(x => x.DefenceAdvocate?.Equals(SourceParticipant.Username, System.StringComparison.OrdinalIgnoreCase) ?? false).Select(x => x.Id).ToList();
                foreach (var endpoint in room.RoomEndpoints.Where(roomEndpoint => participantsEndpoints.Contains(roomEndpoint.EndpointId)))
                {
                    await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString());
                }
            }
        }
        protected override async Task PublishStatusAsync(CallbackEvent callbackEvent)
        {
            if (SourceParticipant == null)
            {
                return;
            }

            await ReturnRoomParticipantToWaitingRoom();

            var participantState         = ParticipantState.Disconnected;
            var updateParticipantCommand = new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id,
                                                                                     participantState, null, null);
            await CommandHandler.Handle(updateParticipantCommand);

            var removeFromRoomCommand =
                new RemoveParticipantFromParticipantRoomCommand(SourceParticipantRoom.Id, SourceParticipant.Id);
            await CommandHandler.Handle(removeFromRoomCommand);

            if (!SourceConference.IsClosed())
            {
                await AddDisconnectedTask();
            }
        }
        public async Task Should_update_conference_status()
        {
            var seededConference = await TestDataManager.SeedConference();

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceId = seededConference.Id;
            var participant = seededConference.GetParticipants().First();
            const ParticipantState state = ParticipantState.InConsultation;
            const RoomType         room  = RoomType.ConsultationRoom1;

            var beforeState = participant.GetCurrentStatus();

            var command = new UpdateParticipantStatusAndRoomCommand(_newConferenceId, participant.Id, state, room);
            await _handler.Handle(command);

            var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(_newConferenceId));

            var updatedParticipant = updatedConference.GetParticipants().Single(x => x.Username == participant.Username);
            var afterState         = updatedParticipant.GetCurrentStatus();

            afterState.Should().NotBe(beforeState);
            afterState.ParticipantState.Should().Be(state);
            updatedParticipant.CurrentRoom.Should().Be(room);
        }