Ejemplo n.º 1
0
        public void ShouldStoreAuditWithProperErrorStatusWhenOriginalDoesNotExist()
        {
            //arrange
            var rawMessage = MessageTestHelpers.GetAuditMessage();

            rawMessage.Headers.Add(Headers.Retry, "test");

            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            fixture.Register(() => Store);
            fixture.Register <IHeaderParser>(() => new HeaderParser());
            var service = fixture.Create <StoreMessagesThatAreRetriesService>();

            //act
            var id = service.Store(rawMessage,
                                   new QueueSettings("test", new ApplicationConfiguration {
                ApplicationId = "test"
            }));

            //assert
            using (var session = Store.OpenSessionForDefaultTenant())
            {
                var doc = session.Load <MessageDocument>(id);
                doc.Should().NotBeNull("Stored document should not be null");
                doc.AdditionalErrorStatus.Should().Be(AdditionalErrorStatus.IsRetry, "AdditionalErrorStatus should be IsRetry");
                doc.IsError.Should().BeFalse("IsError should be false");
                doc.CanRetry.Should().BeFalse("Can retry should be false");
            }
        }
Ejemplo n.º 2
0
        public void ShouldStoreRetryHistoryAfterStoringAnAuditRetry()
        {
            //arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            fixture.Register(() => Store);
            fixture.Register <IHeaderParser>(() => new HeaderParser());
            var service = fixture.Create <StoreMessagesThatAreRetriesService>();
            var originalMessageStorageService = fixture.Create <StoreMessagesThatAreNotRetriesService>();
            var queueSettings = new QueueSettings("test", new ApplicationConfiguration {
                ApplicationId = "test"
            });

            var originalMessage = MessageTestHelpers.GetErrorMessage();
            var originalId      = originalMessageStorageService.Store(originalMessage, queueSettings);

            var rawMessage = MessageTestHelpers.GetAuditMessage();

            rawMessage.Headers.Add(Headers.Retry, originalId.ToString());

            //act
            var id = service.Store(rawMessage, queueSettings);

            //assert
            using (var session = Store.OpenSessionForDefaultTenant())
            {
                var doc = session.Load <MessageDocument>(id);
                doc.Should().NotBeNull("Document should exist");
                doc.Retries.Count.Should().Be(1);
            }
        }
Ejemplo n.º 3
0
        public void ShouldHaveProperErrorStatusAfterStoringAnAuditRetry()
        {
            //arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            fixture.Register(() => Store);
            fixture.Register <IHeaderParser>(() => new HeaderParser());
            var service = fixture.Create <StoreMessagesThatAreRetriesService>();
            var originalMessageStorageService = fixture.Create <StoreMessagesThatAreNotRetriesService>();
            var queueSettings = new QueueSettings("test", new ApplicationConfiguration {
                ApplicationId = "test"
            });

            var originalMessage = MessageTestHelpers.GetErrorMessage();
            var originalId      = originalMessageStorageService.Store(originalMessage, queueSettings);

            var rawMessage = MessageTestHelpers.GetAuditMessage();

            rawMessage.Headers.Add(Headers.Retry, originalId.ToString());

            //act
            var id = service.Store(rawMessage, queueSettings);

            //assert
            using (var session = Store.OpenSessionForDefaultTenant())
            {
                var doc = session.Load <MessageDocument>(id);
                doc.Should().NotBeNull("Document should exist");
                doc.AdditionalErrorStatus.Should().Be(AdditionalErrorStatus.Resolved, "additional error status should be resolved");
                doc.IsError.Should().BeTrue("IsError should be true");
                doc.CanRetry.Should().BeFalse("Can retry should be false");
            }
        }
        public void ShouldStoreAuditWithProperExpiration()
        {
            //arrange
            var rawMessage = MessageTestHelpers.GetAuditMessage();

            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            fixture.Register(() => Store);
            fixture.Register <IHeaderParser>(() => new HeaderParser());
            var service = fixture.Create <StoreMessagesThatAreNotRetriesService>();

            int auditExpirationHours = 1;
            int errorExpirationHours = 2;

            DateTime expiresAfter  = DateTime.UtcNow.AddHours(auditExpirationHours).AddMinutes(-15);
            DateTime expiresBefore = DateTime.UtcNow.AddHours(auditExpirationHours).AddMinutes(15);

            //act
            var id = service.Store(rawMessage,
                                   new QueueSettings("test", new ApplicationConfiguration {
                ApplicationId = "test", DocumentExpirationInHours = auditExpirationHours, ErrorDocumentExpirationInHours = errorExpirationHours
            }));

            //assert
            using (var session = Store.OpenSessionForDefaultTenant())
            {
                var doc     = session.Load <MessageDocument>(id);
                var expires = DateTime.Parse(session.Advanced.GetMetadataFor(doc)["Raven-Expiration-Date"].ToString());
                expires.Should().BeAfter(expiresAfter, $"Should expire after around {auditExpirationHours} hours");
                expires.Should().BeBefore(expiresBefore, $"Should expire after around {auditExpirationHours} hours");
            }
        }
Ejemplo n.º 5
0
        public void HeaderParserGetsProperAdditionalErrorStatusFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.AdditionalErrorStatus.Should().Be(AdditionalErrorStatus.NotAnError);
        }
Ejemplo n.º 6
0
        public void HeaderParserGetsProperIsErrorFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.IsError.Should().BeFalse();
        }
Ejemplo n.º 7
0
        public void HeaderParserGetsProperContentTypeAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.ContentType.Should().Be(ApplicationJsonContentType);
        }
Ejemplo n.º 8
0
        public void HeaderParserGetsProperTimeSentFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.TimeSent.Should().Be(DateTime.ParseExact("2014-12-31T02:24:06:300190Z", DateTimeFormat, CultureInfo.InvariantCulture).ToUniversalTime());
        }
Ejemplo n.º 9
0
        public void HeaderParserGetsProperBusTechnologyFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.BusTechnology.Should().Be("NServiceBus");
        }
Ejemplo n.º 10
0
        public void CanRoundTripHeaders()
        {
            //arrange
            var rawMessage = MessageTestHelpers.GetAuditMessage();

            //act
            var publishData   = rawMessage.GetEelementsForRabbitPublish();
            var newRawMessage = new RawMessage(new BasicDeliverEventArgs("tag", 1, false, "exchange", "", new BasicProperties {
                Headers = publishData.Item2
            }, publishData.Item1));

            //assert
            newRawMessage.Headers.ShouldBeEquivalentTo(rawMessage.Headers);
        }
Ejemplo n.º 11
0
        public void HeaderParserGetsProperNServiceSagaInfoFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.SagaInfo.Should().NotBeNull();
            doc.SagaInfo.Class.Should().Be("Autobahn.Fulfillment.Tasks.Sagas.FulfillmentSaga");
            doc.SagaInfo.Key.Should().Be("3b654483-a8ea-470b-8c78-a4110184fa8c");
        }
Ejemplo n.º 12
0
        public void HeaderParserGetsProperNServiceBusMessageTypesAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.MessageTypes.ShouldBeEquivalentTo(new List <TypeName>
            {
                new TypeName("Autobahn.Fulfillment.Contracts.Ordering.NotifyOrderHasBeenCanceled, Autobahn.Fulfillment.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
                new TypeName("Autobahn.Fulfillment.Contracts.Ordering.INotifyOrderHasBeenCanceled, Autobahn.Fulfillment.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
                new TypeName("Veyron.Messages.Commands.ICommand, Veyron.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
            });
        }
Ejemplo n.º 13
0
        public void HeaderParserGetsProperHeadersFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            doc.Headers.ShouldBeEquivalentTo(new Dictionary <string, string>
            {
                { "NServiceBus.MessageId", "33db72af-be36-4773-8c95-a41200279462" },
                { "NServiceBus.CorrelationId", "33db72af-be36-4773-8c95-a41200279462" },
                { "NServiceBus.MessageIntent", "Send" },
                { "NServiceBus.Version", "5.0.3" },
                { "NServiceBus.TimeSent", "2014-12-31 02:24:06:300190 Z" },
                { "NServiceBus.ContentType", "application/json" },
                {
                    "NServiceBus.EnclosedMessageTypes",
                    "Autobahn.Fulfillment.Contracts.Ordering.NotifyOrderHasBeenCanceled, Autobahn.Fulfillment.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;Autobahn.Fulfillment.Contracts.Ordering.INotifyOrderHasBeenCanceled, Autobahn.Fulfillment.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;Veyron.Messages.Commands.ICommand, Veyron.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                },
                { "NServiceBus.ConversationId", "84383232-6efc-4ca0-a304-a412002794da" },
                { "NServiceBus.OriginatingMachine", "QA-1-WEB-1" },
                { "NServiceBus.OriginatingEndpoint", "Ronaele.UI.Web" },
                { "NServiceBus.RabbitMQ.CallbackQueue", "Autobahn.Fulfillment.Host.QA-1-WEB-1" },
                { "NServiceBus.ReplyToAddress", "Ronaele.UI.Web" },
                {
                    "NServiceBus.InvokedSagas", "Autobahn.Fulfillment.Tasks.Sagas.FulfillmentSaga:3b654483-a8ea-470b-8c78-a4110184fa8c"
                },
                { "NServiceBus.ProcessingStarted", "2014-12-31 02:24:06:794413 Z" },
                { "NServiceBus.ProcessingEnded", "2014-12-31 02:24:07:074692 Z" },
                { "NServiceBus.ProcessingMachine", "QA-1-WEB-1" },
                { "NServiceBus.ProcessingEndpoint", "Autobahn.Fulfillment.Host" },
                { "NServiceBus.OriginatingAddress", "Ronaele.UI.Web@QA-1-WEB-1" },
                { "WinIdName", "GCC-DEV\\developer" },
                { "$.diagnostics.hostid", "0ba7c10aa289498b4d9d6936935f51f7" },
                { "$.diagnostics.hostdisplayname", "QA-1-WEB-1" },
                { "$.diagnostics.license.expired", "false" },
                { "$.diagnostics.originating.hostid", "6da45a72687753278b930fe38a91a4ad" }
            });
        }
Ejemplo n.º 14
0
        public void HeaderParserGetsProperProcessingTimeFromAudit()
        {
            //arrange
            var rawMessage   = MessageTestHelpers.GetAuditMessage();
            var headerParser = new HeaderParser();
            var doc          = new MessageDocument();

            //act
            headerParser.AddHeaderInformation(rawMessage, doc);

            //assert
            var processingStarted =
                DateTime.ParseExact("2014-12-31T02:24:06:794413Z", DateTimeFormat, CultureInfo.InvariantCulture)
                .ToUniversalTime();
            var processingEnded =
                DateTime.ParseExact("2014-12-31T02:24:07:074692Z", DateTimeFormat, CultureInfo.InvariantCulture)
                .ToUniversalTime();

            doc.ProcessingTime.Should().Be(processingEnded - processingStarted);
        }