public void CustomMailbox_ReceiveOne_andNack() { var received = false; var s = new TestScheduler(); var channel = new Mock <IModel>(); channel.Setup(x => x.BasicNack(It.IsAny <ulong>(), It.IsAny <bool>(), It.IsAny <bool>())); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new MailboxContext { Channel = channel.Object, EventArgs = NewArgs() }); var mb = new FakeSimpleMailbox(src); var typed = new FakeMailbox <string>(mb, str => str); typed.Subscribe(m => { received = true; m.Reject(); }); s.AdvanceBy(1); Assert.True(received); }
public void CustomMailbox_ReceiveMany_AcksThemAll() { var received = 0; var s = new TestScheduler(); var channel = new Mock <IModel>(); channel.Setup(x => x.BasicAck(It.IsAny <ulong>(), It.IsAny <bool>())); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new MailboxContext { Channel = channel.Object, EventArgs = NewArgs() }); var mb = new FakeSimpleMailbox(src); var custom = new FakeMailbox <string>(mb, str => str); custom.Subscribe(m => { received++; m.Confirm(); }); s.AdvanceBy(20); Assert.True(received == 20); }
public void CustomMailbox_ReceiveOne_UnableToDeserialize() { int? received = null; Exception ex = null; var s = new TestScheduler(); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new MailboxContext { Channel = null, EventArgs = NewArgs(WrongPayload) }); var c = new FakeMailbox <TestMessage>(new FakeSimpleMailbox(src, autoAck: true), JsonConvert.DeserializeObject <TestMessage>); c.Subscribe(m => { if (m.IsOk <TestMessage>()) { received = m.AsOk <TestMessage>().Message.Code; } else { ex = m.AsError().Ex; } }); s.AdvanceBy(1); Assert.True(received == null); Assert.True(ex != null); }
public void CustomMailbox_ReceiveOne() { var received = false; var s = new TestScheduler(); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new DeliveryContext(NewArgs(), null)); var c = new FakeMailbox <string>(new FakeSimpleMailbox(src, autoAck: true), str => str); c.Subscribe(m => received = true); s.AdvanceBy(1); Assert.True(received); }
public void CustomMailbox_SubscribeOnError_Acks(bool acks) { var received = false; var exception = false; var s = new TestScheduler(); var channel = new Mock <IModel>(); channel.Setup(x => x.BasicNack(It.IsAny <ulong>(), It.IsAny <bool>(), It.IsAny <bool>())); channel.Setup(x => x.BasicAck(It.IsAny <ulong>(), It.IsAny <bool>())); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new MailboxContext { Channel = channel.Object, EventArgs = NewArgs(WrongPayload) }); var mb = new FakeSimpleMailbox(src); var typed = new FakeMailbox <TestMessage>(mb, JsonConvert.DeserializeObject <TestMessage>); typed.Subscribe(m => { if (m.IsOk <TestMessage>()) { received = true; m.Confirm(); } else { exception = true; if (acks) { m.Confirm(); } else { m.Reject(); } } }); s.AdvanceBy(1); Assert.False(received); Assert.True(exception); }
public void CustomMailbox_ReceiveOne_andAck() { var received = false; var s = new TestScheduler(); var channel = new Mock <IModel>(); channel.Setup(x => x.BasicAck(It.IsAny <ulong>(), It.IsAny <bool>())); var src = Observable .Interval(TimeSpan.FromTicks(1), s) .Select(z => new DeliveryContext(NewArgs(), channel.Object)); var mb = new FakeSimpleMailbox(src); var custom = new FakeMailbox <string>(mb, str => str); custom.Subscribe(m => { received = true; m.Confirm(); }); s.AdvanceBy(1); Assert.True(received); }