|
| 1 | +using Grpc.Core; |
| 2 | +using ProtoBuf.Grpc.Client; |
| 3 | +using ProtoBuf.Grpc.Configuration; |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace protobuf_net.Grpc.Test |
| 9 | +{ |
| 10 | + public class DisposeTests |
| 11 | + { |
| 12 | + [Service] |
| 13 | + public interface IDisposableService : IDisposable, IAsyncDisposable |
| 14 | + {} |
| 15 | + |
| 16 | + [Fact] |
| 17 | + public void DisposeWorks() |
| 18 | + { |
| 19 | + using var client = DummyChannel.Instance.CreateGrpcService<IDisposableService>(); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public async Task DisposeAsyncWorks() |
| 24 | + { |
| 25 | + await using var client = DummyChannel.Instance.CreateGrpcService<IDisposableService>(); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + internal sealed class DummyChannel : ChannelBase |
| 30 | + { |
| 31 | + public static DummyChannel Instance { get; } = new(); |
| 32 | + private DummyChannel() : base("") { } |
| 33 | + public override CallInvoker CreateCallInvoker() => DummyCallInvoker.Instance; |
| 34 | + |
| 35 | + private sealed class DummyCallInvoker : CallInvoker |
| 36 | + { |
| 37 | + public static DummyCallInvoker Instance { get; } = new(); |
| 38 | + private DummyCallInvoker() { } |
| 39 | + |
| 40 | + public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options) |
| 41 | + => throw new NotSupportedException(); |
| 42 | + |
| 43 | + public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options) |
| 44 | + => throw new NotSupportedException(); |
| 45 | + |
| 46 | + public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request) |
| 47 | + => throw new NotSupportedException(); |
| 48 | + |
| 49 | + public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request) |
| 50 | + => throw new NotSupportedException(); |
| 51 | + |
| 52 | + public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string? host, CallOptions options, TRequest request) |
| 53 | + => throw new NotSupportedException(); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments