Esempio n. 1
0
        public async stt::Task ListVoicesAsync()
        {
            moq::Mock <TextToSpeech.TextToSpeechClient> mockGrpcClient = new moq::Mock <TextToSpeech.TextToSpeechClient>(moq::MockBehavior.Strict);
            ListVoicesRequest request = new ListVoicesRequest
            {
                LanguageCode = "language_code2f6c7160",
            };
            ListVoicesResponse expectedResponse = new ListVoicesResponse
            {
                Voices = { new Voice(), },
            };

            mockGrpcClient.Setup(x => x.ListVoicesAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ListVoicesResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            TextToSpeechClient client = new TextToSpeechClientImpl(mockGrpcClient.Object, null);
            ListVoicesResponse responseCallSettings = await client.ListVoicesAsync(request.LanguageCode, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            ListVoicesResponse responseCancellationToken = await client.ListVoicesAsync(request.LanguageCode, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async Task ListVoicesAsync2()
        {
            Mock <TextToSpeech.TextToSpeechClient> mockGrpcClient = new Mock <TextToSpeech.TextToSpeechClient>(MockBehavior.Strict);
            ListVoicesRequest  request          = new ListVoicesRequest();
            ListVoicesResponse expectedResponse = new ListVoicesResponse();

            mockGrpcClient.Setup(x => x.ListVoicesAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <ListVoicesResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            TextToSpeechClient client   = new TextToSpeechClientImpl(mockGrpcClient.Object, null);
            ListVoicesResponse response = await client.ListVoicesAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }