Пример #1
0
        public void ResultCallAsyncResponseHeaders()
        {
            var expectedMessage  = new Message <int>(10);
            var expectedHeaders  = new Metadata();
            var expectedStatus   = new Status(StatusCode.Internal, "some details");
            var expectedTrailers = new Metadata();
            var disposeCounter   = 0;

            var context = new CallContext(headers: null);

            var call = new AsyncUnaryCall <Message <int> >(
                GetAsync(expectedMessage),
                GetAsync(expectedHeaders),
                () => expectedStatus,
                () => expectedTrailers,
                () => disposeCounter++);

            using (new SynchronizationContextMock())
            {
                var result = UnaryCall <Message <int>, Message <int> > .CallAsync(call, context, CancellationToken.None).Result;

                result.ShouldBe(10);
            }

            context.ResponseHeaders.ShouldBe(expectedHeaders);
            context.ResponseTrailers.ShouldBe(expectedTrailers);
            context.ResponseStatus.ShouldBe(expectedStatus);
            disposeCounter.ShouldBe(1);
        }
Пример #2
0
        public void VoidCallAsyncResponse()
        {
            var disposeCounter = 0;

            var call = new AsyncUnaryCall <Message>(
                GetAsync(new Message()),
                GetNotSupportedAsync <Metadata>(),
                () => throw new NotSupportedException(),
                () => throw new NotSupportedException(),
                () => disposeCounter++);

            using (new SynchronizationContextMock())
            {
                UnaryCall <Message, Message> .CallAsync(call, null, CancellationToken.None).Wait();
            }

            disposeCounter.ShouldBe(1);
        }
Пример #3
0
        public void ResultCallAsyncResponse()
        {
            var expectedMessage = new Message <int>(10);
            var disposeCounter  = 0;

            var call = new AsyncUnaryCall <Message <int> >(
                GetAsync(expectedMessage),
                GetNotSupportedAsync <Metadata>(),
                () => throw new NotSupportedException(),
                () => throw new NotSupportedException(),
                () => disposeCounter++);

            using (new SynchronizationContextMock())
            {
                var result = UnaryCall <Message <int>, Message <int> > .CallAsync(call, null, CancellationToken.None).Result;

                result.ShouldBe(10);
            }

            disposeCounter.ShouldBe(1);
        }