public async stt::Task BeginTransactionAsync() { moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict); BeginTransactionRequest request = new BeginTransactionRequest { ProjectId = "project_id43ad98b0", }; BeginTransactionResponse expectedResponse = new BeginTransactionResponse { Transaction = proto::ByteString.CopyFromUtf8("transaction6ab7d5f4"), }; mockGrpcClient.Setup(x => x.BeginTransactionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <BeginTransactionResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); BeginTransactionResponse responseCallSettings = await client.BeginTransactionAsync(request.ProjectId, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); BeginTransactionResponse responseCancellationToken = await client.BeginTransactionAsync(request.ProjectId, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task BeginTransactionAsync2() { Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict); BeginTransactionRequest request = new BeginTransactionRequest { ProjectId = "projectId-1969970175", }; BeginTransactionResponse expectedResponse = new BeginTransactionResponse { Transaction = ByteString.CopyFromUtf8("-34"), }; mockGrpcClient.Setup(x => x.BeginTransactionAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <BeginTransactionResponse>(Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); BeginTransactionResponse response = await client.BeginTransactionAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }