Ejemplo n.º 1
0
        public void ProcessAsync_ExceptionWhileProcessingItem_ThrowExceptionAndUpdatesItem()
        {
            var queue          = new SingleItemStatefulQueue(new StringItem("An item"));
            var handler        = new ThrowExceptionPayloadHandler(new Exception("An exception"));
            var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

            Assert.ThrowsAsync <Exception>(() => queueProcessor.ProcessAsync());
            Assert.IsTrue(queue.UpdateWasCalled);
        }
Ejemplo n.º 2
0
        public async Task ProcessAsync_NoExceptionWhileProcessingItem_UpdatesItem()
        {
            var queue          = new SingleItemStatefulQueue(new StringItem("An item"));
            var handler        = new FakePayloadHandler();
            var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

            await queueProcessor.ProcessAsync();

            Assert.IsTrue(queue.UpdateWasCalled);
        }
Ejemplo n.º 3
0
        public async Task ProcessAsync_AnItemInQueue_ReturnsTrue()
        {
            var queue          = new SingleItemStatefulQueue(new StringItem("An item"));
            var handler        = new FakePayloadHandler();
            var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

            var processed = await queueProcessor.ProcessAsync();

            Assert.IsTrue(processed);
        }
Ejemplo n.º 4
0
        public async Task ProcessAsync_EmptyQueue_ReturnsFalse()
        {
            var queue          = new EmptyStatefulQueue();
            var handler        = new FakePayloadHandler();
            var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

            var processed = await queueProcessor.ProcessAsync();

            Assert.IsFalse(processed);
        }
Ejemplo n.º 5
0
        public async Task ProcessAsync_SinglePendingItemInQueueAndExceptionWhileProcessingIt_UpdatesItem()
        {
            using (var scope = new IsolationScope(TestFixtureContext.Provider))
            {
                var connection = scope.Provider.GetRequiredService <IDbConnection>();
                await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "An item"));

                var queue          = new StatefulQueue <string>(connection);
                var handler        = new ThrowExceptionPayloadHandler(new Exception("Any exception"));
                var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

                Assert.ThrowsAsync <Exception>(() => queueProcessor.ProcessAsync());

                var item = await connection.SingleSqlAsync <StringItem>("SELECT TOP 1 * FROM Kiukie.Queue");

                Assert.IsNotNull(item);
                Assert.AreEqual((int)QueueItemStatus.Failed, item.StatusId);
            }
        }
Ejemplo n.º 6
0
        public async Task ProcessAsync_SinglePendingItemInQueue_ProcessesAndEmptiesQueue()
        {
            using (var scope = new IsolationScope(TestFixtureContext.Provider))
            {
                var connection = scope.Provider.GetRequiredService <IDbConnection>();
                await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(StatusId, Payload) VALUES(@StatusId, @Payload)", new StringItem(QueueItemStatus.Pending, "An item"));

                var queue          = new StatefulQueue <string>(connection);
                var handler        = new FakePayloadHandler();
                var queueProcessor = new StatefulQueueProcessor <string>(queue, handler);

                var processed = await queueProcessor.ProcessAsync();

                Assert.IsTrue(processed);

                processed = await queueProcessor.ProcessAsync();

                Assert.IsFalse(processed);
            }
        }