public async stt::Task GetLogMetricRequestObjectAsync() { moq::Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new moq::Mock <MetricsServiceV2.MetricsServiceV2Client>(moq::MockBehavior.Strict); GetLogMetricRequest request = new GetLogMetricRequest { MetricNameAsLogMetricName = LogMetricName.FromProjectMetric("[PROJECT]", "[METRIC]"), }; LogMetric expectedResponse = new LogMetric { LogMetricName = LogMetricName.FromProjectMetric("[PROJECT]", "[METRIC]"), Description = "description2cf9da67", Filter = "filtere47ac9b2", #pragma warning disable CS0612 Version = LogMetric.Types.ApiVersion.V2, #pragma warning restore CS0612 MetricDescriptor = new ga::MetricDescriptor(), ValueExtractor = "value_extractor09b994a6", LabelExtractors = { { "key8a0b6e3c", "value60c16320" }, }, BucketOptions = new ga::Distribution.Types.BucketOptions(), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetLogMetricAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <LogMetric>(stt::Task.FromResult(expectedResponse), null, null, null, null)); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); LogMetric responseCallSettings = await client.GetLogMetricAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); LogMetric responseCancellationToken = await client.GetLogMetricAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetLogMetricAsync2() { Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new Mock <MetricsServiceV2.MetricsServiceV2Client>(MockBehavior.Strict); GetLogMetricRequest request = new GetLogMetricRequest { MetricNameAsMetricNameOneof = MetricNameOneof.From(new MetricName("[PROJECT]", "[METRIC]")), }; LogMetric expectedResponse = new LogMetric { MetricNameOneof = MetricNameOneof.From(new MetricName("[PROJECT]", "[METRIC]")), Description = "description-1724546052", Filter = "filter-1274492040", ValueExtractor = "valueExtractor2047672534", }; mockGrpcClient.Setup(x => x.GetLogMetricAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogMetric>(Task.FromResult(expectedResponse), null, null, null, null)); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); LogMetric response = await client.GetLogMetricAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }