public void ShouldGetEventTypeFromAttribute()
        {
            // Act
            var eventType = EventTypeAttribute.GetEventTypeFrom(typeof(EventTypeGivenEventType));

            // Assert
            eventType.ShouldBe("TestEventType");
        }
示例#2
0
        private IEnumerable <MethodInfo> GenerateExecutableMethods(IEventListener listener, IEventDescriptor eventInfo)
        {
            string eventType = EventTypeAttribute.GetEventType(listener);

            if (eventType != eventInfo.EventType)
            {
                return(Enumerable.Empty <MethodInfo>());
            }

            return(listener.GetType()
                   .GetMethods()
                   .Where(method =>
            {
                var ps = method.GetParameters();
                return ps.Length == 0 || ps.Length == 1;
            })
                   .Where(method =>
            {
                string eventName = EventNameAttribute.GetEventName(method);
                return eventName == eventInfo.EventName;
            }).ToList());
        }
        public static NewStreamMessage ToMessageData <TEvent>(this TEvent @event,
                                                              IDictionary <string, object>?headers = null) where TEvent : EventSourceEvent
        {
            var eventClrType = (@event ?? throw new ArgumentNullException(nameof(@event))).GetType();
            var typeName     = EventTypeAttribute.GetEventTypeFrom(eventClrType);

            if (typeName == default)
            {
                throw new ArgumentException("Event Type Name could not be determined", nameof(@event));
            }

            var version = Attributes.GetCustomAttributeValue <EventTypeAttribute, int>(eventClrType,
                                                                                       eventTypeAttribute => eventTypeAttribute.Version);

            headers ??= new Dictionary <string, object>();
            headers.Add(Constants.VersionKey, version);
            headers.TryAdd(Constants.TimestampKey, new DateTimeOffset(DateTime.UtcNow));

            var data     = Serializer.Serialize(@event, eventClrType);
            var metadata = Serializer.Serialize(headers);

            return(new NewStreamMessage(Guid.NewGuid(), typeName, data, metadata));
        }