public async Task PublishMultipleCloudEvent_WithBuilder_ValidParameters_Succeeds()
        {
            // Arrange
            const string eventSubject = "integration-test";
            const string licensePlate = "1-TOM-337";
            var          firstEventId = Guid.NewGuid().ToString();
            var          firstEvent   = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), eventSubject, firstEventId)
            {
                Data            = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            };
            var secondEventId = Guid.NewGuid().ToString();
            var secondEvent   = new CloudEvent(CloudEventsSpecVersion.V1_0, "NewCarRegistered", new Uri("http://test-host"), eventSubject, secondEventId)
            {
                Data            = new CarEventData(licensePlate),
                DataContentType = new ContentType("application/json")
            };

            CloudEvent[] cloudEvents = { firstEvent, secondEvent };

            IEventGridPublisher publisher = EventPublisherFactory.CreateCloudEventPublisher(_config);

            // Act
            await publisher.PublishManyAsync(cloudEvents);

            // Assert
            Assert.All(cloudEvents, cloudEvent => AssertReceivedNewCarRegisteredEventWithTimeout(cloudEvent, licensePlate));
        }
        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);
        }
        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);
        }