public async Task CreateIntentAsync() { Mock <Intents.IntentsClient> mockGrpcClient = new Mock <Intents.IntentsClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); CreateIntentRequest expectedRequest = new CreateIntentRequest { ParentAsProjectAgentName = new ProjectAgentName("[PROJECT]"), Intent = new Intent(), }; Intent expectedResponse = new Intent { IntentName = new IntentName("[PROJECT]", "[INTENT]"), DisplayName = "displayName1615086568", Priority = 1165461084, IsFallback = false, MlDisabled = true, Action = "action-1422950858", ResetContexts = true, RootFollowupIntentName = "rootFollowupIntentName402253784", ParentFollowupIntentName = "parentFollowupIntentName-1131901680", }; mockGrpcClient.Setup(x => x.CreateIntentAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Intent>(Task.FromResult(expectedResponse), null, null, null, null)); IntentsClient client = new IntentsClientImpl(mockGrpcClient.Object, null); ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); Intent intent = new Intent(); Intent response = await client.CreateIntentAsync(parent, intent); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for BatchDeleteIntents</summary> public void BatchDeleteIntents() { // Snippet: BatchDeleteIntents(ProjectAgentName,IEnumerable<Intent>,CallSettings) // Create client IntentsClient intentsClient = IntentsClient.Create(); // Initialize request argument(s) ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); IEnumerable <Intent> intents = new List <Intent>(); // Make the request Operation <Empty, Struct> response = intentsClient.BatchDeleteIntents(parent, intents); // Poll until the returned long-running operation is complete Operation <Empty, Struct> completedResponse = response.PollUntilCompleted(); // The long-running operation is now complete. // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Empty, Struct> retrievedResponse = intentsClient.PollOnceBatchDeleteIntents(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // The long-running operation is now complete. } // End snippet }
public async Task CreateEntityTypeAsync2() { Mock <EntityTypes.EntityTypesClient> mockGrpcClient = new Mock <EntityTypes.EntityTypesClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); CreateEntityTypeRequest expectedRequest = new CreateEntityTypeRequest { ParentAsProjectAgentName = new ProjectAgentName("[PROJECT]"), EntityType = new EntityType(), LanguageCode = "languageCode-412800396", }; EntityType expectedResponse = new EntityType { EntityTypeName = new EntityTypeName("[PROJECT]", "[ENTITY_TYPE]"), DisplayName = "displayName1615086568", }; mockGrpcClient.Setup(x => x.CreateEntityTypeAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <EntityType>(Task.FromResult(expectedResponse), null, null, null, null)); EntityTypesClient client = new EntityTypesClientImpl(mockGrpcClient.Object, null); ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); EntityType entityType = new EntityType(); string languageCode = "languageCode-412800396"; EntityType response = await client.CreateEntityTypeAsync(parent, entityType, languageCode); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void CreateEntityType() { Mock <EntityTypes.EntityTypesClient> mockGrpcClient = new Mock <EntityTypes.EntityTypesClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); CreateEntityTypeRequest expectedRequest = new CreateEntityTypeRequest { ParentAsProjectAgentName = new ProjectAgentName("[PROJECT]"), EntityType = new EntityType(), }; EntityType expectedResponse = new EntityType { EntityTypeName = new EntityTypeName("[PROJECT]", "[ENTITY_TYPE]"), DisplayName = "displayName1615086568", }; mockGrpcClient.Setup(x => x.CreateEntityType(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); EntityTypesClient client = new EntityTypesClientImpl(mockGrpcClient.Object, null); ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); EntityType entityType = new EntityType(); EntityType response = client.CreateEntityType(parent, entityType); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for CreateIntent</summary> public void CreateIntent1() { // Snippet: CreateIntent(ProjectAgentName,Intent,CallSettings) // Create client IntentsClient intentsClient = IntentsClient.Create(); // Initialize request argument(s) ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); Intent intent = new Intent(); // Make the request Intent response = intentsClient.CreateIntent(parent, intent); // End snippet }
/// <summary>Snippet for CreateIntentAsync</summary> public async Task CreateIntentAsync1() { // Snippet: CreateIntentAsync(ProjectAgentName,Intent,CallSettings) // Additional: CreateIntentAsync(ProjectAgentName,Intent,CancellationToken) // Create client IntentsClient intentsClient = await IntentsClient.CreateAsync(); // Initialize request argument(s) ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); Intent intent = new Intent(); // Make the request Intent response = await intentsClient.CreateIntentAsync(parent, intent); // End snippet }
public async Task <ActionResult <dynamic> > Message([FromQuery(Name = "q")] string query) { IntentsClient intentsClient = await IntentsClient.CreateAsync(); ProjectAgentName parent = new ProjectAgentName("party-supplier"); PagedAsyncEnumerable <ListIntentsResponse, Intent> response = intentsClient.ListIntentsAsync(parent); var results = new List <Intent>(); await response.ForEachAsync(item => { results.Add(item); }); return(results); }
/// <summary>Snippet for ListIntentsAsync</summary> public async Task ListIntentsAsync2() { // Snippet: ListIntentsAsync(ProjectAgentName,string,string,int?,CallSettings) // Create client IntentsClient intentsClient = await IntentsClient.CreateAsync(); // Initialize request argument(s) ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); string languageCode = ""; // Make the request PagedAsyncEnumerable <ListIntentsResponse, Intent> response = intentsClient.ListIntentsAsync(parent: parent, languageCode: languageCode); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Intent item) => { // Do something with each item Console.WriteLine(item); }); // Or iterate over pages (of server-defined size), performing one RPC per page await response.AsRawResponses().ForEachAsync((ListIntentsResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Intent item in page) { Console.WriteLine(item); } }); // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Intent> singlePage = await response.ReadPageAsync(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Intent item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for ListIntents</summary> public void ListIntents1() { // Snippet: ListIntents(ProjectAgentName,string,int?,CallSettings) // Create client IntentsClient intentsClient = IntentsClient.Create(); // Initialize request argument(s) ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); // Make the request PagedEnumerable <ListIntentsResponse, Intent> response = intentsClient.ListIntents(parent); // Iterate over all response items, lazily performing RPCs as required foreach (Intent item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListIntentsResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Intent item in page) { Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Intent> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Intent item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
public void CreateIntent2() { Mock <Intents.IntentsClient> mockGrpcClient = new Mock <Intents.IntentsClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); CreateIntentRequest expectedRequest = new CreateIntentRequest { ParentAsProjectAgentName = new ProjectAgentName("[PROJECT]"), Intent = new Intent(), LanguageCode = "languageCode-412800396", }; Intent expectedResponse = new Intent { IntentName = new IntentName("[PROJECT]", "[INTENT]"), DisplayName = "displayName1615086568", Priority = 1165461084, IsFallback = false, MlDisabled = true, Action = "action-1422950858", ResetContexts = true, RootFollowupIntentName = "rootFollowupIntentName402253784", ParentFollowupIntentName = "parentFollowupIntentName-1131901680", }; mockGrpcClient.Setup(x => x.CreateIntent(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); IntentsClient client = new IntentsClientImpl(mockGrpcClient.Object, null); ProjectAgentName parent = new ProjectAgentName("[PROJECT]"); Intent intent = new Intent(); string languageCode = "languageCode-412800396"; Intent response = client.CreateIntent(parent, intent, languageCode); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }