Пример #1
0
        public async Task Run([EventHubTrigger("rapids", Connection = "EventHubConnectionString")] EventData[] events)
        {
            List <Exception> exceptions = new List <Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    EventMessageBody messageBody = new EventMessageBody(eventData);
                    if (messageBody.IsEventType(EventType.None))
                    {
                        continue;
                    }

                    await messageBody.AsServiceBusMessage().SendAsync();
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                }
            }

            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }
Пример #2
0
        public void GivenValidBodyWithUnknownTopic_WhenUsingAskingIsNoneEventType_ThenItShouldReturnTrue()
        {
            // arrange
            const string expected = "{'eventType':'propane','need':'accessory'}";

            Environment.SetEnvironmentVariable("ServiceBusConnectionString", "Endpoint=sb://googazon-rivers.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=dammitbobby");
            EventMessageBody eventMessageBody = new EventMessageBody(new EventData(Encoding.UTF8.GetBytes(expected)));

            // act
            bool actual = eventMessageBody.IsEventType(EventType.None);

            // assert
            actual.Should().BeTrue();
        }