コード例 #1
0
        public void Can_return_message_after_queue_has_been_disposed()
        {
            // Arrange
            var queuePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var item1 = new DispatchItem(new XUri("http://a"), new DispatcherEvent(new XDoc("msg"), new XUri("http://channl"), new XUri("http://resource")), "a");

            var dispatchResult = new Result<bool>();
            var dispatchQueue = new PersistentPubSubDispatchQueue(queuePath, TaskTimerFactory.Current, 1.Minutes(), i => dispatchResult);
            dispatchQueue.Enqueue(item1);

            // Act
            dispatchQueue.Dispose();
            dispatchResult.Return(true);

            // Assert

            // should not have thrown on the return, that is all
        }
コード例 #2
0
        public void Disposed_queue_throws_on_access()
        {
            // Arrange
            var queuePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var dispatchQueue = new PersistentPubSubDispatchQueue(queuePath, TaskTimerFactory.Current, 1.Minutes(), i => new Result<bool>().WithReturn(true));

            // Act
            dispatchQueue.Dispose();

            // Assert
            try {
                var item = new DispatchItem(new XUri("http://a"), new DispatcherEvent(new XDoc("msg"), new XUri("http://channl"), new XUri("http://resource")), "a");
                dispatchQueue.Enqueue(item);
                Assert.Fail("Enqueue didn't throw");
            } catch(ObjectDisposedException) {
            } catch(Exception e) {
                Assert.Fail(string.Format("Enqueue threw unexpected exception: {0}", e));
            }
        }
コード例 #3
0
        public void Dispose_is_idempotent()
        {
            // Arrange
            var queuePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var dispatchQueue = new PersistentPubSubDispatchQueue(queuePath, TaskTimerFactory.Current, 1.Minutes(), i => new Result<bool>().WithReturn(true));

            // Act
            dispatchQueue.Dispose();

            // Assert
            dispatchQueue.Dispose();
        }
コード例 #4
0
        public void Creating_a_queue_with_persisted_items_starts_dispatch_immediately()
        {
            // Arrange
            var queuePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var item1 = new DispatchItem(new XUri("http://a"), new DispatcherEvent(new XDoc("msg"), new XUri("http://channl"), new XUri("http://resource")), "a");

            var dispatchQueue = new PersistentPubSubDispatchQueue(queuePath, TaskTimerFactory.Current, 1.Seconds(), (item) => new Result<bool>().WithReturn(false));
            dispatchQueue.Enqueue(item1);
            dispatchQueue.Dispose();

            var dispatched = new List<DispatchItem>();
            Func<DispatchItem, Result<bool>> handler = (i) => {
                dispatched.Add(i);
                var result = new Result<bool>();
                result.Return(true);
                return result;
            };

            // Act
            dispatchQueue = new PersistentPubSubDispatchQueue(queuePath, TaskTimerFactory.Current, 1.Seconds(), handler);

            // Assert
            Assert.IsTrue(Wait.For(() => dispatched.Count == 1, 5.Seconds()), "item was not dispatched in time");
            Assert.AreEqual(item1.Location, dispatched[0].Location, "wrong item location for dispatched item");
        }