Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            UpdateEndpointRequest request;

            try
            {
                request = new UpdateEndpointRequest
                {
                    EndpointId            = EndpointId,
                    UpdateEndpointDetails = UpdateEndpointDetails,
                    RegistryId            = RegistryId,
                    IfMatch      = IfMatch,
                    OpcRequestId = OpcRequestId
                };

                response = client.UpdateEndpoint(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Endpoint);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        private void PrepareUpdateEndpointRequest(Guid hearingId, Guid endpointId, UpdateEndpointRequest request)
        {
            var jsonBody = RequestHelper.Serialise(request);

            Context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            Context.Uri        = UpdateEndpoint(hearingId, endpointId);
            Context.HttpMethod = HttpMethod.Patch;
        }
        public async Task Should_pass_validation_when_displayname_is_populated()
        {
            var request = new UpdateEndpointRequest
            {
                DisplayName = "Updated display name"
            };
            var result = await _validator.ValidateAsync(request);

            result.IsValid.Should().BeTrue();
        }
        public void GivenIHaveUpdateToANon_ExistentEndpointForAConferenceRequest()
        {
            var conferenceId = _context.Test.Conference.Id;
            var sipAddress   = "*****@*****.**";
            var request      = new UpdateEndpointRequest
            {
                DisplayName = "Automated Add EP test"
            };

            SetupUpdateEndpointRequest(conferenceId, sipAddress, request);
        }
        public void GivenIHaveUpdateEndpointForAConferenceRequest()
        {
            var conferenceId = _context.Test.Conference.Id;
            var sipAddress   = _context.Test.Conference.Endpoints.First().SipAddress;
            var request      = new UpdateEndpointRequest
            {
                DisplayName     = "Automated Add EP test",
                DefenceAdvocate = "Sol One"
            };

            SetupUpdateEndpointRequest(conferenceId, sipAddress, request);
        }
        public async Task Should_fail_validation_when_display_name_is_empty()
        {
            var request = new UpdateEndpointRequest
            {
                DisplayName = string.Empty
            };

            var result = await _validator.ValidateAsync(request);

            result.Errors.Any(x => x.ErrorMessage == UpdateEndpointRequestValidation.NoDisplayNameError)
            .Should().BeTrue();
        }
Exemplo n.º 7
0
        public async stt::Task UpdateEndpointAsync()
        {
            moq::Mock <EndpointService.EndpointServiceClient> mockGrpcClient = new moq::Mock <EndpointService.EndpointServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            UpdateEndpointRequest request = new UpdateEndpointRequest
            {
                Endpoint   = new Endpoint(),
                UpdateMask = new wkt::FieldMask(),
            };
            Endpoint expectedResponse = new Endpoint
            {
                EndpointName   = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
                DisplayName    = "display_name137f65c2",
                Description    = "description2cf9da67",
                DeployedModels =
                {
                    new DeployedModel(),
                },
                TrafficSplit =
                {
                    {
                        "key8a0b6e3c",
                        1623286560
                    },
                },
                Etag   = "etage8ad7218",
                Labels =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                CreateTime           = new wkt::Timestamp(),
                UpdateTime           = new wkt::Timestamp(),
                EncryptionSpec       = new EncryptionSpec(),
                NetworkAsNetworkName = NetworkName.FromProjectNetwork("[PROJECT]", "[NETWORK]"),
                ModelDeploymentMonitoringJobAsModelDeploymentMonitoringJobName = ModelDeploymentMonitoringJobName.FromProjectLocationModelDeploymentMonitoringJob("[PROJECT]", "[LOCATION]", "[MODEL_DEPLOYMENT_MONITORING_JOB]"),
                EnablePrivateServiceConnect = false,
            };

            mockGrpcClient.Setup(x => x.UpdateEndpointAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Endpoint>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            EndpointServiceClient client  = new EndpointServiceClientImpl(mockGrpcClient.Object, null);
            Endpoint responseCallSettings = await client.UpdateEndpointAsync(request.Endpoint, request.UpdateMask, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Endpoint responseCancellationToken = await client.UpdateEndpointAsync(request.Endpoint, request.UpdateMask, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 8
0
        public void GivenIHaveUpdateEndpointToAHearingRequestWithANonexistentHearingId(Scenario scenario)
        {
            var hearingId             = GetHearingIdForTest(scenario);
            var updateEndpointRequest = new UpdateEndpointRequest()
            {
                DisplayName = $"DisplayName{Guid.NewGuid()}",
            };

            var updatedEndPointId = _context.TestData.EndPointResponses.First().Id;

            _context.TestData.TestContextData.Add(UpdatedEndPointId, updatedEndPointId);
            _context.TestData.TestContextData.Add(UpdateEndPointRequest, updateEndpointRequest);
            _context.Request = _context.Patch(UpdateEndpoint(hearingId, updatedEndPointId), updateEndpointRequest);
        }
        public void UpdateEndpoint()
        {
            moq::Mock <EndpointService.EndpointServiceClient> mockGrpcClient = new moq::Mock <EndpointService.EndpointServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            UpdateEndpointRequest request = new UpdateEndpointRequest
            {
                Endpoint   = new Endpoint(),
                UpdateMask = new wkt::FieldMask(),
            };
            Endpoint expectedResponse = new Endpoint
            {
                EndpointName   = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
                DisplayName    = "display_name137f65c2",
                Description    = "description2cf9da67",
                DeployedModels =
                {
                    new DeployedModel(),
                },
                TrafficSplit =
                {
                    {
                        "key8a0b6e3c",
                        1623286560
                    },
                },
                Etag   = "etage8ad7218",
                Labels =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                CreateTime     = new wkt::Timestamp(),
                UpdateTime     = new wkt::Timestamp(),
                EncryptionSpec = new EncryptionSpec(),
            };

            mockGrpcClient.Setup(x => x.UpdateEndpoint(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            EndpointServiceClient client = new EndpointServiceClientImpl(mockGrpcClient.Object, null);
            Endpoint response            = client.UpdateEndpoint(request.Endpoint, request.UpdateMask);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task Should_update_endpoint_and_not_send_event()
        {
            var request = new UpdateEndpointRequest
            {
                DisplayName             = "Updated Display Name With Defence Advocate Test",
                DefenceAdvocateUsername = null
            };
            var response = await Controller.UpdateEndpointAsync(HearingId, Guid.NewGuid(), request);

            response.Should().NotBeNull();
            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            CommandHandlerMock.Verify(c => c.Handle(It.IsAny <UpdateEndPointOfHearingCommand>()), Times.Once);

            EventPublisher.Verify(
                x => x.PublishAsync(It.IsAny <EndpointUpdatedIntegrationEvent>()), Times.Never);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> UpdateDisplayNameForEndpointAsync(Guid conferenceId, string sipAddress,
                                                                            [FromBody] UpdateEndpointRequest request)
        {
            _logger.LogDebug(
                "Attempting to update endpoint {sipAddress} with display name {DisplayName}", sipAddress, request.DisplayName);

            var command = new UpdateEndpointCommand(conferenceId, sipAddress, request.DisplayName, request.DefenceAdvocate);
            await _commandHandler.Handle(command);

            if (!string.IsNullOrWhiteSpace(request.DisplayName))
            {
                await UpdateDisplayNameInKinly(conferenceId);
            }

            _logger.LogDebug(
                "Successfully updated endpoint {sipAddress} with display name {DisplayName}", sipAddress, request.DisplayName);
            return(Ok());
        }
        public async Task Should_update_endpoint_and_send_event()
        {
            var endpoint = Hearing.Endpoints.First();

            EndpointId = endpoint.Id;
            var request = new UpdateEndpointRequest
            {
                DisplayName             = "Updated Display Name With Defence Advocate Test",
                DefenceAdvocateUsername = null
            };
            var response = await Controller.UpdateEndpointAsync(HearingId, EndpointId, request);

            response.Should().NotBeNull();
            var result = (NoContentResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            CommandHandlerMock.Verify(c => c.Handle(It.IsAny <UpdateEndPointOfHearingCommand>()), Times.Once);

            EventPublisher.Verify(
                x => x.PublishAsync(It.Is <EndpointUpdatedIntegrationEvent>(r =>
                                                                            r.HearingId == HearingId && r.Sip == endpoint.Sip && r.DisplayName == request.DisplayName &&
                                                                            r.DefenceAdvocateUsername == request.DefenceAdvocateUsername)), Times.Once);
        }
Exemplo n.º 13
0
 public Task UpdateEndpointInConference(Guid conferenceId, string sip, UpdateEndpointRequest request)
 {
     _logger.LogInformation("Updating endpoint {Sip} in conference {ConferenceId}", sip, conferenceId);
     return(_apiClient.UpdateDisplayNameForEndpointAsync(conferenceId, sip, request));
 }
        private void SetupUpdateEndpointRequest(Guid conferenceId, string sipAddress, UpdateEndpointRequest request)
        {
            var jsonBody = RequestHelper.Serialise(request);

            _context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            _context.Uri         = UpdateEndpoint(conferenceId, sipAddress);
            _context.HttpMethod  = HttpMethod.Patch;
        }
Exemplo n.º 15
0
 public Task UpdateEndpointInConference(Guid conferenceId, string sip, UpdateEndpointRequest request)
 {
     UpdateEndpointInConferenceCount++;
     return(Task.FromResult(HttpStatusCode.OK));
 }
        public async Task <IActionResult> UpdateEndpointAsync(Guid hearingId, Guid endpointId, UpdateEndpointRequest updateEndpointRequest)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = new UpdateEndpointRequestValidation().Validate(updateEndpointRequest);

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

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

                if (hearing == null)
                {
                    throw new HearingNotFoundException(hearingId);
                }
                var defenceAdvocate =
                    DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(updateEndpointRequest.DefenceAdvocateUsername,
                                                                        hearing.GetParticipants());
                var command = new UpdateEndPointOfHearingCommand(hearingId, endpointId, updateEndpointRequest.DisplayName, defenceAdvocate);
                await _commandHandler.Handle(command);

                var endpoint = hearing.GetEndpoints().SingleOrDefault(x => x.Id == endpointId);

                if (endpoint != null && hearing.Status == BookingStatus.Created)
                {
                    await _eventPublisher.PublishAsync(new EndpointUpdatedIntegrationEvent(hearingId, endpoint.Sip,
                                                                                           updateEndpointRequest.DisplayName, defenceAdvocate?.Person.Username));
                }
            }
            catch (HearingNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }
            catch (EndPointNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }

            return(NoContent());
        }