public async stt::Task CommitRequestObjectAsync() { moq::Mock <Firestore.FirestoreClient> mockGrpcClient = new moq::Mock <Firestore.FirestoreClient>(moq::MockBehavior.Strict); CommitRequest request = new CommitRequest { Database = "projects/test/databases/databased8eee011", Writes = { new Write(), }, Transaction = proto::ByteString.CopyFromUtf8("transaction6ab7d5f4"), }; CommitResponse expectedResponse = new CommitResponse { WriteResults = { new WriteResult(), }, CommitTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.CommitAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <CommitResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); FirestoreClient client = new FirestoreClientImpl(mockGrpcClient.Object, null); CommitResponse responseCallSettings = await client.CommitAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); CommitResponse responseCancellationToken = await client.CommitAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task CommitAsync2() { Mock <Firestore.FirestoreClient> mockGrpcClient = new Mock <Firestore.FirestoreClient>(MockBehavior.Strict); CommitRequest request = new CommitRequest { Database = new DatabaseRootName("[PROJECT]", "[DATABASE]").ToString(), Writes = { }, }; CommitResponse expectedResponse = new CommitResponse(); mockGrpcClient.Setup(x => x.CommitAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <CommitResponse>(Task.FromResult(expectedResponse), null, null, null, null)); FirestoreClient client = new FirestoreClientImpl(mockGrpcClient.Object, null); CommitResponse response = await client.CommitAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }