public async Task It_retries_announcing_advance_when_initializing()
    {
        using (var conn = CreateConnection())
        {
            await conn.OpenAsync().ConfigureAwait(false);

            var dispatchedMessages = new List <OutgoingMessage>();
            Task Dispatch(OutgoingMessage operation)
            {
                dispatchedMessages.Add(operation);
                return(Task.CompletedTask);
            }

            await persister.Initialize(Dispatch, conn);

            var announceFailed = false;
            try
            {
                await persister.TryAdvance(op =>
                {
                    if (op.Headers.ContainsKey(RouterDeduplicationHeaders.Advance))
                    {
                        throw new Exception("Simulated");
                    }
                    return(Dispatch(op));
                }, conn);
            }
            catch (Exception)
            {
                announceFailed = true;
            }

            Assert.IsTrue(announceFailed);

            var newPersister = new OutboxPersister(3, "S", "D");
            await newPersister.Initialize(Dispatch, conn);

            var advanceMessage = dispatchedMessages.Single(m => m.Headers.ContainsKey(RouterDeduplicationHeaders.Advance));

            Assert.AreEqual("2", advanceMessage.Headers[RouterDeduplicationHeaders.AdvanceEpoch]);
            Assert.AreEqual("6", advanceMessage.Headers[RouterDeduplicationHeaders.AdvanceHeadLo]);
            Assert.AreEqual("9", advanceMessage.Headers[RouterDeduplicationHeaders.AdvanceHeadHi]);
        }
    }
    public async Task Can_advance_without_sending()
    {
        using (var conn = CreateConnection())
        {
            await conn.OpenAsync().ConfigureAwait(false);

            Task Dispatch(OutgoingMessage operation)
            {
                Console.WriteLine(operation.MessageId);
                return(Task.CompletedTask);
            }

            await persister.Initialize(Dispatch, conn);

            await persister.TryAdvance(Dispatch, conn);

            await persister.TryAdvance(Dispatch, conn);

            var linkState = await persister.TryAdvance(Dispatch, conn);

            Assert.AreEqual(4, linkState.Epoch);
        }
    }