Beispiel #1
0
        public async Task Dequeue_EmptyQueue_ReturnsEmpty()
        {
            using (var scope = new IsolationScope(TestFixtureContext.Provider))
            {
                var connection = scope.Provider.GetRequiredService <IDbConnection>();
                var queue      = new DefaultBulkQueue <string>(connection, bulkSize: 2);

                var items = await queue.DequeueAsync();

                Assert.IsEmpty(items);
            }
        }
Beispiel #2
0
        public async Task Dequeue_NotEmptyQueue_DequeueItemsInOrder()
        {
            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 items = await queue.DequeueAsync();

                Assert.AreEqual(2, items.Count());
            }
        }
Beispiel #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);
            }
        }