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!!")); }
internal FakeAdvancedApi(FakeBusEventRecorder recorder, FakeBusEventFactory factory, IRebusTime rebusTime) { _dataBus = new FakeDataBus(rebusTime); Workers = new FakeWorkersApi(recorder, rebusTime); Topics = new FakeTopicsApi(recorder, factory, rebusTime); SyncBus = new FakeSyncBus(recorder, factory, rebusTime); Routing = new FakeRoutingApi(recorder, factory, rebusTime); TransportMessage = new FakeTransportMessageApi(recorder, rebusTime); }
public async Task Outgoing_databus_properties_should_be_dehydrated() { var context = new TestableOutgoingLogicalMessageContext(); context.Message = new OutgoingLogicalMessage(typeof(MessageWithDataBusProperty), new MessageWithDataBusProperty { DataBusProperty = new DataBusProperty<string>("test") }); var fakeDatabus = new FakeDataBus(); var sendBehavior = new DataBusSendBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions()); await sendBehavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.AreEqual(TimeSpan.MaxValue, fakeDatabus.TTBRUsed); }
public async Task Outgoing_databus_properties_should_be_dehydrated() { var context = new TestableOutgoingLogicalMessageContext(); context.Message = new OutgoingLogicalMessage(typeof(MessageWithDataBusProperty), new MessageWithDataBusProperty { DataBusProperty = new DataBusProperty <string>("test") }); var fakeDatabus = new FakeDataBus(); var sendBehavior = new DataBusSendBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions()); await sendBehavior.Invoke(context, ctx => Task.CompletedTask); Assert.AreEqual(TimeSpan.MaxValue, fakeDatabus.TTBRUsed); }
public async Task Time_to_live_should_be_passed_on_the_databus() { var context = new TestableOutgoingLogicalMessageContext(); context.Message = new OutgoingLogicalMessage(typeof(MessageWithExplicitTimeToLive), new MessageWithExplicitTimeToLive { DataBusProperty = new DataBusProperty<string>("test") }); context.Extensions.AddDeliveryConstraint(new DiscardIfNotReceivedBefore(TimeSpan.FromMinutes(1))); var fakeDatabus = new FakeDataBus(); var sendBehavior = new DataBusSendBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions()); await sendBehavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.AreEqual(TimeSpan.FromMinutes(1), fakeDatabus.TTBRUsed); }
public async Task Time_to_live_should_be_passed_on_the_databus() { var context = new TestableOutgoingLogicalMessageContext(); context.Message = new OutgoingLogicalMessage(typeof(MessageWithExplicitTimeToLive), new MessageWithExplicitTimeToLive { DataBusProperty = new DataBusProperty <string>("test") }); context.Extensions.AddDeliveryConstraint(new DiscardIfNotReceivedBefore(TimeSpan.FromMinutes(1))); var fakeDatabus = new FakeDataBus(); var sendBehavior = new DataBusSendBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions()); await sendBehavior.Invoke(context, ctx => Task.CompletedTask); Assert.AreEqual(TimeSpan.FromMinutes(1), fakeDatabus.TTBRUsed); }
public async Task Incoming_databus_properties_should_be_hydrated() { var propertyKey = Guid.NewGuid().ToString(); var databusKey = Guid.NewGuid().ToString(); var message = new LogicalMessage(new MessageMetadata(typeof(MessageWithDataBusProperty)), new MessageWithDataBusProperty { DataBusProperty = new DataBusProperty <string>("not used in this test") { Key = propertyKey } }); var fakeDatabus = new FakeDataBus(); var receiveBehavior = new DataBusReceiveBehavior(fakeDatabus, new XmlDataBusSerializer <string>(), new Conventions()); using (var stream = new MemoryStream()) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(string)); serializer.Serialize(stream, "test"); stream.Position = 0; fakeDatabus.StreamsToReturn[databusKey] = stream; await receiveBehavior.Invoke( new IncomingLogicalMessageContext( message, "messageId", "replyToAddress", new Dictionary <string, string> { { "NServiceBus.DataBus." + propertyKey, databusKey } }, null), ctx => Task.CompletedTask); } var instance = (MessageWithDataBusProperty)message.Instance; Assert.AreEqual(instance.DataBusProperty.Value, "test"); }
public async Task Incoming_databus_properties_should_be_hydrated() { var propertyKey = Guid.NewGuid().ToString(); var databusKey = Guid.NewGuid().ToString(); var message = new LogicalMessage(new MessageMetadata(typeof(MessageWithDataBusProperty)), new MessageWithDataBusProperty { DataBusProperty = new DataBusProperty<string>("not used in this test") { Key = propertyKey } }); var fakeDatabus = new FakeDataBus(); var receiveBehavior = new DataBusReceiveBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions()); using (var stream = new MemoryStream()) { new BinaryFormatter().Serialize(stream, "test"); stream.Position = 0; fakeDatabus.StreamsToReturn[databusKey] = stream; await receiveBehavior.Invoke( new IncomingLogicalMessageContext( message, "messageId", "replyToAddress", new Dictionary<string, string> { {"NServiceBus.DataBus." + propertyKey, databusKey} }, null), ctx => TaskEx.CompletedTask); } var instance = (MessageWithDataBusProperty)message.Instance; Assert.AreEqual(instance.DataBusProperty.Value, "test"); }