public async Task Should_clear_dispatched_messages_and_cleanup_queue_after_given_expiry()
        {
            configuration.RequiresOutboxSupport();

            var storage = (OutboxStorage)configuration.OutboxStorage;
            var ctx     = configuration.GetContextBagForOutbox();

            var messageId = Guid.NewGuid().ToString();

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(ctx))
            {
                await storage.Store(messageToStore, transaction, ctx);

                await transaction.Commit();
            }

            // Account for the low resolution of DateTime.UtcNow.
            var afterStore = DateTimeOffset.UtcNow.AddTicks(1);

            await storage.SetAsDispatched(messageId, configuration.GetContextBagForOutbox());

            await configuration.CleanupMessagesOlderThan(afterStore);

            var message = await storage.Get(messageId, configuration.GetContextBagForOutbox());

            using (var tx = stateManager.CreateTransaction())
            {
                Assert.AreEqual(0, await storage.Cleanup.GetCountAsync(tx));
                Assert.AreEqual(0, await storage.Outbox.GetCountAsync(tx));
            }

            Assert.Null(message);
        }
Пример #2
0
        public async Task Should_not_remove_non_dispatched_messages()
        {
            configuration.RequiresOutboxSupport();

            var storage = configuration.OutboxStorage;
            var ctx     = configuration.GetContextBagForOutbox();

            var messageId = Guid.NewGuid().ToString();

            var messageToStore = new OutboxMessage(messageId, new[] { new TransportOperation("x", null, null, null) });

            using (var transaction = await storage.BeginTransaction(ctx))
            {
                await storage.Store(messageToStore, transaction, ctx);

                await transaction.Commit();
            }

            await configuration.CleanupMessagesOlderThan(DateTimeOffset.UtcNow);

            var message = await storage.Get(messageId, configuration.GetContextBagForOutbox());

            Assert.NotNull(message);
        }