public async stt::Task SynthesizeSpeechAsync() { moq::Mock <TextToSpeech.TextToSpeechClient> mockGrpcClient = new moq::Mock <TextToSpeech.TextToSpeechClient>(moq::MockBehavior.Strict); SynthesizeSpeechRequest request = new SynthesizeSpeechRequest { Input = new SynthesisInput(), Voice = new VoiceSelectionParams(), AudioConfig = new AudioConfig(), }; SynthesizeSpeechResponse expectedResponse = new SynthesizeSpeechResponse { AudioContent = proto::ByteString.CopyFromUtf8("audio_content20992f23"), Timepoints = { new Timepoint(), }, AudioConfig = new AudioConfig(), }; mockGrpcClient.Setup(x => x.SynthesizeSpeechAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SynthesizeSpeechResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); TextToSpeechClient client = new TextToSpeechClientImpl(mockGrpcClient.Object, null); SynthesizeSpeechResponse responseCallSettings = await client.SynthesizeSpeechAsync(request.Input, request.Voice, request.AudioConfig, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); SynthesizeSpeechResponse responseCancellationToken = await client.SynthesizeSpeechAsync(request.Input, request.Voice, request.AudioConfig, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task SynthesizeSpeechAsync() { Mock <TextToSpeech.TextToSpeechClient> mockGrpcClient = new Mock <TextToSpeech.TextToSpeechClient>(MockBehavior.Strict); SynthesizeSpeechRequest expectedRequest = new SynthesizeSpeechRequest { Input = new SynthesisInput(), Voice = new VoiceSelectionParams(), AudioConfig = new AudioConfig(), }; SynthesizeSpeechResponse expectedResponse = new SynthesizeSpeechResponse { AudioContent = ByteString.CopyFromUtf8("16"), }; mockGrpcClient.Setup(x => x.SynthesizeSpeechAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <SynthesizeSpeechResponse>(Task.FromResult(expectedResponse), null, null, null, null)); TextToSpeechClient client = new TextToSpeechClientImpl(mockGrpcClient.Object, null); SynthesisInput input = new SynthesisInput(); VoiceSelectionParams voice = new VoiceSelectionParams(); AudioConfig audioConfig = new AudioConfig(); SynthesizeSpeechResponse response = await client.SynthesizeSpeechAsync(input, voice, audioConfig); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }