public ProcessedMessage ConvertToSaveMessage(TransportMessage message) { var metadata = new Dictionary <string, object> { ["MessageId"] = message.Id, ["MessageIntent"] = message.MessageIntent, ["HeadersForSearching"] = string.Join(" ", message.Headers.Values) }; foreach (var enricher in enrichers) { enricher.Enrich(message.Headers, metadata); } bodyStorageEnricher.StoreAuditMessageBody( message.Body, message.Headers, metadata); var auditMessage = new ProcessedMessage(message.Headers, metadata) { // We do this so Raven does not spend time assigning a hilo key Id = $"ProcessedMessages/{Guid.NewGuid()}" }; return(auditMessage); }
public async Task Should_remove_body_when_above_threshold() { var fakeStorage = new FakeBodyStorage(); var maxBodySizeToStore = 20000; var settings = new Settings { MaxBodySizeToStore = maxBodySizeToStore }; var enricher = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings); var body = Encoding.UTF8.GetBytes(new string('a', maxBodySizeToStore + 1)); await enricher.StoreAuditMessageBody(body, new Dictionary <string, string>(), new Dictionary <string, object>()); Assert.AreEqual(0, fakeStorage.StoredBodySize, "Body should be removed if above threshold"); }
public async Task Should_store_body_in_storage_when_above_large_object_heap_but_below_threshold_and_not_binary() { var fakeStorage = new FakeBodyStorage(); var maxBodySizeToStore = 100000; var settings = new Settings { MaxBodySizeToStore = maxBodySizeToStore }; var enricher = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings); var expectedBodySize = BodyStorageFeature.BodyStorageEnricher.LargeObjectHeapThreshold + 1; var body = Encoding.UTF8.GetBytes(new string('a', expectedBodySize)); var metadata = new Dictionary <string, object>(); await enricher.StoreAuditMessageBody(body, new Dictionary <string, string>(), metadata); Assert.AreEqual(expectedBodySize, fakeStorage.StoredBodySize, "Body should be stored if below threshold"); Assert.IsFalse(metadata.ContainsKey("Body")); }
public async Task Should_remove_body_when_above_threshold_and_binary() { var fakeStorage = new FakeBodyStorage(); var maxBodySizeToStore = 20000; var settings = new Settings { MaxBodySizeToStore = maxBodySizeToStore }; var enricher = new BodyStorageFeature.BodyStorageEnricher(fakeStorage, settings); var body = Encoding.UTF8.GetBytes(new string('a', maxBodySizeToStore + 1)); var metadata = new Dictionary <string, object>(); var headers = new Dictionary <string, string> { { Headers.ContentType, "application/binary" } }; await enricher.StoreAuditMessageBody(body, headers, metadata); Assert.AreEqual(0, fakeStorage.StoredBodySize, "Body should be removed if above threshold"); Assert.IsFalse(metadata.ContainsKey("Body")); }