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 void ParseToNewCarRegistered_ValidRawEvent_ShouldSucceed()
        {
            // Arrange
            const string           eventId       = "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66";
            const string           licensePlate  = "1-TOM-337";
            var                    originalEvent = new NewCarRegistered(eventId, licensePlate);
            var                    rawEventBody  = JsonConvert.SerializeObject(originalEvent.GetPayload());
            var                    rawEvent      = new RawEvent(eventId, originalEvent.EventType, rawEventBody, originalEvent.Subject, originalEvent.DataVersion, originalEvent.EventTime);
            IEnumerable <RawEvent> events        = new List <RawEvent>
            {
                rawEvent
            };

            var serializedRawEvents = JsonConvert.SerializeObject(events);

            // Act
            var eventGridMessage = EventGridParser.Parse <NewCarRegistered>(serializedRawEvents);

            // Assert
            Assert.NotNull(eventGridMessage);
            Assert.NotNull(eventGridMessage.Events);
            Assert.Single(eventGridMessage.Events);
            var eventPayload = eventGridMessage.Events.Single();

            Assert.Equal(eventId, eventPayload.Id);
            Assert.Equal(originalEvent.Subject, eventPayload.Subject);
            Assert.Equal(originalEvent.EventType, eventPayload.EventType);
            Assert.Equal(originalEvent.EventTime, eventPayload.EventTime);
            Assert.Equal(originalEvent.DataVersion, eventPayload.DataVersion);
            Assert.NotNull(eventPayload.Data);

            CarEventData expectedEventData = originalEvent.GetPayload();
            CarEventData actualEventData   = eventPayload.GetPayload();

            Assert.NotNull(expectedEventData);
            Assert.NotNull(actualEventData);
            Assert.Equal(expectedEventData, actualEventData);
        }
Exemple #3
0
        private static void AssertReceivedNewCarRegisteredEvent(string eventId, string eventType, string eventSubject, string licensePlate, string receivedEvent)
        {
            Assert.NotEqual(String.Empty, receivedEvent);

            EventBatch <NewCarRegistered> deserializedEventGridMessage = EventGridParser.Parse <NewCarRegistered>(receivedEvent);

            Assert.NotNull(deserializedEventGridMessage);
            Assert.NotEmpty(deserializedEventGridMessage.SessionId);
            Assert.NotNull(deserializedEventGridMessage.Events);

            NewCarRegistered deserializedEvent = Assert.Single(deserializedEventGridMessage.Events);

            Assert.NotNull(deserializedEvent);
            Assert.Equal(eventId, deserializedEvent.Id);
            Assert.Equal(eventSubject, deserializedEvent.Subject);
            Assert.Equal(eventType, deserializedEvent.EventType);

            Assert.NotNull(deserializedEvent.Data);
            CarEventData eventData = deserializedEvent.GetPayload();

            Assert.NotNull(eventData);
            Assert.Equal(JsonConvert.DeserializeObject <CarEventData>(deserializedEvent.Data.ToString()), eventData);
            Assert.Equal(licensePlate, eventData.LicensePlate);
        }