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); }
public void Event_CreateWithId_ShouldSucceed() { // Arrange string eventId = Guid.NewGuid().ToString(); const string licensePlate = "1-TOM-337"; // Act var createdEvent = new NewCarRegistered(eventId, licensePlate); // Assert Assert.NotNull(createdEvent); Assert.Equal(eventId, createdEvent.Id); Assert.NotNull(createdEvent.Subject); Assert.NotNull(createdEvent.Data); Assert.Equal(licensePlate, createdEvent.GetPayload().LicensePlate); Assert.NotEqual(default(DateTimeOffset), createdEvent.EventTime); }
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); }