public async stt::Task CreateDocumentRequestObjectAsync() { moq::Mock <Firestore.FirestoreClient> mockGrpcClient = new moq::Mock <Firestore.FirestoreClient>(moq::MockBehavior.Strict); CreateDocumentRequest request = new CreateDocumentRequest { Parent = "projects/test/databases/test/documents/parent7858e4d0", CollectionId = "collection_idd84d1a0a", DocumentId = "document_id10fcfae7", Document = new Document(), Mask = new DocumentMask(), }; Document expectedResponse = new Document { Name = "name1c9368b0", Fields = { { "key8a0b6e3c", new Value() }, }, CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.CreateDocumentAsync(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.CreateDocumentAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Document responseCancellationToken = await client.CreateDocumentAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task CreateDocumentAsync() { Mock <Firestore.FirestoreClient> mockGrpcClient = new Mock <Firestore.FirestoreClient>(MockBehavior.Strict); CreateDocumentRequest request = new CreateDocumentRequest { Parent = new AnyPathName("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]").ToString(), CollectionId = "collectionId-821242276", DocumentId = "documentId506676927", Document = new Document(), }; Document expectedResponse = new Document { Name = "name3373707", }; mockGrpcClient.Setup(x => x.CreateDocumentAsync(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.CreateDocumentAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }