Пример #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");
        }
Пример #2
0
        private void SerialiseEndpointConsultationRequest(EndpointConsultationRequest request)
        {
            _context.Uri        = ConsultationEndpoints.EndpointConsultationRequest;
            _context.HttpMethod = HttpMethod.Post;
            var jsonBody = RequestHelper.Serialise(request);

            _context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");
        }
Пример #3
0
        public void GivenIHaveAStartEndpointConsultationForNonexistentEndpoint()
        {
            var conference = _context.Test.Conference;
            var request    = new EndpointConsultationRequest
            {
                ConferenceId  = conference.Id,
                EndpointId    = Guid.NewGuid(),
                RequestedById = Guid.NewGuid()
            };

            SerialiseEndpointConsultationRequest(request);
        }
Пример #4
0
        public async Task Should_pass_validation()
        {
            var request = new EndpointConsultationRequest
            {
                ConferenceId  = Guid.NewGuid(),
                EndpointId    = Guid.NewGuid(),
                RequestedById = Guid.NewGuid()
            };

            var result = await _validator.ValidateAsync(request);

            result.IsValid.Should().BeTrue();
        }
Пример #5
0
        public void GivenIHaveAStartEndpointConsultationForNonexistentDefenceAdvocate()
        {
            var conference = _context.Test.Conference;
            var endpoint   = _context.Test.Conference.Endpoints.First(x => !string.IsNullOrEmpty(x.DefenceAdvocate));
            var request    = new EndpointConsultationRequest
            {
                ConferenceId  = conference.Id,
                EndpointId    = endpoint.Id,
                RequestedById = Guid.NewGuid()
            };

            SerialiseEndpointConsultationRequest(request);
        }
Пример #6
0
        public async Task Should_fail_validation_when_defence_advocate_id_is_empty()
        {
            var request = new EndpointConsultationRequest
            {
                ConferenceId      = Guid.NewGuid(),
                EndpointId        = Guid.NewGuid(),
                DefenceAdvocateId = Guid.Empty
            };

            var result = await _validator.ValidateAsync(request);

            result.Errors.Any(x => x.ErrorMessage == EndpointConsultationRequestValidation.NoDefenceAdvocateError)
            .Should().BeTrue();
        }
Пример #7
0
        public async Task Should_fail_validation_endpoint_id_is_empty()
        {
            var request = new EndpointConsultationRequest
            {
                ConferenceId  = Guid.NewGuid(),
                EndpointId    = Guid.Empty,
                RequestedById = Guid.NewGuid()
            };

            var result = await _validator.ValidateAsync(request);

            result.Errors.Any(x => x.ErrorMessage == EndpointConsultationRequestValidation.NoEndpointError)
            .Should().BeTrue();
        }
Пример #8
0
        public void GivenIHaveAStartEndpointConsultationForNonexistentConference()
        {
            var endpoint        = _context.Test.Conference.Endpoints.First(x => !string.IsNullOrEmpty(x.DefenceAdvocate));
            var defenceAdvocate =
                _context.Test.Conference.Participants.First(x => x.Username.Equals(endpoint.DefenceAdvocate));

            var request = new EndpointConsultationRequest
            {
                ConferenceId  = Guid.NewGuid(),
                EndpointId    = endpoint.Id,
                RequestedById = defenceAdvocate.Id
            };

            SerialiseEndpointConsultationRequest(request);
        }
Пример #9
0
        public async Task <IActionResult> StartPrivateConsultationWithEndpointAsync(EndpointConsultationRequest request)
        {
            _logger.LogDebug("StartPrivateConsultationWithEndpoint");

            var getConferenceByIdQuery = new GetConferenceByIdQuery(request.ConferenceId);
            var conference             =
                await _queryHandler.Handle <GetConferenceByIdQuery, Conference>(getConferenceByIdQuery);

            if (conference == null)
            {
                _logger.LogWarning("Unable to find conference");
                return(NotFound($"Unable to find conference {request.ConferenceId}"));
            }

            var endpoint = conference.GetEndpoints().SingleOrDefault(x => x.Id == request.EndpointId);

            if (endpoint == null)
            {
                _logger.LogWarning("Unable to find endpoint");
                return(NotFound($"Unable to find endpoint {request.EndpointId}"));
            }

            var defenceAdvocate = conference.GetParticipants().SingleOrDefault(x => x.Id == request.DefenceAdvocateId);

            if (defenceAdvocate == null)
            {
                _logger.LogWarning("Unable to find defence advocate");
                return(NotFound($"Unable to find defence advocate {request.DefenceAdvocateId}"));
            }

            if (string.IsNullOrWhiteSpace(endpoint.DefenceAdvocate))
            {
                var message = "Endpoint does not have a defence advocate linked";
                _logger.LogWarning(message);
                return(Unauthorized(message));
            }

            if (!endpoint.DefenceAdvocate.Trim().Equals(defenceAdvocate.Username.Trim(), StringComparison.CurrentCultureIgnoreCase))
            {
                var message = "Defence advocate is not allowed to speak to requested endpoint";
                _logger.LogWarning(message);
                return(Unauthorized(message));
            }

            await _videoPlatformService.StartEndpointPrivateConsultationAsync(conference, endpoint, defenceAdvocate);

            return(Accepted());
        }
Пример #10
0
        public void GivenIHaveAStartEndpointConsultationWithANotLinkedDefenceAdvocate()
        {
            var conference      = _context.Test.Conference;
            var endpoint        = _context.Test.Conference.Endpoints.First(x => !string.IsNullOrEmpty(x.DefenceAdvocate));
            var defenceAdvocate =
                _context.Test.Conference.Participants.First(x => !x.Username.Equals(endpoint.DefenceAdvocate));

            var request = new EndpointConsultationRequest
            {
                ConferenceId  = conference.Id,
                EndpointId    = endpoint.Id,
                RequestedById = defenceAdvocate.Id
            };

            SerialiseEndpointConsultationRequest(request);
        }
Пример #11
0
        public void GivenIHaveAStartEndpointConsultationWithoutALinkedDefenceAdvocate()
        {
            var conference      = _context.Test.Conference;
            var endpoint        = _context.Test.Conference.Endpoints.First(x => string.IsNullOrEmpty(x.DefenceAdvocate));
            var defenceAdvocate =
                _context.Test.Conference.Participants.First(x => x.UserRole == UserRole.Representative);

            var request = new EndpointConsultationRequest
            {
                ConferenceId  = conference.Id,
                EndpointId    = endpoint.Id,
                RequestedById = defenceAdvocate.Id
            };

            SerialiseEndpointConsultationRequest(request);
        }
Пример #12
0
        public async Task should_return_not_found_when_endpoint_not_found()
        {
            var conferenceId = TestConference.Id;
            var endpointId   = Guid.NewGuid();

            var request = new EndpointConsultationRequest()
            {
                ConferenceId = conferenceId,
                EndpointId   = endpointId
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

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

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be($"Unable to find endpoint {request.EndpointId}");
        }
Пример #13
0
        public async Task should_return_ok_when_vho_invites()
        {
            // Arrange
            var endpointWithoutDefenceAdvocate = TestConference.GetEndpoints().First(x => string.IsNullOrWhiteSpace(x.DefenceAdvocate));
            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = TestConference.Id,
                EndpointId    = endpointWithoutDefenceAdvocate.Id,
                RequestedById = Guid.Empty,
                RoomLabel     = "NewRoom_NotInDb"
            };

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

            // Assert
            result.Should().BeOfType <OkResult>();
        }
Пример #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();
        }
Пример #15
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>();
        }
Пример #16
0
        public async Task should_return_not_found_when_defence_advocate_not_found()
        {
            var conferenceId      = TestConference.Id;
            var endpointId        = TestConference.GetEndpoints().First().Id;
            var defenceAdvocateId = Guid.NewGuid();

            var request = new EndpointConsultationRequest()
            {
                ConferenceId  = conferenceId,
                EndpointId    = endpointId,
                RequestedById = defenceAdvocateId
            };
            var result = await Controller.StartConsultationWithEndpointAsync(request);

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

            actionResult.Should().NotBeNull();
            actionResult.Value.Should().Be($"Unable to find defence advocate {request.RequestedById}");
        }
Пример #17
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");
        }
Пример #18
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");
        }
Пример #19
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>();
        }
Пример #20
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}");
        }
Пример #21
0
        public async Task <IActionResult> StartConsultationWithEndpointAsync(EndpointConsultationRequest request)
        {
            var isVhoRequest           = request.RequestedById == Guid.Empty;
            var getConferenceByIdQuery = new GetConferenceByIdQuery(request.ConferenceId);
            var conference             = await _queryHandler.Handle <GetConferenceByIdQuery, Conference>(getConferenceByIdQuery);

            if (conference == null)
            {
                _logger.LogWarning("Unable to find conference");
                return(NotFound($"Unable to find conference {request.ConferenceId}"));
            }

            var endpoint = conference.GetEndpoints().SingleOrDefault(x => x.Id == request.EndpointId);

            if (endpoint == null)
            {
                _logger.LogWarning("Unable to find endpoint");
                return(NotFound($"Unable to find endpoint {request.EndpointId}"));
            }

            var requestedBy = conference.GetParticipants().SingleOrDefault(x => x.Id == request.RequestedById);

            if (isVhoRequest || requestedBy?.UserRole == UserRole.Judge || requestedBy?.UserRole == UserRole.JudicialOfficeHolder)
            {
                await _consultationService.EndpointTransferToRoomAsync(request.ConferenceId, endpoint.Id, request.RoomLabel);

                return(Ok());
            }


            if (requestedBy == null)
            {
                _logger.LogWarning("Unable to find defence advocate");
                return(NotFound($"Unable to find defence advocate {request.RequestedById}"));
            }

            if (string.IsNullOrWhiteSpace(endpoint.DefenceAdvocate))
            {
                const string message = "Endpoint does not have a defence advocate linked";
                _logger.LogWarning(message);
                return(Unauthorized(message));
            }

            if (!endpoint.DefenceAdvocate.Trim().Equals(requestedBy.Username.Trim(), StringComparison.CurrentCultureIgnoreCase))
            {
                const string message = "Defence advocate is not allowed to speak to requested endpoint";
                _logger.LogWarning(message);
                return(Unauthorized(message));
            }

            var roomQuery = new GetConsultationRoomByIdQuery(request.ConferenceId, request.RoomLabel);
            var room      = await _queryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery);

            if (room == null)
            {
                _logger.LogWarning($"Unable to find room {request.RoomLabel}");
                return(NotFound($"Unable to find room {request.RoomLabel}"));
            }

            if (room.RoomEndpoints.Any())
            {
                _logger.LogWarning("Unable to join endpoint {endpointId} to {RoomLabel}", endpoint.Id, request.RoomLabel);
                return(BadRequest("Room already has an active endpoint"));
            }

            await _consultationService.EndpointTransferToRoomAsync(request.ConferenceId, endpoint.Id, request.RoomLabel);

            return(Ok());
        }