public void GetAgent()
        {
            moq::Mock <Agents.AgentsClient> mockGrpcClient = new moq::Mock <Agents.AgentsClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAgentRequest request = new GetAgentRequest
            {
                AgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
            };
            Agent expectedResponse = new Agent
            {
                AgentName                = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
                DisplayName              = "display_name137f65c2",
                DefaultLanguageCode      = "default_language_codee612e130",
                TimeZone                 = "time_zone73f23b20",
                Description              = "description2cf9da67",
                AvatarUri                = "avatar_urie1767db7",
                SpeechToTextSettings     = new SpeechToTextSettings(),
                StartFlowAsFlowName      = FlowName.FromProjectLocationAgentFlow("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"),
                EnableStackdriverLogging = false,
                EnableSpellCorrection    = true,
            };

            mockGrpcClient.Setup(x => x.GetAgent(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AgentsClient client   = new AgentsClientImpl(mockGrpcClient.Object, null);
            Agent        response = client.GetAgent(request.Name);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #2
0
        public void GetAgentRequestObject()
        {
            moq::Mock <Agents.AgentsClient> mockGrpcClient = new moq::Mock <Agents.AgentsClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAgentRequest request = new GetAgentRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
            };
            Agent expectedResponse = new Agent
            {
                ParentAsProjectName    = gagr::ProjectName.FromProject("[PROJECT]"),
                DisplayName            = "display_name137f65c2",
                DefaultLanguageCode    = "default_language_codee612e130",
                SupportedLanguageCodes =
                {
                    "supported_language_codesbcd806b9",
                },
                TimeZone                = "time_zone73f23b20",
                Description             = "description2cf9da67",
                AvatarUri               = "avatar_urie1767db7",
                EnableLogging           = false,
                MatchMode               = Agent.Types.MatchMode.MlOnly,
                ClassificationThreshold = -7.68696135E+17F,
                ApiVersion              = Agent.Types.ApiVersion.V2Beta1,
                Tier = Agent.Types.Tier.Standard,
            };

            mockGrpcClient.Setup(x => x.GetAgent(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AgentsClient client   = new AgentsClientImpl(mockGrpcClient.Object, null);
            Agent        response = client.GetAgent(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #3
0
        public void cannot_get_agent_definition_when_unauthorized()
        {
            // Arrange
            GetAgentRequest request = new GetAgentRequest()
            {
                Agent = new Agent()
                {
                    Name = AGENT_NAME,
                    MBox = new Uri(AGENT_MBOX)
                }
            };

            this._mockHttp
            .When(HttpMethod.Get, this.GetApiUrl("agents"))
            .WithQueryString("agent", AGENT_QS)
            .Respond(HttpStatusCode.Forbidden);

            // Act
            Func <Task> action = async() =>
            {
                await this._client.Agents.Get(request);
            };

            // Assert
            action.ShouldThrow <ForbiddenException>();
        }
Example #4
0
        public async Task can_get_agent_definition()
        {
            // Arrange
            GetAgentRequest request = new GetAgentRequest()
            {
                Agent = new Agent()
                {
                    Name = AGENT_NAME,
                    MBox = new Uri(AGENT_MBOX)
                }
            };

            this._mockHttp
            .When(HttpMethod.Get, this.GetApiUrl("agents"))
            .WithQueryString("agent", AGENT_QS)
            .Respond(HttpStatusCode.OK, "application/json", this.ReadDataFile(Constants.AGENT));

            // Act
            Person actor = await this._client.Agents.Get(request);

            // Assert
            actor.Should().NotBeNull();
            actor.Name.Should().NotBeNull().And.HaveCount(x => x > 0).And.Contain(request.Agent.Name);
            actor.MBox.Should().NotBeNull().And.HaveCount(x => x > 0).And.Contain(request.Agent.MBox);
        }
Example #5
0
        public async Task GetAgentAsync2()
        {
            Mock <Agents.AgentsClient> mockGrpcClient = new Mock <Agents.AgentsClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            GetAgentRequest request = new GetAgentRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
            };
            Agent expectedResponse = new Agent
            {
                Parent                  = "parent21175163357",
                DisplayName             = "displayName1615086568",
                DefaultLanguageCode     = "defaultLanguageCode856575222",
                TimeZone                = "timeZone36848094",
                Description             = "description-1724546052",
                AvatarUri               = "avatarUri-402824826",
                EnableLogging           = false,
                ClassificationThreshold = 1.11581064E8f,
            };

            mockGrpcClient.Setup(x => x.GetAgentAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Agent>(Task.FromResult(expectedResponse), null, null, null, null));
            AgentsClient client   = new AgentsClientImpl(mockGrpcClient.Object, null);
            Agent        response = await client.GetAgentAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Example #6
0
        /// <summary>
        /// 获取企业号应用
        /// 该API用于获取授权方的企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="suite_id">套件ID</param>
        /// <param name="auth_corpid">授权方企业ID</param>
        /// <param name="permanent_code">永久授权码</param>
        /// <param name="agentid">授权方应用ID</param>
        /// <param name="suiteAccessToken"></param>
        /// <returns></returns>
        public static GetAgentResult GetAgent(this IQyHelper helper, string suite_id, string auth_corpid,
                                              string permanent_code, string agentid, string suiteAccessToken)
        {
            var request = new GetAgentRequest();

            request.suite_id       = suite_id;
            request.auth_corpid    = auth_corpid;
            request.permanent_code = permanent_code;
            request.agentid        = agentid;
            return(helper.GetAgent(request, suiteAccessToken));
        }
        /// <summary>
        /// Creates a waiter using the provided configuration.
        /// </summary>
        /// <param name="request">Request to send.</param>
        /// <param name="config">Wait Configuration</param>
        /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
        /// <returns>a new Oci.common.Waiter instance</returns>
        public Waiter <GetAgentRequest, GetAgentResponse> ForAgent(GetAgentRequest request, WaiterConfiguration config, params LifecycleStates[] targetStates)
        {
            var agent = new WaiterAgent <GetAgentRequest, GetAgentResponse>(
                request,
                request => client.GetAgent(request),
                response => targetStates.Contains(response.Agent.LifecycleState.Value),
                targetStates.Contains(LifecycleStates.Deleted)
                );

            return(new Waiter <GetAgentRequest, GetAgentResponse>(config, agent));
        }
 /// <summary>Snippet for GetAgent</summary>
 public void GetAgent_RequestObject()
 {
     // Snippet: GetAgent(GetAgentRequest,CallSettings)
     // Create client
     AgentsClient agentsClient = AgentsClient.Create();
     // Initialize request argument(s)
     GetAgentRequest request = new GetAgentRequest
     {
         ParentAsProjectName = new ProjectName("[PROJECT]"),
     };
     // Make the request
     Agent response = agentsClient.GetAgent(request);
     // End snippet
 }
 /// <summary>Snippet for GetAgent</summary>
 public void GetAgentRequestObject()
 {
     // Snippet: GetAgent(GetAgentRequest, CallSettings)
     // Create client
     AgentsClient agentsClient = AgentsClient.Create();
     // Initialize request argument(s)
     GetAgentRequest request = new GetAgentRequest
     {
         AgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
     };
     // Make the request
     Agent response = agentsClient.GetAgent(request);
     // End snippet
 }
        /// <summary>Snippet for GetAgentAsync</summary>
        public async Task GetAgentAsync_RequestObject()
        {
            // Snippet: GetAgentAsync(GetAgentRequest,CallSettings)
            // Additional: GetAgentAsync(GetAgentRequest,CancellationToken)
            // Create client
            AgentsClient agentsClient = await AgentsClient.CreateAsync();

            // Initialize request argument(s)
            GetAgentRequest request = new GetAgentRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
            };
            // Make the request
            Agent response = await agentsClient.GetAgentAsync(request);

            // End snippet
        }
        /// <summary>Snippet for GetAgentAsync</summary>
        public async Task GetAgentRequestObjectAsync()
        {
            // Snippet: GetAgentAsync(GetAgentRequest, CallSettings)
            // Additional: GetAgentAsync(GetAgentRequest, CancellationToken)
            // Create client
            AgentsClient agentsClient = await AgentsClient.CreateAsync();

            // Initialize request argument(s)
            GetAgentRequest request = new GetAgentRequest
            {
                AgentName = AgentName.FromProjectLocationAgent("[PROJECT]", "[LOCATION]", "[AGENT]"),
            };
            // Make the request
            Agent response = await agentsClient.GetAgentAsync(request);

            // End snippet
        }
Example #12
0
        public GetAgentListResponse GetAgentList(GetAgentRequest request,
                                                 IEnumerable <KeyValuePair <string, string> > pairs)
        {
            var response = new GetAgentListResponse();

            try
            {
                //根据经纪人获取手机号
                bx_agent agentModel = GetAgent(request.Agent);
                //参数校验
                if (agentModel == null)
                {
                    response.Status = HttpStatusCode.Forbidden;
                    return(response);
                }

                if (!ValidateReqest(pairs, agentModel.SecretKey, request.SecCode))
                {
                    response.Status = HttpStatusCode.Forbidden;
                    return(response);
                }

                int totalCount = 0;
                var item       = _agentRepository.GetAgentList(request.CurAgent, request.Agent, request.Search, request.AgentStatus, request.CurPage, request.PageSize, out totalCount);

                if (item.Count > 0)
                {
                    response.Status     = HttpStatusCode.OK;
                    response.totalCount = totalCount;
                    response.AgentList  = item;
                }
                else
                {
                    response.Status = HttpStatusCode.NoContent;
                }
            }
            catch (Exception ex)
            {
                response.Status = HttpStatusCode.InternalServerError;
                logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException);
            }
            return(response);
        }
Example #13
0
        async Task <Person> IAgentsApi.Get(GetAgentRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            request.Validate();

            var    options  = new RequestOptions(ENDPOINT);
            string agentStr = JsonConvert.SerializeObject(request.Agent, new JsonSerializerSettings()
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            });

            options.QueryStringParameters.Add("agent", agentStr);

            HttpResponseMessage response = await this._client.GetJson(options);

            return(await response.Content.ReadAsAsync <Person>(new[] { new StrictJsonMediaTypeFormatter() }));
        }
Example #14
0
        private void HandleOutput(GetAgentRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case LifecycleStateParamSet:
                response = client.Waiters.ForAgent(request, waiterConfig, WaitForLifecycleState).Execute();
                break;

            case Default:
                response = client.GetAgent(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.Agent);
        }
Example #15
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetAgentRequest request;

            try
            {
                request = new GetAgentRequest
                {
                    AgentId      = AgentId,
                    OpcRequestId = OpcRequestId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Example #16
0
        public async stt::Task GetAgentRequestObjectAsync()
        {
            moq::Mock <Agents.AgentsClient> mockGrpcClient = new moq::Mock <Agents.AgentsClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAgentRequest request = new GetAgentRequest
            {
                ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"),
            };
            Agent expectedResponse = new Agent
            {
                ParentAsProjectName    = gagr::ProjectName.FromProject("[PROJECT]"),
                DisplayName            = "display_name137f65c2",
                DefaultLanguageCode    = "default_language_codee612e130",
                SupportedLanguageCodes =
                {
                    "supported_language_codesbcd806b9",
                },
                TimeZone      = "time_zone73f23b20",
                Description   = "description2cf9da67",
                AvatarUri     = "avatar_urie1767db7",
                EnableLogging = false,
#pragma warning disable CS0612
                MatchMode = Agent.Types.MatchMode.MlOnly,
#pragma warning restore CS0612
                ClassificationThreshold = -7.6869614E+17F,
                ApiVersion = Agent.Types.ApiVersion.V2Beta1,
                Tier       = Agent.Types.Tier.Standard,
            };

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

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Agent responseCancellationToken = await client.GetAgentAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Example #17
0
        public HttpResponseMessage GetAgentList([FromUri] GetAgentRequest request)
        {
            _logInfo.Info(string.Format("微信获取代理人列表接口请求串:{0}", Request.RequestUri));
            var viewModel = new AgentProtoViewModel();

            if (!ModelState.IsValid)
            {
                viewModel.BusinessStatus = -10000;
                string msg = ModelState.Values.Where(item => item.Errors.Count == 1).Aggregate(string.Empty, (current, item) => current + (item.Errors[0].ErrorMessage + ";   "));
                viewModel.StatusMessage = "输入参数错误," + msg;
                return(viewModel.ResponseToJson());
            }
            var response = _agentService.GetAgentList(request, Request.GetQueryNameValuePairs());

            if (response.Status == HttpStatusCode.BadRequest || response.Status == HttpStatusCode.Forbidden)
            {
                viewModel.BusinessStatus = -10001;
                viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                return(viewModel.ResponseToJson());
            }
            if (response.Status == HttpStatusCode.InternalServerError)
            {
                viewModel.BusinessStatus = -10003;
                viewModel.StatusMessage  = "服务发生异常";
            }
            if (response.Status == HttpStatusCode.NoContent)
            {
                viewModel.BusinessStatus = 0;
                viewModel.StatusMessage  = "无代理人信息";
            }
            else
            {
                viewModel.BusinessStatus = 1;
                viewModel.TotalCount     = response.totalCount;
                viewModel.AgentList      = response.AgentList.ConverToViewModel();
            }
            return(viewModel.ResponseToJson());
        }
 public GetAgentResponse GetAgentEdit(GetAgentRequest request)
 {
     return(WrapResponse <GetAgentResponse, GetAgentResponseBody>(new ServiceExecutionDelegator <GetAgentResponseBody, GetAgentRequestBody>().ResolveRequest(request.Request, (request.Request.Platform ?? ConfigurationManager.AppSettings["DefaultPlatform"]), ApiServiceName.GetAgent)));
 }
 /// <summary>
 /// Creates a waiter using default wait configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <GetAgentRequest, GetAgentResponse> ForAgent(GetAgentRequest request, params LifecycleStates[] targetStates)
 {
     return(this.ForAgent(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates));
 }
Example #20
0
        /// <summary>
        /// 获取企业号应用
        /// 该API用于获取授权方的企业号某个应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetAgentResult GetAgent(this IQyHelper helper, GetAgentRequest request, string suiteAccessToken)
        {
            string url = string.Format("{0}service/get_agent?suite_access_token={1}", baseUrl, suiteAccessToken);

            return(HttpHelper.HttpPost.GetJsonResult <GetAgentRequest, GetAgentResult>(request, url));
        }