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(); } }
public void GivenInvalidBody_WhenUsingAskingForServiceBusMessage_ThenItShouldShouldReturnNullServiceBusMessage() { // arrange const string expected = "{'businessName':'Strickland Propane, LLC'}"; 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 ServiceBusMessage actual = eventMessageBody.AsServiceBusMessage(); // assert actual.Should().BeOfType <NullServiceBusMessage>(); }