コード例 #1
0
        public void Should_run()
        {
            var sipAddStream    = "TestSipStream";
            var randomGen       = new Mock <IRandomGenerator>();
            var endpointRequest = new EndpointRequest {
                DefenceAdvocateUsername = "******", DisplayName = "TestDispName"
            };

            var result = EndpointToResponseMapper.MapRequestToNewEndpointDto(endpointRequest, randomGen.Object, sipAddStream);

            result.Should().NotBeNull();
            result.Sip.EndsWith(sipAddStream).Should().BeTrue();
            result.DisplayName.Should().Be(endpointRequest.DisplayName);
            result.DefenceAdvocateUsername.Should().Be(endpointRequest.DefenceAdvocateUsername);
        }
コード例 #2
0
        public async Task <IActionResult> AddEndPointToHearingAsync(Guid hearingId, AddEndpointRequest addEndpointRequest)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = await new AddEndpointRequestValidation().ValidateAsync(addEndpointRequest);

            if (!result.IsValid)
            {
                ModelState.AddFluentValidationErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            try
            {
                var newEp = EndpointToResponseMapper.MapRequestToNewEndpointDto(addEndpointRequest, _randomGenerator,
                                                                                _kinlyConfiguration.SipAddressStem);

                var command = new AddEndPointToHearingCommand(hearingId, newEp);
                await _commandHandler.Handle(command);

                var hearing =
                    await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(new GetHearingByIdQuery(hearingId));

                var endpoint = hearing.GetEndpoints().FirstOrDefault(x => x.DisplayName.Equals(addEndpointRequest.DisplayName));
                if (endpoint != null && hearing.Status == BookingStatus.Created)
                {
                    await _eventPublisher.PublishAsync(new EndpointAddedIntegrationEvent(hearingId, endpoint));
                }
            }
            catch (HearingNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }

            return(NoContent());
        }