Exemplo n.º 1
0
        public async Task MetadataHandlers(bool responseHandler, bool trailingHandler, bool sync)
        {
            var      call = CreateMetadataTestingApiCall();
            Metadata actualResponseMetadata   = null;
            Metadata actualTrailingMetadata   = null;
            Metadata expectedResponseMetadata = responseHandler ? CreateMetadata("kind", "response") : null;
            Metadata expectedTrailingMetadata = trailingHandler ? CreateMetadata("kind", "trailing") : null;

            CallSettings settings = null;

            if (responseHandler)
            {
                settings = settings.WithResponseMetadataHandler(metadata => actualResponseMetadata = metadata);
            }
            if (trailingHandler)
            {
                settings = settings.WithTrailingMetadataHandler(metadata => actualTrailingMetadata = metadata);
            }
            var request  = new SimpleRequest();
            var response = sync ? call.Sync(request, settings) : await call.Async(request, settings);

            Assert.Equal("response", response.Name);

            AssertMetadata(expectedResponseMetadata, actualResponseMetadata);
            AssertMetadata(expectedTrailingMetadata, actualTrailingMetadata);
        }