public async Task DeleteOperationAsync() { Mock <Operations.OperationsClient> mockGrpcClient = new Mock <Operations.OperationsClient>(MockBehavior.Strict); DeleteOperationRequest expectedRequest = new DeleteOperationRequest { Name = "name3373707", }; Empty expectedResponse = new Empty(); mockGrpcClient.Setup(x => x.DeleteOperationAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Empty>(Task.FromResult(expectedResponse), null, null, null, null)); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); string name = "name3373707"; await client.DeleteOperationAsync(name); mockGrpcClient.VerifyAll(); }
public void DeleteOperation() { Mock <Operations.OperationsClient> mockGrpcClient = new Mock <Operations.OperationsClient>(MockBehavior.Strict); DeleteOperationRequest expectedRequest = new DeleteOperationRequest { Name = "name3373707", }; Empty expectedResponse = new Empty(); mockGrpcClient.Setup(x => x.DeleteOperation(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); string name = "name3373707"; client.DeleteOperation(name); mockGrpcClient.VerifyAll(); }
/// <summary> /// Constructs a client wrapper for the Speech service, with the specified gRPC client and settings. /// </summary> /// <param name="grpcClient">The underlying gRPC client.</param> /// <param name="settings">The base <see cref="SpeechSettings"/> used within this client </param> public SpeechClientImpl(Speech.SpeechClient grpcClient, SpeechSettings settings) { this.GrpcClient = grpcClient; SpeechSettings effectiveSettings = settings ?? SpeechSettings.GetDefault(); LongRunningOperationsClient = new OperationsClientImpl( grpcClient.CreateOperationsClient(), effectiveSettings.LongRunningOperationsSettings); ClientHelper clientHelper = new ClientHelper(effectiveSettings); _callRecognize = clientHelper.BuildApiCall <RecognizeRequest, RecognizeResponse>( GrpcClient.RecognizeAsync, GrpcClient.Recognize, effectiveSettings.RecognizeSettings); _callLongRunningRecognize = clientHelper.BuildApiCall <LongRunningRecognizeRequest, Operation>( GrpcClient.LongRunningRecognizeAsync, GrpcClient.LongRunningRecognize, effectiveSettings.LongRunningRecognizeSettings); _callStreamingRecognize = clientHelper.BuildApiCall <StreamingRecognizeRequest, StreamingRecognizeResponse>( GrpcClient.StreamingRecognize, effectiveSettings.StreamingRecognizeSettings, effectiveSettings.StreamingRecognizeStreamingSettings); OnConstruction(grpcClient, effectiveSettings, clientHelper); }
public async stt::Task CancelOperationAsync() { moq::Mock <Operations.OperationsClient> mockGrpcClient = new moq::Mock <Operations.OperationsClient>(moq::MockBehavior.Strict); CancelOperationRequest request = new CancelOperationRequest { Name = "name1c9368b0", }; wkt::Empty expectedResponse = new wkt::Empty { }; mockGrpcClient.Setup(x => x.CancelOperationAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <wkt::Empty>(stt::Task.FromResult(expectedResponse), null, null, null, null)); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); await client.CancelOperationAsync(request.Name, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); await client.CancelOperationAsync(request.Name, st::CancellationToken.None); mockGrpcClient.VerifyAll(); }
public void GetOperation2() { Mock <Operations.OperationsClient> mockGrpcClient = new Mock <Operations.OperationsClient>(MockBehavior.Strict); GetOperationRequest request = new GetOperationRequest { Name = "name3373707", }; Operation expectedResponse = new Operation { Name = "name2-1052831874", Done = true, }; mockGrpcClient.Setup(x => x.GetOperation(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); Operation response = client.GetOperation(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task GetOperationAsync2() { Mock <Operations.OperationsClient> mockGrpcClient = new Mock <Operations.OperationsClient>(MockBehavior.Strict); GetOperationRequest request = new GetOperationRequest { Name = "name3373707", }; Operation expectedResponse = new Operation { Name = "name2-1052831874", Done = true, }; mockGrpcClient.Setup(x => x.GetOperationAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Operation>(Task.FromResult(expectedResponse), null, null, null, null)); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); Operation response = await client.GetOperationAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void GetOperation() { moq::Mock <Operations.OperationsClient> mockGrpcClient = new moq::Mock <Operations.OperationsClient>(moq::MockBehavior.Strict); GetOperationRequest request = new GetOperationRequest { Name = "name1c9368b0", }; Operation expectedResponse = new Operation { Name = "name1c9368b0", Metadata = new wkt::Any(), Done = true, Error = new gr::Status(), Response = new wkt::Any(), }; mockGrpcClient.Setup(x => x.GetOperation(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); OperationsClient client = new OperationsClientImpl(mockGrpcClient.Object, null); Operation response = client.GetOperation(request.Name); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }