// Copyright (c) Microsoft Corporation. All rights reserved. // TestGrpcClient.cs using Microsoft.AutoGen.Protobuf; namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Tests.Helpers.Grpc; internal sealed class TestGrpcClient : IDisposable { public TestAsyncStreamReader RequestStream { get; } public TestServerStreamWriter ResponseStream { get; } public TestServerCallContext CallContext { get; } private CancellationTokenSource CallContextCancellation = new(); public TestGrpcClient() { CallContext = TestServerCallContext.Create(cancellationToken: CallContextCancellation.Token); RequestStream = new TestAsyncStreamReader(CallContext); ResponseStream = new TestServerStreamWriter(CallContext); } public async Task ReadNext() { var response = await ResponseStream.ReadNextAsync(); return response!; } public void AddMessage(Message message) { RequestStream.AddMessage(message); } public void Dispose() { CallContextCancellation.Cancel(); RequestStream.Dispose(); ResponseStream.Dispose(); } }