public async Task persist_an_incoming_envelope()
        {
            var envelope = new Envelope
            {
                Data          = new byte[] { 1, 2, 3, 4 },
                OwnerId       = 5,
                ExecutionTime = DateTime.Today.AddDays(1),
                DeliverBy     = new DateTimeOffset(DateTime.Today),
                Status        = EnvelopeStatus.Scheduled,
                Attempts      = 2
            };

            var context   = Host.Services.GetRequiredService <SampleDbContext>();
            var messaging = Host.Services.GetRequiredService <IMessageContext>();

            var transaction = new EFCoreEnvelopeTransaction(context, messaging);

            await transaction.ScheduleJob(envelope);

            await context.SaveChangesAsync();

            var persisted = await Host.Services.GetRequiredService <IEnvelopePersistence>()
                            .Admin.AllIncomingEnvelopes();

            var loadedEnvelope = persisted.Single();

            loadedEnvelope.Id.ShouldBe(envelope.Id);

            loadedEnvelope.Destination.ShouldBe(envelope.Destination);
            loadedEnvelope.ExecutionTime.ShouldBe(envelope.ExecutionTime);
            loadedEnvelope.Data.ShouldBe(envelope.Data);
            loadedEnvelope.OwnerId.ShouldBe(envelope.OwnerId);
            loadedEnvelope.Attempts.ShouldBe(envelope.Attempts);
        }
        public async Task persist_an_outgoing_envelope()
        {
            var envelope = new Envelope
            {
                Data        = new byte[] { 1, 2, 3, 4 },
                OwnerId     = 5,
                Destination = TransportConstants.RetryUri,
                DeliverBy   = new DateTimeOffset(DateTime.Today),
            };

            var context   = Host.Services.GetRequiredService <SampleDbContext>();
            var messaging = Host.Services.GetRequiredService <IMessageContext>();

            var transaction = new EFCoreEnvelopeTransaction(context, messaging);

            await transaction.Persist(envelope);

            await context.SaveChangesAsync();

            var persisted = await Host.Services.GetRequiredService <IEnvelopePersistence>()
                            .Admin.AllOutgoingEnvelopes();

            var loadedEnvelope = persisted.Single();

            loadedEnvelope.Id.ShouldBe(envelope.Id);

            loadedEnvelope.Destination.ShouldBe(envelope.Destination);
            loadedEnvelope.DeliverBy.ShouldBe(envelope.DeliverBy);
            loadedEnvelope.Data.ShouldBe(envelope.Data);



            loadedEnvelope.OwnerId.ShouldBe(envelope.OwnerId);
        }