예제 #1
0
        public async Task bindAsyncTest()
        {
            MethodBase methodbase = this.GetType().GetMethod("DummyMethod", BindingFlags.NonPublic | BindingFlags.Instance);

            ParameterInfo[] arrayParam = methodbase.GetParameters();

            ITriggerBinding binding = new EventGridTriggerBinding(arrayParam[0], null);
            JObject         eve     = JObject.Parse(FakeData.singleEvent);
            JObject         data    = (JObject)eve["data"];

            // JObject as input
            ITriggerData triggerDataWithEvent = await binding.BindAsync(eve, null);

            Assert.Equal(data, triggerDataWithEvent.BindingData["data"]);

            // string as input
            ITriggerData triggerDataWithString = await binding.BindAsync(FakeData.singleEvent, null);

            Assert.Equal(data, triggerDataWithString.BindingData["data"]);

            // test invalid, batch of events
            FormatException formatException = await Assert.ThrowsAsync <FormatException>(() => binding.BindAsync(FakeData.arrayOfOneEvent, null));

            Assert.Equal($"Unable to parse {FakeData.arrayOfOneEvent} to {typeof(JObject)}", formatException.Message);

            // test invalid, random object
            var testObject = new TestClass();
            InvalidOperationException invalidException = await Assert.ThrowsAsync <InvalidOperationException>(() => binding.BindAsync(testObject, null));

            Assert.Equal($"Unable to bind {testObject} to type {arrayParam[0].ParameterType}", invalidException.Message);
        }
예제 #2
0
        public async Task BindAsyncTest()
        {
            MethodBase methodbase = this.GetType().GetMethod("DummyMethod", BindingFlags.NonPublic | BindingFlags.Instance);

            ParameterInfo[] arrayParam = methodbase.GetParameters();

            ITriggerBinding binding = new EventGridTriggerBinding(arrayParam[0], null, singleDispatch: true);
            JObject         eve     = JObject.Parse(FakeData.EventGridEvent);
            JObject         data    = (JObject)eve["data"];

            // Data for batch binding
            ITriggerBinding      bindingBatch = new EventGridTriggerBinding(arrayParam[0], null, singleDispatch: false);
            JArray               events       = JArray.Parse(FakeData.MultipleEventGridEvents);
            IEnumerable <JToken> dataEvents   = events.Select(ev => ev["data"]);

            // JObject as input
            ITriggerData triggerDataWithEvent = await binding.BindAsync(eve, null);

            Assert.AreEqual(data, triggerDataWithEvent.BindingData["data"]);

            // JArray as input
            ITriggerData triggerDataWithEvents = await bindingBatch.BindAsync(events, null);

            Assert.AreEqual(dataEvents, triggerDataWithEvents.BindingData["data"]);

            // string as input
            ITriggerData triggerDataWithString = await binding.BindAsync(FakeData.EventGridEvent, null);

            Assert.AreEqual(data, triggerDataWithString.BindingData["data"]);

            // test invalid, batch of events
            FormatException formatException = Assert.Throws <FormatException>(() => binding.BindAsync(FakeData.EventGridEvents, null));

            Assert.AreEqual($"Unable to parse {FakeData.EventGridEvents} to {typeof(JObject)}", formatException.Message);

            // test invalid, random object
            var testObject = new TestClass();
            InvalidOperationException invalidException = Assert.Throws <InvalidOperationException>(() => binding.BindAsync(testObject, null));

            Assert.AreEqual($"Unable to bind {testObject} to type {arrayParam[0].ParameterType}", invalidException.Message);
        }