public async stt::Task GetDocumentRequestObjectAsync() { moq::Mock <Firestore.FirestoreClient> mockGrpcClient = new moq::Mock <Firestore.FirestoreClient>(moq::MockBehavior.Strict); GetDocumentRequest request = new GetDocumentRequest { Name = "projects/test/databases/test/documents/name1c9368b0", Mask = new DocumentMask(), Transaction = proto::ByteString.CopyFromUtf8("transaction6ab7d5f4"), ReadTime = new wkt::Timestamp(), }; Document expectedResponse = new Document { Name = "name1c9368b0", Fields = { { "key8a0b6e3c", new Value() }, }, CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetDocumentAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Document>(stt::Task.FromResult(expectedResponse), null, null, null, null)); FirestoreClient client = new FirestoreClientImpl(mockGrpcClient.Object, null); Document responseCallSettings = await client.GetDocumentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Document responseCancellationToken = await client.GetDocumentAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetDocumentAsync() { Mock <Firestore.FirestoreClient> mockGrpcClient = new Mock <Firestore.FirestoreClient>(MockBehavior.Strict); GetDocumentRequest request = new GetDocumentRequest { Name = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString(), }; Document expectedResponse = new Document { Name = "name2-1052831874", }; mockGrpcClient.Setup(x => x.GetDocumentAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Document>(Task.FromResult(expectedResponse), null, null, null, null)); FirestoreClient client = new FirestoreClientImpl(mockGrpcClient.Object, null); Document response = await client.GetDocumentAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }