Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public async Task ProcessAsync_SinglePendingItemInQueue_ProcessesAndUpdatesItem()
        {
            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);

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

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

                await connection.ExecuteSqlAsync("INSERT INTO Kiukie.Queue(Payload) VALUES(@Payload)", new StringItem("Item2"));

                var queue          = new DefaultBulkQueue <string>(connection, bulkSize: 2);
                var handler        = new FakePayloadHandler();
                var queueProcessor = new DefaultBulkQueueProcessor <string>(queue, handler);

                var processed = await queueProcessor.ProcessAsync();

                Assert.IsTrue(processed);

                processed = await queueProcessor.ProcessAsync();

                Assert.IsFalse(processed);
            }
        }