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 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));
        }
Пример #3
0
        public ICqrsRuntime Build(
            AssemblyScanConfig[] assembliesWithCommandHandlers,
            AssemblyScanConfig[] assembliesWithEventHandlers)
        {
            var commandHandlers = OnResolveCommandHandlers(assembliesWithCommandHandlers);
            var eventHandlers   = OnResolveEventHandlers(assembliesWithEventHandlers);

            return(new CqrsRuntime
                   (
                       CommandBusFactory.Invoke(commandHandlers),
                       EventStoreFactory.Invoke(),
                       EventApplierFactory.Invoke(),
                       EventPublisherFactory.Invoke(eventHandlers)
                   ));
        }
        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 async Task PublishMultipleEvents_WithBuilder_ValidParameters_SucceedsWithTimeout()
        {
            // Arrange
            var events =
                Enumerable
                .Repeat <Func <Guid> >(Guid.NewGuid, 2)
                .Select(newGuid => new NewCarRegistered(
                            newGuid().ToString(),
                            subject: "integration-test",
                            licensePlate: "1-TOM-337"))
                .ToArray();

            IEventGridPublisher publisher = EventPublisherFactory.CreateEventGridEventPublisher(_config);

            // Act
            await publisher.PublishManyAsync(events);

            // Assert
            Assert.All(events, @event => AssertReceivedNewCarRegisteredEventWithTimeout(@event, @event.GetPayload()?.LicensePlate));
        }
        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);
        }
        public async Task PublishMultipleRawEvents_WithBuilder_ValidParameters_SucceedsWithTimeout()
        {
            // Arrange
            const string licensePlate = "1-TOM-1337";
            var          events       =
                Enumerable
                .Repeat <Func <Guid> >(Guid.NewGuid, 2)
                .Select(newGuid => new RawEvent(
                            newGuid().ToString(),
                            eventSubject: "integration-test",
                            eventData: $"{{\"licensePlate\": \"{licensePlate}\"}}",
                            eventType: "Arcus.Samples.Cars.NewCarRegistered",
                            eventVersion: "1.0",
                            eventTime: DateTimeOffset.Now))
                .ToArray();

            IEventGridPublisher publisher = EventPublisherFactory.CreateEventGridEventPublisher(_config);

            // Act
            await publisher.PublishManyAsync(events);

            // Assert
            Assert.All(events, rawEvent => AssertReceivedNewCarRegisteredEventWithTimeout(rawEvent, licensePlate));
        }