private void OnConfigurationEntryAdded(ConfigurationEntryAdded e) { var values = e.Values.Select(i => this.CreateConfigurationValue(i.Key, i.Value)); var entry = new ConfigurationEntry(this.EventAggregator, this.Definition, e.EntryId, values); this.entries.Add(entry); }
public void AddEntry(Guid entityId, IEnumerable <object> values) { var entity = this.Schema.Entities.SingleOrDefault(i => i.Id == entityId); if (entity == null) { throw new ArgumentException($"No entity definition with id {entityId} was found.", nameof(entityId)); } if (entity.Properties.Count() != values.Count()) { throw new ArgumentException("The amount of values does not match the amount of properties.", nameof(values)); } var propertyValues = entity.Properties.Select((p, i) => new { PropertyId = p.Id, Value = values.ElementAt(i) }) .ToDictionary(i => i.PropertyId, i => i.Value); var e = new ConfigurationEntryAdded { Id = this.Id, EntityId = entityId, EntryId = Guid.NewGuid(), Values = propertyValues }; this.ApplyChange(e); }
public async Task Handle_ConfigurationEntryAddedEvent_CreatesValues() { // arrange var initialProject = this.CreateProject(); var initialEntity = initialProject.Entities.First(); var initialProperty = initialEntity.Properties.First(); var message = new ConfigurationEntryAdded { Id = initialProject.Id, EntryId = Guid.NewGuid(), EntityId = initialEntity.Id, Values = new Dictionary <Guid, object> { { initialProperty.Id, "TestValue" } }, Version = 2, TimeStamp = DateTimeOffset.Now }; var target = new ReadModelEventHandler(this.context.DbContext, this.context.Mapper); // act await target.Handle(message); // assert var value = this.context.DbContext.Values.FirstOrDefault(p => p.EntryId == message.EntryId); Assert.NotNull(value); Assert.Equal(initialProperty.Id, value.PropertyId); Assert.Equal("TestValue", value.Value); }
public async Task Handle_ConfigurationEntryAddedEvent_UpdatesProjectVersionTracking() { // arrange var initialProject = this.CreateProject(); var initialEntity = initialProject.Entities.First(); var initialProperty = initialEntity.Properties.First(); var message = new ConfigurationEntryAdded { Id = initialProject.Id, EntryId = Guid.NewGuid(), EntityId = initialEntity.Id, Values = new Dictionary <Guid, object> { { initialProperty.Id, "TestValue" } }, Version = 2, TimeStamp = DateTimeOffset.Now }; var target = new ReadModelEventHandler(this.context.DbContext, this.context.Mapper); // act await target.Handle(message); // assert var project = this.context.DbContext.Projects.First(p => p.Id == message.Id); Assert.Equal(message.Id, project.Id); Assert.Equal(message.Version, project.Version); Assert.Equal(message.TimeStamp, project.TimeStamp); }
private static IEnumerable <ConfigurationValue> ConvertEntryAddedToValues(ConfigurationEntryAdded message) { message.ArgumentNotNull(nameof(message)); return(message.Values.Select(v => new ConfigurationValue { Id = Guid.NewGuid(), EntryId = message.EntryId, PropertyId = v.Key, Value = v.Value?.ToString() })); }
public async Task Handle(ConfigurationEntryAdded message) { message.ArgumentNotNull(nameof(message)); await this.UpdateProjectAsync(message); var entry = this.mapper.Map <ConfigurationEntry>(message); this.dbContext.Entries.Add(entry); var values = this.mapper.Map <IEnumerable <ConfigurationValue> >(message); this.dbContext.Values.AddRange(values); await this.dbContext.SaveChangesAsync(); }
private void Apply(ConfigurationEntryAdded e) { this.eventAggregator.Publish(e); }