public async stt::Task CreateSpanRequestObjectAsync() { moq::Mock <TraceService.TraceServiceClient> mockGrpcClient = new moq::Mock <TraceService.TraceServiceClient>(moq::MockBehavior.Strict); Span request = new Span { SpanName = SpanName.FromProjectTraceSpan("[PROJECT]", "[TRACE]", "[SPAN]"), SpanId = "span_id47c232d3", ParentSpanId = "parent_span_ide637f6a2", DisplayName = new TruncatableString(), StartTime = new wkt::Timestamp(), EndTime = new wkt::Timestamp(), Attributes = new Span.Types.Attributes(), StackTrace = new StackTrace(), TimeEvents = new Span.Types.TimeEvents(), Links = new Span.Types.Links(), Status = new gr::Status(), SameProcessAsParentSpan = false, ChildSpanCount = -1491694397, SpanKind = Span.Types.SpanKind.Consumer, }; Span expectedResponse = new Span { SpanName = SpanName.FromProjectTraceSpan("[PROJECT]", "[TRACE]", "[SPAN]"), SpanId = "span_id47c232d3", ParentSpanId = "parent_span_ide637f6a2", DisplayName = new TruncatableString(), StartTime = new wkt::Timestamp(), EndTime = new wkt::Timestamp(), Attributes = new Span.Types.Attributes(), StackTrace = new StackTrace(), TimeEvents = new Span.Types.TimeEvents(), Links = new Span.Types.Links(), Status = new gr::Status(), SameProcessAsParentSpan = false, ChildSpanCount = -1491694397, SpanKind = Span.Types.SpanKind.Consumer, }; mockGrpcClient.Setup(x => x.CreateSpanAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Span>(stt::Task.FromResult(expectedResponse), null, null, null, null)); TraceServiceClient client = new TraceServiceClientImpl(mockGrpcClient.Object, null); Span responseCallSettings = await client.CreateSpanAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Span responseCancellationToken = await client.CreateSpanAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task CreateSpanAsync() { Mock <TraceService.TraceServiceClient> mockGrpcClient = new Mock <TraceService.TraceServiceClient>(MockBehavior.Strict); apis::Span request = new apis::Span { SpanName = new SpanName("[PROJECT]", "[TRACE]", "[SPAN]"), SpanId = "spanId-2011840976", DisplayName = new TruncatableString(), StartTime = new Timestamp(), EndTime = new Timestamp(), }; apis::Span expectedResponse = new apis::Span { SpanName = new SpanName("[PROJECT]", "[TRACE]", "[SPAN]"), SpanId = "spanId2-643891741", ParentSpanId = "parentSpanId-1757797477", }; mockGrpcClient.Setup(x => x.CreateSpanAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <apis::Span>(Task.FromResult(expectedResponse), null, null, null, null)); TraceServiceClient client = new TraceServiceClientImpl(mockGrpcClient.Object, null); apis::Span response = await client.CreateSpanAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }