public void GivenUnenrichedMessage_WhenAskingForEnrichedInstance_ThenItShouldReturnNewObjectWithEnrichment() { // arrange const string json = "{\"Dammit\":\"Bobby!\"}"; ServiceBusMessage serviceBusMessage = new ServiceBusMessage(json); dynamic enrichment = new ExpandoObject(); // act ServiceBusMessage actual = serviceBusMessage.EnrichedInstance(enrichment); // assert actual.Should().NotBe(serviceBusMessage); actual.IsEnriched().Should().BeTrue(); }
public void GivenEnrichedMessage_WhenAskingForEnrichedInstance_ThenItShouldReturnNewObjectWithOriginalAndNewEnrichment() { // arrange const string json = "{\"Dammit\":\"Bobby!\",\"Results\":[{\"Mother\":\"Will not be happy.\"}]}"; const string expected = "{\"Dammit\":\"Bobby!\",\"Results\":[{\"Mother\":\"Will not be happy.\"},{\"Hello\":\", World.\"}]}"; ServiceBusMessage serviceBusMessage = new ServiceBusMessage(json); Enrichment enrichment = new Enrichment(); // act ServiceBusMessage actual = serviceBusMessage.EnrichedInstance(enrichment); // assert actual.Should().NotBe(serviceBusMessage); actual.IsEnriched().Should().BeTrue(); ((string)actual).Should().Be(expected); }
public static async Task Run( [ServiceBusTrigger("customerservice", "brickandmortar", Connection = "ServiceBusConnectionString")] string message, [EventHub("rapids", Connection = "EventHubConnectionString")] IAsyncCollector <EventData> collector) { try { ServiceBusMessage serviceBusMessage = new ServiceBusMessage(message); if (serviceBusMessage.IsEnriched()) { return; } await collector.AddAsync(serviceBusMessage.EnrichedInstance(new BrickAndMortarState()).AsEventData()); } catch (Exception e) { Console.WriteLine($"{e.Message}\n\n{e.StackTrace}"); } }