public void MovesToDeadLetterQueue() { var redis = A.Fake <IRedisClient>(); var subscriber = new MessageQueue.RedisEventSubscriber(redis, "TestPrefix", "Test"); var eventData = new TestEvent(); var serializedEvent = JsonConvert.SerializeObject(eventData); TestEvent callbackData = null; A.CallTo(() => redis.ListRightPopLeftPush("TestPrefix:{Test:TestEvent}:PublishedEvents", "TestPrefix:{Test:TestEvent}:ProcessingEvents")).Returns(serializedEvent); A.CallTo(() => redis.SubscribeAsync("Test:TestEvent", A <Action <RedisChannel, RedisValue> > ._)) .Invokes(callObject => { var action = callObject.Arguments[1] as Action <RedisChannel, RedisValue>; action(callObject.Arguments[0].ToString(), serializedEvent); }); Action <TestEvent> cb = (data) => { callbackData = data; throw new Exception("Oh No!"); }; try { subscriber.SubscribeAsync(cb).Wait(); Assert.Fail("Should have thrown exception"); } catch (Exception e) { Assert.AreEqual("Oh No!", e.InnerException.InnerException.Message); A.CallTo(() => redis.ListRightPopLeftPush("TestPrefix:{Test:TestEvent}:PublishedEvents", "TestPrefix:{Test:TestEvent}:ProcessingEvents")).MustHaveHappened(); A.CallTo(() => redis.ListLeftPush("TestPrefix:{Test:TestEvent}:DeadLetters", serializedEvent)).MustHaveHappened(); A.CallTo(() => redis.ListRemove("TestPrefix:{Test:TestEvent}:ProcessingEvents", serializedEvent)).MustHaveHappened(); } }
public SubscribeTest() { _redis = A.Fake <IRedisClient>(); var subscriber = new MessageQueue.RedisEventSubscriber(_redis, "TestPrefix", "Test"); var testEvent = new TestEvent(); _serializedEvent = JsonConvert.SerializeObject(testEvent); A.CallTo(() => _redis.ListLengthAsync("TestPrefix:{Test:TestEvent}:PublishedEvents")).Returns(2); A.CallTo(() => _redis.ListRangeAsync("TestPrefix:{Test:TestEvent}:PublishedEvents", 0, 2)).Returns(new RedisValue[] { "Test1", "Test2" }); A.CallTo(() => _redis.ListRightPopLeftPush("TestPrefix:{Test:TestEvent}:PublishedEvents", "TestPrefix:{Test:TestEvent}:ProcessingEvents")).Returns(_serializedEvent); A.CallTo(() => _redis.SubscribeAsync("Test:TestEvent", A <Action <RedisChannel, RedisValue> > ._)) .Invokes(callObject => { var action = callObject.Arguments[1] as Action <RedisChannel, RedisValue>; action(callObject.Arguments[0].ToString(), _serializedEvent); }); Action <TestEvent> cb = (data) => { _callbackData = data; _callBackExecutedCount++; }; subscriber.SubscribeAsync(cb).Wait(); }
public void DoesNotThrowAndDoesNotCallCallBackIfEventIsAlreadyProcessed() { var redis = A.Fake <IRedisClient>(); var subscriber = new MessageQueue.RedisEventSubscriber(redis, "TestPrefix", "Test"); TestEvent callbackData = null; A.CallTo(() => redis.ListRightPopLeftPush("TestPrefix:{Test:TestEvent}:PublishedEvents", "TestPrefix:{Test:TestEvent}:ProcessingEvents")).Returns(RedisValue.Null); A.CallTo(() => redis.SubscribeAsync("Test:TestEvent", A <Action <RedisChannel, RedisValue> > ._)) .Invokes(callObject => { var action = callObject.Arguments[1] as Action <RedisChannel, RedisValue>; action(callObject.Arguments[0].ToString(), RedisValue.Null); }); Action <TestEvent> cb = (data) => { callbackData = null; }; subscriber.SubscribeAsync(cb).Wait(); A.CallTo(() => redis.ListRightPopLeftPush("TestPrefix:{Test:TestEvent}:PublishedEvents", "TestPrefix:{Test:TestEvent}:ProcessingEvents")).MustHaveHappened(); Assert.IsNull(callbackData); }