private void OnConfigurationEntryModified(ConfigurationEntryModified e)
 {
     foreach (var propertyId in e.Values.Keys)
     {
         this.values[propertyId] = CreateConfigurationValue(propertyId, e.Values[propertyId]);
     }
 }
        public async Task Handle_ConfigurationEntryModifiedEvent_UpdatesValues()
        {
            // arrange
            var initialProject = this.CreateProject();
            var initialEntity  = initialProject.Entities.First();
            var initialEntry   = initialEntity.Entries.First();

            var message = new ConfigurationEntryModified
            {
                Id      = initialProject.Id,
                EntryId = initialEntry.Id,
                Values  = new Dictionary <Guid, object>
                {
                    { initialEntity.Properties.ElementAt(0).Id, "TestValue1" },
                    { initialEntity.Properties.ElementAt(1).Id, "TestValue2" }
                },
                Version   = 2,
                TimeStamp = DateTimeOffset.Now
            };

            var target = new ReadModelEventHandler(this.context.DbContext, this.context.Mapper);

            // act
            await target.Handle(message);

            // assert
            var values = this.context.DbContext.Values.Where(p => p.EntryId == message.EntryId);

            Assert.Equal(2, values.Count());
            Assert.Contains(values, v => v.Value == "TestValue1");
            Assert.Contains(values, v => v.Value == "TestValue2");
        }
        public async Task Handle_ConfigurationEntryModifiedEvent_UpdatesProjectVersionTracking()
        {
            // arrange
            var initialProject = this.CreateProject();
            var initialEntity  = initialProject.Entities.First();
            var initialEntry   = initialEntity.Entries.First();

            var message = new ConfigurationEntryModified
            {
                Id      = initialProject.Id,
                EntryId = initialEntry.Id,
                Values  = new Dictionary <Guid, object>
                {
                    { initialEntity.Properties.ElementAt(0).Id, "TestValue1" },
                    { initialEntity.Properties.ElementAt(1).Id, "TestValue2" }
                },
                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> ConvertEntryModifiedToValues(ConfigurationEntryModified 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(ConfigurationEntryModified message)
        {
            message.ArgumentNotNull(nameof(message));

            await this.UpdateProjectAsync(message);

            IQueryable <ConfigurationValue> oldValues = this.dbContext.Values.Where(p => p.EntryId == message.EntryId);

            this.dbContext.Values.RemoveRange(oldValues);

            var newValues = this.mapper.Map <IEnumerable <ConfigurationValue> >(message);

            this.dbContext.Values.AddRange(newValues);

            await this.dbContext.SaveChangesAsync();
        }
Exemple #6
0
        public void ModifyEntry(Guid entryId, IEnumerable <object> values)
        {
            values.ArgumentNotNull(nameof(values));

            var entry = this.GetEntry(entryId);

            if (entry.Definition.Properties.Count() != values.Count())
            {
                throw new ArgumentException("The amount of values does not match the amount of properties.", nameof(values));
            }

            var propertyValues = entry.Definition.Properties.Select((p, i) => new { PropertyId = p.Id, Value = values.ElementAt(i) })
                                 .ToDictionary(i => i.PropertyId, i => i.Value);

            var e = new ConfigurationEntryModified
            {
                Id      = this.Id,
                EntryId = entryId,
                Values  = propertyValues
            };

            this.ApplyChange(e);
        }
Exemple #7
0
 private void Apply(ConfigurationEntryModified e)
 {
     this.eventAggregator.Publish(e);
 }