private Envelope <IEvent> ParseEvent(StoredEvent storedEvent) { try { var @event = formatter.Parse(storedEvent.Data); @event.SetEventNumber(storedEvent.EventNumber); @event.SetEventStreamNumber(storedEvent.EventStreamNumber); return(@event); } catch (TypeNameNotFoundException) { return(null); } catch (Exception ex) { log.LogFatal(ex, w => w .WriteProperty("action", "ParseEvent") .WriteProperty("state", "Failed") .WriteProperty("eventId", storedEvent.Data.EventId.ToString()) .WriteProperty("eventNumber", storedEvent.EventNumber)); throw; } }
public void Should_serialize_and_deserialize_envelope() { var commitId = Guid.NewGuid(); var inputEvent = new Envelope <MyEvent>(new MyEvent { MyProperty = "My-Property" }); inputEvent.SetAggregateId(Guid.NewGuid()); inputEvent.SetCommitId(commitId); inputEvent.SetEventId(Guid.NewGuid()); inputEvent.SetEventPosition("1"); inputEvent.SetEventStreamNumber(1); inputEvent.SetTimestamp(SystemClock.Instance.GetCurrentInstant()); var eventData = sut.ToEventData(inputEvent.To <IEvent>(), commitId); var outputEvent = sut.Parse(eventData).To <MyEvent>(); AssertHeaders(inputEvent.Headers, outputEvent.Headers); AssertPayload(inputEvent, outputEvent); }
public EventReceiverTests() { var events = new[] { new StoredEvent("3", 3, eventData1), new StoredEvent("4", 4, eventData2), new StoredEvent("5", 5, eventData3) }; consumerName = eventConsumer.GetType().Name; var eventStore = new MyEventStore(events); A.CallTo(() => eventConsumer.Name).Returns(consumerName); A.CallTo(() => eventConsumerInfoRepository.FindAsync(consumerName)).Returns(Task.FromResult <IEventConsumerInfo>(consumerInfo)); A.CallTo(() => formatter.Parse(eventData1)).Returns(envelope1); A.CallTo(() => formatter.Parse(eventData2)).Returns(envelope2); A.CallTo(() => formatter.Parse(eventData3)).Returns(envelope3); sut = new EventReceiver(formatter, eventStore, eventConsumerInfoRepository, log); }
public void Should_serialize_and_deserialize_envelope() { var commitId = Guid.NewGuid(); var inputEvent = new Envelope <MyEvent>(new MyEvent { MyProperty = "My-Property" }); inputEvent.SetAggregateId(Guid.NewGuid()); inputEvent.SetCommitId(commitId); inputEvent.SetEventId(Guid.NewGuid()); inputEvent.SetEventNumber(1); inputEvent.SetEventStreamNumber(1); inputEvent.SetTimestamp(SystemClock.Instance.GetCurrentInstant()); var sut = new EventDataFormatter(typeNameRegistry, serializerSettings); var eventData = sut.ToEventData(inputEvent.To <IEvent>(), commitId); var outputEvent = sut.Parse(eventData).To <MyEvent>(); CompareHeaders(outputEvent.Headers, inputEvent.Headers); Assert.Equal(inputEvent.Payload.MyProperty, outputEvent.Payload.MyProperty); }