private void AssertReceivedNewCarRegisteredEventWithTimeout(CloudEvent @event, string licensePlate)
        {
            TracePublishedEvent(@event.Id, @event);
            string receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(@event.Id, timeout: TimeSpan.FromSeconds(30));

            ArcusAssert.ReceivedNewCarRegisteredEvent(@event.Id, @event.Type, @event.Subject, licensePlate, receivedEvent);
        }
        public async Task PublishSingleRawEventWithDetailedInfo_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string licensePlate    = "1-TOM-337";
            const string expectedSubject = "/";
            var          eventId         = Guid.NewGuid().ToString();
            var          data            = new CarEventData(licensePlate);
            var          rawEventBody    = JsonConvert.SerializeObject(data);
            var          cloudEvent      = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), subject: expectedSubject, id: eventId, DateTime.UtcNow)
            {
                Data            = data,
                DataContentType = new ContentType("application/json")
            };

            IEventGridPublisher publisher = EventPublisherFactory.CreateCloudEventPublisher(_config);

            // Act
            await publisher.PublishRawCloudEventAsync(
                cloudEvent.SpecVersion,
                cloudEvent.Id,
                cloudEvent.Type,
                cloudEvent.Source,
                rawEventBody,
                cloudEvent.Subject,
                cloudEvent.Time ?? default(DateTimeOffset));

            TracePublishedEvent(eventId, cloudEvent);

            // Assert
            var receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId);

            ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, cloudEvent.Type, cloudEvent.Subject, licensePlate, receivedEvent);
        }
        private void AssertReceivedEventWithRetryCount(IEvent @event, string licensePlate)
        {
            TracePublishedEvent(@event.Id, @event);
            string receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(@event.Id, retryCount: 5);

            ArcusAssert.ReceivedNewCarRegisteredEvent(@event.Id, @event.EventType, @event.Subject, licensePlate, receivedEvent);
        }
Exemple #4
0
        public void WrapInServiceBusMessage_BasicWithEncoding_ReturnsValidServiceBusMessageWithSpecifiedEncoding()
        {
            // Arrange
            var originalMessagePayload = OrderGenerator.Generate();
            var expectedEncoding       = Encoding.ASCII;

            // Act
            var serviceBusMessage = originalMessagePayload.WrapInServiceBusMessage(encoding: expectedEncoding);

            // Assert
            Assert.NotNull(serviceBusMessage);
            Assert.Null(serviceBusMessage.CorrelationId);
            var userProperties = serviceBusMessage.UserProperties;

            Assert.True(userProperties.ContainsKey(PropertyNames.ContentType));
            Assert.True(userProperties.ContainsKey(PropertyNames.Encoding));
            Assert.False(userProperties.ContainsKey(PropertyNames.TransactionId));
            ArcusAssert.MatchesDictionaryEntry(PropertyNames.ContentType, ExpectedDefaultContentType, userProperties);
            AssertMessagePayload(serviceBusMessage, userProperties, expectedEncoding, originalMessagePayload);
        }
Exemple #5
0
        public void WrapInServiceBusMessage_BasicWithoutOptions_ReturnsValidServiceBusMessage()
        {
            // Arrange
            var messagePayload = OrderGenerator.Generate();

            // Act
            var serviceBusMessage = messagePayload.WrapInServiceBusMessage();

            // Assert
            Assert.NotNull(serviceBusMessage);
            Assert.Null(serviceBusMessage.CorrelationId);
            var userProperties = serviceBusMessage.UserProperties;

            Assert.True(userProperties.ContainsKey(PropertyNames.ContentType));
            Assert.True(userProperties.ContainsKey(PropertyNames.Encoding));
            Assert.False(userProperties.ContainsKey(PropertyNames.TransactionId));
            ArcusAssert.MatchesDictionaryEntry(PropertyNames.ContentType, ExpectedDefaultContentType, userProperties);
            ArcusAssert.MatchesDictionaryEntry(PropertyNames.Encoding, ExpectedDefaultEncoding, userProperties);
            AssertMessagePayload(serviceBusMessage, userProperties, ExpectedDefaultEncoding, messagePayload);
        }
        public async Task PublishSingleEventGridEvent_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string eventSubject = "integration-test";
            const string licensePlate = "1-TOM-337";
            var          eventId      = Guid.NewGuid().ToString();
            var          @event       = new NewCarRegistered(eventId, eventSubject, licensePlate);

            IEventGridPublisher publisher = EventPublisherFactory.CreateEventGridEventPublisher(_config);

            // Act
            await publisher.PublishAsync(@event);

            TracePublishedEvent(eventId, @event);

            // Assert
            var receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId);

            ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, @event.EventType, eventSubject, licensePlate, receivedEvent);
        }
        public void WrapInServiceBusMessage_BasicWithOperationId_ReturnsValidServiceBusMessageWithSpecifiedCorrelationId()
        {
            // Arrange
            Order messagePayload = OrderGenerator.Generate();
            var   operationId    = Guid.NewGuid().ToString();

            // Act
            ServiceBusMessage serviceBusMessage = messagePayload.AsServiceBusMessage(operationId: operationId);

            // Assert
            Assert.NotNull(serviceBusMessage);
            Assert.Equal(operationId, serviceBusMessage.CorrelationId);
            IDictionary <string, object> userProperties = serviceBusMessage.ApplicationProperties;

            Assert.True(userProperties.ContainsKey(PropertyNames.ContentType));
            Assert.True(userProperties.ContainsKey(PropertyNames.Encoding));
            Assert.False(userProperties.ContainsKey(PropertyNames.TransactionId));
            ArcusAssert.MatchesDictionaryEntry(PropertyNames.ContentType, ExpectedDefaultContentType, userProperties);
            ArcusAssert.MatchesDictionaryEntry(PropertyNames.Encoding, ExpectedDefaultEncoding, userProperties);
            AssertMessagePayload(serviceBusMessage, userProperties, ExpectedDefaultEncoding, messagePayload);
        }
        public async Task PublishSingleCloudEvent_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string eventSubject = "integration-test";
            const string licensePlate = "1-TOM-337";
            var          eventId      = Guid.NewGuid().ToString();
            var          @event       = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), eventSubject, eventId)
            {
                Data            = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            };

            IEventGridPublisher publisher = EventPublisherFactory.CreateCloudEventPublisher(_config);

            // Act
            await publisher.PublishAsync(@event);

            TracePublishedEvent(eventId, @event);

            // Assert
            string receivedEvent = _endpoint.ServiceBusEventConsumerHost.GetReceivedEvent(eventId);

            ArcusAssert.ReceivedNewCarRegisteredEvent(eventId, @event.Type, eventSubject, licensePlate, receivedEvent);
        }