public async stt::Task DetectIntentRequestObjectAsync()
        {
            moq::Mock <Sessions.SessionsClient> mockGrpcClient = new moq::Mock <Sessions.SessionsClient>(moq::MockBehavior.Strict);
            DetectIntentRequest request = new DetectIntentRequest
            {
                SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
                QueryParams          = new QueryParameters(),
                QueryInput           = new QueryInput(),
                OutputAudioConfig    = new OutputAudioConfig(),
            };
            DetectIntentResponse expectedResponse = new DetectIntentResponse
            {
                ResponseId        = "response_id17f822e1",
                QueryResult       = new QueryResult(),
                OutputAudio       = proto::ByteString.CopyFromUtf8("output_audio7e712c4b"),
                OutputAudioConfig = new OutputAudioConfig(),
                ResponseType      = DetectIntentResponse.Types.ResponseType.Partial,
                AllowCancellation = true,
            };

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

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            DetectIntentResponse responseCancellationToken = await client.DetectIntentAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Beispiel #2
0
        public async Task DetectIntentAsync2()
        {
            Mock <Sessions.SessionsClient> mockGrpcClient = new Mock <Sessions.SessionsClient>(MockBehavior.Strict);
            DetectIntentRequest            request        = new DetectIntentRequest
            {
                SessionAsSessionName = new SessionName("[PROJECT]", "[SESSION]"),
                QueryInput           = new QueryInput(),
            };
            DetectIntentResponse expectedResponse = new DetectIntentResponse
            {
                ResponseId = "responseId1847552473",
            };

            mockGrpcClient.Setup(x => x.DetectIntentAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <DetectIntentResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            SessionsClient       client   = new SessionsClientImpl(mockGrpcClient.Object, null);
            DetectIntentResponse response = await client.DetectIntentAsync(request);

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