Esempio n. 1
0
        public async stt::Task BeginTransactionAsync()
        {
            moq::Mock <Firestore.FirestoreClient> mockGrpcClient = new moq::Mock <Firestore.FirestoreClient>(moq::MockBehavior.Strict);
            BeginTransactionRequest request = new BeginTransactionRequest
            {
                Database = "projects/test/databases/databased8eee011",
            };
            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));
            FirestoreClient          client = new FirestoreClientImpl(mockGrpcClient.Object, null);
            BeginTransactionResponse responseCallSettings = await client.BeginTransactionAsync(request.Database, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            BeginTransactionResponse responseCancellationToken = await client.BeginTransactionAsync(request.Database, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async Task BeginTransactionAsync2()
        {
            Mock <Firestore.FirestoreClient> mockGrpcClient = new Mock <Firestore.FirestoreClient>(MockBehavior.Strict);
            BeginTransactionRequest          request        = new BeginTransactionRequest
            {
                Database = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString(),
            };
            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));
            FirestoreClient          client   = new FirestoreClientImpl(mockGrpcClient.Object, null);
            BeginTransactionResponse response = await client.BeginTransactionAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }