/// <summary>Snippet for DeleteGlossary</summary> public void DeleteGlossary() { // Snippet: DeleteGlossary(GlossaryName,CallSettings) // Create client TranslationServiceClient translationServiceClient = TranslationServiceClient.Create(); // Initialize request argument(s) GlossaryName name = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); // Make the request Operation <DeleteGlossaryResponse, DeleteGlossaryMetadata> response = translationServiceClient.DeleteGlossary(name); // Poll until the returned long-running operation is complete Operation <DeleteGlossaryResponse, DeleteGlossaryMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result DeleteGlossaryResponse result = completedResponse.Result; // 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 <DeleteGlossaryResponse, DeleteGlossaryMetadata> retrievedResponse = translationServiceClient.PollOnceDeleteGlossary(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result DeleteGlossaryResponse retrievedResult = retrievedResponse.Result; } // End snippet }
public async Task GetGlossaryAsync() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); GetGlossaryRequest expectedRequest = new GetGlossaryRequest { GlossaryName = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"), }; Glossary expectedResponse = new Glossary { GlossaryName = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"), EntryCount = 811131134, }; mockGrpcClient.Setup(x => x.GetGlossaryAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Glossary>(Task.FromResult(expectedResponse), null, null, null, null)); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); GlossaryName name = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); Glossary response = await client.GetGlossaryAsync(name); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for DeleteGlossaryAsync</summary> public async Task DeleteGlossaryAsync() { // Snippet: DeleteGlossaryAsync(string,CallSettings) // Additional: DeleteGlossaryAsync(string,CancellationToken) // Create client TranslationServiceClient translationServiceClient = await TranslationServiceClient.CreateAsync(); // Initialize request argument(s) string formattedName = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]").ToString(); // Make the request Operation <DeleteGlossaryResponse, DeleteGlossaryMetadata> response = await translationServiceClient.DeleteGlossaryAsync(formattedName); // Poll until the returned long-running operation is complete Operation <DeleteGlossaryResponse, DeleteGlossaryMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result DeleteGlossaryResponse result = completedResponse.Result; // 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 <DeleteGlossaryResponse, DeleteGlossaryMetadata> retrievedResponse = await translationServiceClient.PollOnceDeleteGlossaryAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result DeleteGlossaryResponse retrievedResult = retrievedResponse.Result; } // End snippet }
public void GetGlossary() { Mock <TranslationService.TranslationServiceClient> mockGrpcClient = new Mock <TranslationService.TranslationServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); GetGlossaryRequest expectedRequest = new GetGlossaryRequest { Name = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]").ToString(), }; Glossary expectedResponse = new Glossary { Name = "name2-1052831874", EntryCount = 811131134, }; mockGrpcClient.Setup(x => x.GetGlossary(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); TranslationServiceClient client = new TranslationServiceClientImpl(mockGrpcClient.Object, null); string formattedName = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]").ToString(); Glossary response = client.GetGlossary(formattedName); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for GetGlossary</summary> public void GetGlossary() { // Snippet: GetGlossary(GlossaryName,CallSettings) // Create client TranslationServiceClient translationServiceClient = TranslationServiceClient.Create(); // Initialize request argument(s) GlossaryName name = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); // Make the request Glossary response = translationServiceClient.GetGlossary(name); // End snippet }
/// <summary>Snippet for GetGlossaryAsync</summary> public async Task GetGlossaryAsync() { // Snippet: GetGlossaryAsync(GlossaryName,CallSettings) // Additional: GetGlossaryAsync(GlossaryName,CancellationToken) // Create client TranslationServiceClient translationServiceClient = await TranslationServiceClient.CreateAsync(); // Initialize request argument(s) GlossaryName name = new GlossaryName("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); // Make the request Glossary response = await translationServiceClient.GetGlossaryAsync(name); // End snippet }