public async stt::Task GetAutoscalingPolicyResourceNamesAsync() { moq::Mock <AutoscalingPolicyService.AutoscalingPolicyServiceClient> mockGrpcClient = new moq::Mock <AutoscalingPolicyService.AutoscalingPolicyServiceClient>(moq::MockBehavior.Strict); GetAutoscalingPolicyRequest request = new GetAutoscalingPolicyRequest { AutoscalingPolicyName = AutoscalingPolicyName.FromProjectLocationAutoscalingPolicy("[PROJECT]", "[LOCATION]", "[AUTOSCALING_POLICY]"), }; AutoscalingPolicy expectedResponse = new AutoscalingPolicy { Id = "id74b70bb8", AutoscalingPolicyName = AutoscalingPolicyName.FromProjectLocationAutoscalingPolicy("[PROJECT]", "[LOCATION]", "[AUTOSCALING_POLICY]"), BasicAlgorithm = new BasicAutoscalingAlgorithm(), WorkerConfig = new InstanceGroupAutoscalingPolicyConfig(), SecondaryWorkerConfig = new InstanceGroupAutoscalingPolicyConfig(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, }; mockGrpcClient.Setup(x => x.GetAutoscalingPolicyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AutoscalingPolicy>(stt::Task.FromResult(expectedResponse), null, null, null, null)); AutoscalingPolicyServiceClient client = new AutoscalingPolicyServiceClientImpl(mockGrpcClient.Object, null); AutoscalingPolicy responseCallSettings = await client.GetAutoscalingPolicyAsync(request.AutoscalingPolicyName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); AutoscalingPolicy responseCancellationToken = await client.GetAutoscalingPolicyAsync(request.AutoscalingPolicyName, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetAutoscalingPolicyAsync2() { Mock <AutoscalingPolicyService.AutoscalingPolicyServiceClient> mockGrpcClient = new Mock <AutoscalingPolicyService.AutoscalingPolicyServiceClient>(MockBehavior.Strict); GetAutoscalingPolicyRequest request = new GetAutoscalingPolicyRequest { Name = new AutoscalingPolicyName("[PROJECT]", "[REGION]", "[AUTOSCALING_POLICY]").ToString(), }; AutoscalingPolicy expectedResponse = new AutoscalingPolicy { Id = "id3355", Name = "name2-1052831874", }; mockGrpcClient.Setup(x => x.GetAutoscalingPolicyAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <AutoscalingPolicy>(Task.FromResult(expectedResponse), null, null, null, null)); AutoscalingPolicyServiceClient client = new AutoscalingPolicyServiceClientImpl(mockGrpcClient.Object, null); AutoscalingPolicy response = await client.GetAutoscalingPolicyAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }