public void CreateLogMetric() { Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new Mock <MetricsServiceV2.MetricsServiceV2Client>(MockBehavior.Strict); CreateLogMetricRequest expectedRequest = new CreateLogMetricRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Metric = new LogMetric(), }; LogMetric expectedResponse = new LogMetric { MetricNameOneof = MetricNameOneof.From(new MetricName("[PROJECT]", "[METRIC]")), Description = "description-1724546052", Filter = "filter-1274492040", ValueExtractor = "valueExtractor2047672534", }; mockGrpcClient.Setup(x => x.CreateLogMetric(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogMetric metric = new LogMetric(); LogMetric response = client.CreateLogMetric(parent, metric); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void CreateLogMetricResourceNames() { moq::Mock <MetricsServiceV2.MetricsServiceV2Client> mockGrpcClient = new moq::Mock <MetricsServiceV2.MetricsServiceV2Client>(moq::MockBehavior.Strict); CreateLogMetricRequest request = new CreateLogMetricRequest { ParentAsMetricName = MetricName.FromProjectMetric("[PROJECT]", "[METRIC]"), Metric = new LogMetric(), }; LogMetric expectedResponse = new LogMetric { MetricName = MetricName.FromProjectMetric("[PROJECT]", "[METRIC]"), Description = "description2cf9da67", Filter = "filtere47ac9b2", 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.CreateLogMetric(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); MetricsServiceV2Client client = new MetricsServiceV2ClientImpl(mockGrpcClient.Object, null); LogMetric response = client.CreateLogMetric(request.ParentAsMetricName, request.Metric); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }