Пример #1
0
            async Task <CloudQueue> IAsyncConverter <QueueAttribute, CloudQueue> .ConvertAsync(
                QueueAttribute attrResolved,
                CancellationToken cancellation)
            {
                IAsyncConverter <QueueAttribute, IStorageQueue> convert = this;
                var queue = await convert.ConvertAsync(attrResolved, cancellation);

                return(queue.SdkObject);
            }
Пример #2
0
            public async Task <ITriggerData> BindAsync(Message value, ValueBindingContext context)
            {
                Message clone     = value.Clone();
                object  converted = await _converter.ConvertAsync(value, context.CancellationToken);

                IValueProvider provider = await BrokeredMessageValueProvider.CreateAsync(clone, converted, typeof(T),
                                                                                         context.CancellationToken);

                return(new TriggerData(provider, null));
            }
        public async Task TestUnsubscribe()
        {
            var ext = new EventGridExtensionConfig();

            var host = TestHelpers.NewHost <MyProg1>(ext);

            await host.StartAsync(); // add listener

            var request = CreateUnsubscribeRequest("TestEventGrid");
            IAsyncConverter <HttpRequestMessage, HttpResponseMessage> handler = ext;
            var response = await handler.ConvertAsync(request, CancellationToken.None);

            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }
Пример #4
0
            public override Func <object, object> Work(object instance)
            {
                IAsyncConverter <TSrc, TDest> converter = (IAsyncConverter <TSrc, TDest>)instance;

                Func <object, object> func = (input) =>
                {
                    TSrc         src        = (TSrc)input;
                    Task <TDest> resultTask = Task.Run(() => converter.ConvertAsync(src, CancellationToken.None));

                    TDest result = resultTask.GetAwaiter().GetResult();
                    return(result);
                };

                return(func);
            }
Пример #5
0
            public override FuncAsyncConverter Execute(object instance)
            {
                IAsyncConverter <TSrc, TDest> converter = (IAsyncConverter <TSrc, TDest>)instance;

                FuncAsyncConverter func = async(input, attr, ctx) =>
                {
                    TSrc  src    = (TSrc)input;
                    var   cts    = ctx == null ? CancellationToken.None : ctx.CancellationToken;
                    TDest result = await converter.ConvertAsync(src, cts);

                    return(result);
                };

                return(func);
            }
Пример #6
0
        public async Task <ConversionResult <IStorageBlob> > TryConvertAsync(object input,
                                                                             CancellationToken cancellationToken)
        {
            TInput typedInput = input as TInput;

            if (typedInput == null)
            {
                return(new ConversionResult <IStorageBlob>
                {
                    Succeeded = false,
                    Result = null
                });
            }

            IStorageBlob blob = await _innerConverter.ConvertAsync(typedInput, cancellationToken);

            return(new ConversionResult <IStorageBlob>
            {
                Succeeded = true,
                Result = blob
            });
        }
        public async Task <ConversionResult <ServiceBusEntity> > TryConvertAsync(object input,
                                                                                 CancellationToken cancellationToken)
        {
            TInput typedInput = input as TInput;

            if (typedInput == null)
            {
                return(new ConversionResult <ServiceBusEntity>
                {
                    Succeeded = false,
                    Result = null
                });
            }

            ServiceBusEntity entity = await _innerConverter.ConvertAsync(typedInput, cancellationToken).ConfigureAwait(false);

            return(new ConversionResult <ServiceBusEntity>
            {
                Succeeded = true,
                Result = entity
            });
        }
Пример #8
0
        public async Task <ConversionResult <BlobBaseClient> > TryConvertAsync(object input,
                                                                               CancellationToken cancellationToken)
        {
            TInput typedInput = input as TInput;

            if (typedInput == null)
            {
                return(new ConversionResult <BlobBaseClient>
                {
                    Succeeded = false,
                    Result = null
                });
            }

            var blob = await _innerConverter.ConvertAsync(typedInput, cancellationToken).ConfigureAwait(false);

            return(new ConversionResult <BlobBaseClient>
            {
                Succeeded = true,
                Result = blob
            });
        }
        public async Task TestDispatch()
        {
            var ext = new EventGridExtensionConfig();

            var host = TestHelpers.NewHost <MyProg1>(ext);

            await host.StartAsync(); // add listener

            var request = CreateDispatchRequest("TestEventGrid",
                                                JObject.Parse(@"{'subject':'one','data':{'prop':'alpha'}}"),
                                                JObject.Parse(@"{'subject':'two','data':{'prop':'beta'}}"));

            IAsyncConverter <HttpRequestMessage, HttpResponseMessage> handler = ext;
            var response = await handler.ConvertAsync(request, CancellationToken.None);

            // Verify that the user function was dispatched twice, in order.
            // Also verifies each instance gets its own proper binding data (from FakePayload.Prop)
            Assert.Equal("[Dispatch:one, alpha][Dispatch:two, beta]", _log.ToString());

            // TODO - Verify that we return from webhook before the dispatch is finished
            // https://github.com/Azure/azure-functions-eventgrid-extension/issues/10
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }