public void When_passing_property_with_reserved_name() { var reserved = ReservedEventProperties() .ToDictionary(p => p, p => new EntityProperty(42)); var properties = EventProperties.From(reserved); Assert.That(properties.Count, Is.EqualTo(0), "Should skip all properties with reserved names, such as RowKey, Id, etc"); }
static EventData CreateEvent(string id) { var properties = new Dictionary <string, EntityProperty> { { "Type", new EntityProperty("StreamChanged") }, { "Data", new EntityProperty("{}") } }; return(new EventData(EventId.From(id), EventProperties.From(properties))); }
static EventData CreateEvent(int num) { var properties = new Dictionary <string, EntityProperty> { { "Type", new EntityProperty("TestEvent") }, { "Data", new EntityProperty(num) } }; return(new EventData(EventId.None, EventProperties.From(properties))); }
private static EventData ToEventData <TAggregateId>(IDomainEvent <TAggregateId> e) where TAggregateId : IAggregateId { var properties = new { Type = e.GetType().AssemblyQualifiedName, Data = JsonConvert.SerializeObject(e) }; return(new EventData(EventId.None, EventProperties.From(properties))); }
static EventData Event(int id) { var properties = new { Id = id, Type = "<type>", Data = "{some}" }; return(new EventData(EventId.From(id.ToString()), EventProperties.From(properties))); }
public EventData BuildEventData <T>(IEvent eventData) where T : IAggregateRoot { var id = _guidProvider.GenerateGuid(); var properties = new EventStorageData( typeof(T).Name, id, eventData.GetType().AssemblyQualifiedName, JsonConvert.SerializeObject(eventData)); return(new EventData(EventId.From(id), EventProperties.From(properties))); }
static EventData ToEventData(Event e) { var id = Guid.NewGuid(); var properties = new { Id = id, Type = e.GetType().FullName, Data = JsonConvert.SerializeObject(e) }; return(new EventData(EventId.From(id), EventProperties.From(properties))); }
static EventData ToEventData(object @event) { var id = Guid.NewGuid().ToString("D"); var properties = new EventEntity { Id = id, Type = @event.GetType().FullName, Data = JsonConvert.SerializeObject(@event, SerializerSettings) }; return(new EventData(EventId.From(id), EventProperties.From(properties))); }
static EventData CreateEvent(string id = null) { var properties = new Dictionary <string, EntityProperty> { { "Type", new EntityProperty("StreamChanged") }, { "Data", new EntityProperty("{}") } }; var eventId = id != null ? EventId.From(id) : EventId.None; return(new EventData(eventId, EventProperties.From(properties))); }
static EventData Event(object e) { var id = Guid.NewGuid(); var properties = new { Id = id, // id that you specify for Event ctor is used only for duplicate event detection Type = e.GetType().Name, // you can include any number of custom properties along with event Data = JSON(e), // you're free to choose any name you like for data property Bin = BSON(e) // and any storage format: binary, string, whatever (any EdmType) }; return(new EventData(EventId.From(id), EventProperties.From(properties))); }
static void AssertEventEntity(int version, EventEntity actual) { var expected = new { RowKey = version.FormatEventRowKey(), Properties = EventProperties.From(new Dictionary <string, EntityProperty> { { "Type", new EntityProperty("StreamChanged") }, { "Data", new EntityProperty("{}") }, }), Version = version, }; actual.ShouldMatch(expected.ToExpectedObject()); }
static EventData Event(object @event, params Include[] includes) { var id = Guid.NewGuid(); var properties = new { Type = @event.GetType().Name, Data = JsonConvert.SerializeObject(@event) }; return(new EventData( EventId.From(id), EventProperties.From(properties), EventIncludes.From(includes))); }
public static EventData ToEventData(this DomainEvent e, int version, params ITableEntity[] includes) { // Properties are turned into columns in the table, which can be // convenient for quickly glancing at the data. var properties = new { // Visualizing the event id in the table as a column is useful for querying e.EventId, EventType = e.GetType().FullName, Data = new Serializer().Serialize(e), DataVersion = (e.GetType().Assembly.GetName().Version ?? new Version(1, 0)).ToString(2), Version = version, }; return(new EventData( // This turns off the SS-UID-[id] duplicate event detection rows, since // we use GUIDs for events and therefore we'll never be duplicating EventId.None, EventProperties.From(properties), EventIncludes.From(includes.Select(x => Include.InsertOrReplace(x))))); }
public async Task <AppendResult> AppendEventAsync <TAggregateId>(IDomainEvent <TAggregateId> @event) where TAggregateId : IAggregateId { var paritionKey = @event.AggregateId.IdAsString(); var partition = new Partition(_table, paritionKey); var openResult = await Stream.TryOpenAsync(partition).ConfigureAwait(false); var stream = openResult.Found ? openResult.Stream : new Stream(partition); if (stream.Version != @event.AggregateVersion) { throw new EventStoreConcurrencyException(); } try { var evtId = EventId.From(@event.EventId.ToString()); var evtProperties = new { Id = @event.EventId.ToString(), Type = @event.GetType().AssemblyQualifiedName, Data = JsonConvert.SerializeObject(@event) }; var writeResult = await Stream.WriteAsync(stream, new EventData(EventId.From(evtId), EventProperties.From(evtProperties))) .ConfigureAwait(false); return(new AppendResult(writeResult.Events.ToList().Last().Version)); } catch (ConcurrencyConflictException) { throw new EventStoreConcurrencyException(); } }