public async stt::Task GetIndexRequestObjectAsync() { moq::Mock <IndexService.IndexServiceClient> mockGrpcClient = new moq::Mock <IndexService.IndexServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetIndexRequest request = new GetIndexRequest { IndexName = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]"), }; Index expectedResponse = new Index { IndexName = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]"), DisplayName = "display_name137f65c2", Description = "description2cf9da67", MetadataSchemaUri = "metadata_schema_uric874bf0a", Metadata = new wkt::Value(), DeployedIndexes = { new DeployedIndexRef(), }, Etag = "etage8ad7218", Labels = { { "key8a0b6e3c", "value60c16320" }, }, CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetIndexAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Index>(stt::Task.FromResult(expectedResponse), null, null, null, null)); IndexServiceClient client = new IndexServiceClientImpl(mockGrpcClient.Object, null); Index responseCallSettings = await client.GetIndexAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Index responseCancellationToken = await client.GetIndexAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void GetIndexResourceNames() { moq::Mock <IndexService.IndexServiceClient> mockGrpcClient = new moq::Mock <IndexService.IndexServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetIndexRequest request = new GetIndexRequest { IndexName = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]"), }; Index expectedResponse = new Index { IndexName = IndexName.FromProjectLocationIndex("[PROJECT]", "[LOCATION]", "[INDEX]"), DisplayName = "display_name137f65c2", Description = "description2cf9da67", MetadataSchemaUri = "metadata_schema_uric874bf0a", Metadata = new wkt::Value(), DeployedIndexes = { new DeployedIndexRef(), }, Etag = "etage8ad7218", Labels = { { "key8a0b6e3c", "value60c16320" }, }, CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetIndex(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); IndexServiceClient client = new IndexServiceClientImpl(mockGrpcClient.Object, null); Index response = client.GetIndex(request.IndexName); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }