Example #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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }