Exemplo n.º 1
0
        public async Task TestUnsubscribe()
        {
            var ext  = new EventGridExtensionConfig();
            var host = TestHelpers.NewHost <MyProg1>(ext);
            await host.StartAsync(); // add listener

            var request  = CreateUnsubscribeRequest("TestEventGrid");
            var response = await ext.ConvertAsync(request, CancellationToken.None);

            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }
        public static JobHost NewHost <T>(EventGridExtensionConfig ext = null)
        {
            JobHostConfiguration config = new JobHostConfiguration();

            config.HostId = Guid.NewGuid().ToString("n");
            config.StorageConnectionString   = null;
            config.DashboardConnectionString = null;
            config.TypeLocator = new FakeTypeLocator <T>();
            config.AddExtension(ext ?? new EventGridExtensionConfig());
            config.AddExtension(new TestExtensionConfig());
            var host = new JobHost(config);

            return(host);
        }
Exemplo n.º 3
0
        public async Task ExecutionFailureTest()
        {
            var ext  = new EventGridExtensionConfig();
            var host = TestHelpers.NewHost <MyProg2>(ext);
            await host.StartAsync(); // add listener

            JObject dummyPayload = JObject.Parse("{}");
            var     request      = CreateDispatchRequest("EventGridThrowsException", dummyPayload);
            var     response     = await ext.ConvertAsync(request, CancellationToken.None);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal("Exception while executing function: EventGridThrowsException", responseContent);
            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Exemplo n.º 4
0
        public async Task WrongFunctionNameTest()
        {
            var ext  = new EventGridExtensionConfig();
            var host = TestHelpers.NewHost <MyProg2>(ext);
            await host.StartAsync(); // add listener

            JObject dummyPayload = JObject.Parse("{}");
            var     request      = CreateDispatchRequest("RandomFunctionName", dummyPayload);
            var     response     = await ext.ConvertAsync(request, CancellationToken.None);

            string responseContent = await response.Content.ReadAsStringAsync();

            Assert.Equal("cannot find function: 'RandomFunctionName'", responseContent);
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Exemplo n.º 5
0
        public async Task TestCloudEvent()
        {
            // individual elements
            var ext  = new EventGridExtensionConfig();
            var host = TestHelpers.NewHost <MyProg1>(ext);
            await host.StartAsync(); // add listener

            var request = CreateSingleRequest("TestEventGrid",
                                              JObject.Parse(@"{'subject':'one','data':{'prop':'alpha'}}"));
            var response = await ext.ConvertAsync(request, CancellationToken.None);

            // verifies each instance gets its own proper binding data (from FakePayload.Prop)
            _log.TryGetValue("one", out string alpha);
            Assert.Equal("alpha", alpha);
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }
Exemplo n.º 6
0
        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'}}"));
            var response = await ext.ConvertAsync(request, CancellationToken.None);

            // Verify that the user function was dispatched twice, NOT necessarily in order
            // Also verifies each instance gets its own proper binding data (from FakePayload.Prop)
            _log.TryGetValue("one", out string alpha);
            _log.TryGetValue("two", out string beta);
            Assert.Equal("alpha", alpha);
            Assert.Equal("beta", beta);
            // 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);
        }
        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);
        }