public async Task ReadTest() { const string textData = "this is the payload!!"; var receivedTextData = new List <string>(); var receivedMetadata = new List <Dictionary <string, string> >(); var gotMessage = new ManualResetEvent(false); var handler = new DataBusAttachmentReadingHandler(receivedTextData, gotMessage, receivedMetadata); var dataStore = new InMemDataStore(); dataStore.Save("this is an attachment id", Encoding.UTF8.GetBytes(textData), new Dictionary <string, string> { { "custom-meta", "whee!!" } }); using (FakeDataBus.EstablishContext(dataStore)) { await handler.Handle("this is an attachment id"); } gotMessage.WaitOrDie(TimeSpan.FromSeconds(1)); Assert.That(receivedTextData.Count, Is.EqualTo(1)); Assert.That(receivedTextData.First(), Is.EqualTo(textData)); Assert.That(receivedMetadata.Count, Is.EqualTo(1)); Assert.That(receivedMetadata.First()["custom-meta"], Is.EqualTo("whee!!")); }
public void AttachmentIds_Data_ReturnsIDs() { _inMemDataStore.Save("test1", new byte[] { 1, 2, 3 }); _inMemDataStore.Save("test2", new byte[] { 4, 5, 6 }, new Dictionary <string, string> { { "x", "y" } }); Assert.That(_inMemDataStore.AttachmentIds, Is.EquivalentTo(new[] { "test1", "test2" })); }
public async Task Save(string id, Stream source, Dictionary <string, string> metadata = null) { using (var destination = new MemoryStream()) { await source.CopyToAsync(destination); var bytes = destination.ToArray(); var metadataToWrite = new Dictionary <string, string>(metadata ?? new Dictionary <string, string>()) { [MetadataKeys.SaveTime] = _rebusTime.Now.ToString("O"), [MetadataKeys.Length] = bytes.Length.ToString() }; _dataStore.Save(id, bytes, metadataToWrite); } }