public async stt::Task CreateConversationRequestObjectAsync() { moq::Mock <Conversations.ConversationsClient> mockGrpcClient = new moq::Mock <Conversations.ConversationsClient>(moq::MockBehavior.Strict); CreateConversationRequest request = new CreateConversationRequest { ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), Conversation = new Conversation(), ConversationId = "conversation_id32c22ad5", }; Conversation expectedResponse = new Conversation { ConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), LifecycleState = Conversation.Types.LifecycleState.Unspecified, ConversationProfileAsConversationProfileName = ConversationProfileName.FromProjectConversationProfile("[PROJECT]", "[CONVERSATION_PROFILE]"), PhoneNumber = new ConversationPhoneNumber(), StartTime = new wkt::Timestamp(), EndTime = new wkt::Timestamp(), ConversationStage = Conversation.Types.ConversationStage.HumanAssistStage, }; mockGrpcClient.Setup(x => x.CreateConversationAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Conversation>(stt::Task.FromResult(expectedResponse), null, null, null, null)); ConversationsClient client = new ConversationsClientImpl(mockGrpcClient.Object, null); Conversation responseCallSettings = await client.CreateConversationAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Conversation responseCancellationToken = await client.CreateConversationAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void CreateConversation() { moq::Mock <Conversations.ConversationsClient> mockGrpcClient = new moq::Mock <Conversations.ConversationsClient>(moq::MockBehavior.Strict); CreateConversationRequest request = new CreateConversationRequest { ParentAsProjectName = gagr::ProjectName.FromProject("[PROJECT]"), Conversation = new Conversation(), }; Conversation expectedResponse = new Conversation { ConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), LifecycleState = Conversation.Types.LifecycleState.Unspecified, ConversationProfileAsConversationProfileName = ConversationProfileName.FromProjectConversationProfile("[PROJECT]", "[CONVERSATION_PROFILE]"), PhoneNumber = new ConversationPhoneNumber(), StartTime = new wkt::Timestamp(), EndTime = new wkt::Timestamp(), ConversationStage = Conversation.Types.ConversationStage.HumanAssistStage, }; mockGrpcClient.Setup(x => x.CreateConversation(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); ConversationsClient client = new ConversationsClientImpl(mockGrpcClient.Object, null); Conversation response = client.CreateConversation(request.Parent, request.Conversation); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for CompleteConversation</summary> public void CompleteConversationResourceNames() { // Snippet: CompleteConversation(ConversationName, CallSettings) // Create client ConversationsClient conversationsClient = ConversationsClient.Create(); // Initialize request argument(s) ConversationName name = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"); // Make the request Conversation response = conversationsClient.CompleteConversation(name); // End snippet }
/// <summary>Snippet for CreateParticipant</summary> public void CreateParticipantResourceNames() { // Snippet: CreateParticipant(ConversationName, Participant, CallSettings) // Create client ParticipantsClient participantsClient = ParticipantsClient.Create(); // Initialize request argument(s) ConversationName parent = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"); Participant participant = new Participant(); // Make the request Participant response = participantsClient.CreateParticipant(parent, participant); // End snippet }
/// <summary>Snippet for CompleteConversationAsync</summary> public async Task CompleteConversationResourceNamesAsync() { // Snippet: CompleteConversationAsync(ConversationName, CallSettings) // Additional: CompleteConversationAsync(ConversationName, CancellationToken) // Create client ConversationsClient conversationsClient = await ConversationsClient.CreateAsync(); // Initialize request argument(s) ConversationName name = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"); // Make the request Conversation response = await conversationsClient.CompleteConversationAsync(name); // End snippet }
/// <summary>Snippet for GetConversation</summary> public void GetConversationRequestObject() { // Snippet: GetConversation(GetConversationRequest, CallSettings) // Create client ConversationsClient conversationsClient = ConversationsClient.Create(); // Initialize request argument(s) GetConversationRequest request = new GetConversationRequest { ConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), }; // Make the request Conversation response = conversationsClient.GetConversation(request); // End snippet }
/// <summary>Snippet for ListMessagesAsync</summary> public async Task ListMessagesRequestObjectAsync() { // Snippet: ListMessagesAsync(ListMessagesRequest, CallSettings) // Create client ConversationsClient conversationsClient = await ConversationsClient.CreateAsync(); // Initialize request argument(s) ListMessagesRequest request = new ListMessagesRequest { ParentAsConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), Filter = "", }; // Make the request PagedAsyncEnumerable <ListMessagesResponse, Message> response = conversationsClient.ListMessagesAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((Message 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((ListMessagesResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Message item in page) { // Do something with each item 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 <Message> 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 (Message item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for CreateParticipant</summary> public void CreateParticipantRequestObject() { // Snippet: CreateParticipant(CreateParticipantRequest, CallSettings) // Create client ParticipantsClient participantsClient = ParticipantsClient.Create(); // Initialize request argument(s) CreateParticipantRequest request = new CreateParticipantRequest { ParentAsConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), Participant = new Participant(), }; // Make the request Participant response = participantsClient.CreateParticipant(request); // End snippet }
/// <summary>Snippet for CreateParticipantAsync</summary> public async Task CreateParticipantResourceNamesAsync() { // Snippet: CreateParticipantAsync(ConversationName, Participant, CallSettings) // Additional: CreateParticipantAsync(ConversationName, Participant, CancellationToken) // Create client ParticipantsClient participantsClient = await ParticipantsClient.CreateAsync(); // Initialize request argument(s) ConversationName parent = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"); Participant participant = new Participant(); // Make the request Participant response = await participantsClient.CreateParticipantAsync(parent, participant); // End snippet }
/// <summary>Snippet for ListParticipants</summary> public void ListParticipantsRequestObject() { // Snippet: ListParticipants(ListParticipantsRequest, CallSettings) // Create client ParticipantsClient participantsClient = ParticipantsClient.Create(); // Initialize request argument(s) ListParticipantsRequest request = new ListParticipantsRequest { ParentAsConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), }; // Make the request PagedEnumerable <ListParticipantsResponse, Participant> response = participantsClient.ListParticipants(request); // Iterate over all response items, lazily performing RPCs as required foreach (Participant 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 (ListParticipantsResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Participant item in page) { // Do something with each item 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 <Participant> 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 (Participant item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for GetConversationAsync</summary> public async Task GetConversationRequestObjectAsync() { // Snippet: GetConversationAsync(GetConversationRequest, CallSettings) // Additional: GetConversationAsync(GetConversationRequest, CancellationToken) // Create client ConversationsClient conversationsClient = await ConversationsClient.CreateAsync(); // Initialize request argument(s) GetConversationRequest request = new GetConversationRequest { ConversationName = ConversationName.FromProjectConversation("[PROJECT]", "[CONVERSATION]"), }; // Make the request Conversation response = await conversationsClient.GetConversationAsync(request); // End snippet }