using Grpc.Core; namespace ZB.MOM.WW.MxGateway.Tests.TestSupport; /// /// Minimal in-memory for exercising gRPC service /// implementations directly in unit tests, without a real gRPC transport. /// public sealed class TestServerCallContext : ServerCallContext { private readonly Metadata _requestHeaders; private readonly Metadata _responseTrailers = []; private readonly Dictionary _userState = []; private readonly CancellationToken _cancellationToken; private Status _status; private WriteOptions? _writeOptions; /// Initializes the context with the supplied request headers and cancellation token. /// Request headers visible to the service; defaults to empty. /// Cancellation token surfaced to the service. public TestServerCallContext(Metadata? requestHeaders = null, CancellationToken cancellationToken = default) { _requestHeaders = requestHeaders ?? []; _cancellationToken = cancellationToken; } /// protected override string MethodCore => "/mxaccess_gateway.v1.MxAccessGateway/Test"; /// protected override string HostCore => "localhost"; /// protected override string PeerCore => "ipv4:127.0.0.1:5000"; /// protected override DateTime DeadlineCore => DateTime.UtcNow.AddMinutes(1); /// protected override Metadata RequestHeadersCore => _requestHeaders; /// protected override CancellationToken CancellationTokenCore => _cancellationToken; /// protected override Metadata ResponseTrailersCore => _responseTrailers; /// protected override Status StatusCore { get => _status; set => _status = value; } /// protected override WriteOptions? WriteOptionsCore { get => _writeOptions; set => _writeOptions = value; } /// protected override AuthContext AuthContextCore { get; } = new( string.Empty, new Dictionary>(StringComparer.Ordinal)); /// protected override IDictionary UserStateCore => _userState; /// protected override Task WriteResponseHeadersAsyncCore(Metadata responseHeaders) => Task.CompletedTask; /// protected override ContextPropagationToken CreatePropagationTokenCore(ContextPropagationOptions? options) => throw new NotSupportedException(); }