Exemplo n.º 1
0
        public async Task delete_multiple_incoming_envelope()
        {
            var list = new List <Envelope>();

            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());

            var toDelete = new[] { list[2], list[3], list[7] };

            await ThePersistence.DeleteIncomingEnvelopes(toDelete);

            var stored = ThePersistence.AllIncomingEnvelopes();

            stored.Length.ShouldBe(7);

            stored.Any(x => x.Id == list[2].Id).ShouldBeFalse();
            stored.Any(x => x.Id == list[3].Id).ShouldBeFalse();
            stored.Any(x => x.Id == list[7].Id).ShouldBeFalse();
        }
Exemplo n.º 2
0
        public async Task schedule_execution()
        {
            var list = new List <Envelope>();

            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());


            list[5].ExecutionTime = DateTimeOffset.Now.AddMinutes(5);

            list[7].ExecutionTime = DateTimeOffset.Now.AddMinutes(5);
            list[9].ExecutionTime = DateTimeOffset.Now.AddMinutes(5);

            await ThePersistence.ScheduleExecution(new[] { list[5], list[7], list[9] });

            var stored = ThePersistence.AllIncomingEnvelopes();

            stored.Count(x => x.Status == TransportConstants.Incoming).ShouldBe(7);
            stored.Count(x => x.Status == TransportConstants.Scheduled).ShouldBe(3);

            stored.Single(x => x.Id == list[5].Id).ExecutionTime.HasValue.ShouldBeTrue();
            stored.Single(x => x.Id == list[7].Id).ExecutionTime.HasValue.ShouldBeTrue();
            stored.Single(x => x.Id == list[9].Id).ExecutionTime.HasValue.ShouldBeTrue();
        }
Exemplo n.º 3
0
        public async Task move_to_dead_letter_storage()
        {
            var list = new List <Envelope>();

            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());


            var ex = new DivideByZeroException("Kaboom!");

            var report2 = new ErrorReport(list[2], ex);
            var report3 = new ErrorReport(list[3], ex);
            var report4 = new ErrorReport(list[4], ex);

            await ThePersistence.MoveToDeadLetterStorage(new[] { report2, report3, report4 });

            var stored = ThePersistence.AllIncomingEnvelopes();

            stored.Length.ShouldBe(7);

            stored.Any(x => x.Id == list[2].Id).ShouldBeFalse();
            stored.Any(x => x.Id == list[3].Id).ShouldBeFalse();
            stored.Any(x => x.Id == list[4].Id).ShouldBeFalse();
        }
Exemplo n.º 4
0
        public async Task store_a_single_incoming_envelope()
        {
            var envelope = ObjectMother.Envelope();

            envelope.Status = TransportConstants.Incoming;

            await ThePersistence.StoreIncoming(envelope);

            var stored = ThePersistence.AllIncomingEnvelopes().Single();

            stored.Id.ShouldBe(envelope.Id);
            stored.OwnerId.ShouldBe(envelope.OwnerId);
            stored.Status.ShouldBe(envelope.Status);
        }
Exemplo n.º 5
0
        public async Task get_counts()
        {
            var list = new List <Envelope>();

            // 10 incoming
            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());


            // 7 scheduled
            list.Clear();
            for (var i = 0; i < 7; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Scheduled;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());


            // 3 outgoing
            list.Clear();
            for (var i = 0; i < 3; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Outgoing;

                list.Add(envelope);
            }

            await ThePersistence.StoreOutgoing(list.ToArray(), 0);

            var counts = await ThePersistence.Admin.GetPersistedCounts();

            counts.Incoming.ShouldBe(10);
            counts.Scheduled.ShouldBe(7);
            counts.Outgoing.ShouldBe(3);
        }
Exemplo n.º 6
0
        public async Task increment_the_attempt_count_of_incoming_envelope()
        {
            var envelope = ObjectMother.Envelope();

            envelope.Status = TransportConstants.Incoming;

            await ThePersistence.StoreIncoming(envelope);

            var prop = ReflectionHelper.GetProperty <Envelope>(x => x.Attempts);

            prop.SetValue(envelope, 3);

            await ThePersistence.IncrementIncomingEnvelopeAttempts(envelope);

            var stored = ThePersistence.AllIncomingEnvelopes().Single();

            stored.Attempts.ShouldBe(3);
        }
Exemplo n.º 7
0
        public async Task store_multiple_incoming_envelopes()
        {
            var list = new List <Envelope>();

            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());

            var stored = ThePersistence.AllIncomingEnvelopes();

            list.Select(x => x.Id).OrderBy(x => x)
            .ShouldHaveTheSameElementsAs(stored.Select(x => x.Id).OrderBy(x => x));
        }
Exemplo n.º 8
0
        public async Task load_dead_letter_envelope()
        {
            var list = new List <Envelope>();

            for (var i = 0; i < 10; i++)
            {
                var envelope = ObjectMother.Envelope();
                envelope.Status = TransportConstants.Incoming;

                list.Add(envelope);
            }

            await ThePersistence.StoreIncoming(list.ToArray());


            var ex = new DivideByZeroException("Kaboom!");

            var report2 = new ErrorReport(list[2], ex);
            var report3 = new ErrorReport(list[3], ex);
            var report4 = new ErrorReport(list[4], ex);

            await ThePersistence.MoveToDeadLetterStorage(new[] { report2, report3, report4 });


            var stored = await ThePersistence.Admin.LoadDeadLetterEnvelope(report2.Id);

            stored.ShouldNotBeNull();

            stored.ExceptionMessage.ShouldBe(report2.ExceptionMessage);
            stored.Id.ShouldBe(report2.Id);
            stored.ExceptionText.ShouldBe(report2.ExceptionText);
            stored.ExceptionType.ShouldBe(report2.ExceptionType);
            stored.Explanation.ShouldBe(report2.Explanation);
            stored.MessageType.ShouldBe(report2.MessageType);
            stored.RawData.ShouldBe(report2.RawData);
            stored.Source.ShouldBe(report2.Source);
        }