Exemple #1
0
        public CherrySeeder(Action <ISeederConfigurationBuilder> configurationExpression)
        {
            _entityMetadataDict = new Dictionary <Type, EntityMetadata>();
            _idMappingProvider  = new IdMappingProvider();

            var configBuilder = new SeederConfigurationBuilder();

            configurationExpression(configBuilder);
            _configuration = configBuilder.Build();

            _objectListTransformation = new ObjectListTransformation(
                new ObjectTransformation.ObjectTransformation(
                    new PropertyHandler(
                        _idMappingProvider,
                        new TypeTransformationProvider(_configuration.TypeTransformations)
                        )
                    )
                );

            foreach (var entitySetting in _configuration.EntitySettings)
            {
                _entityMetadataDict.Add(entitySetting.EntityType, new EntityMetadata
                {
                    EntityType    = entitySetting.EntityType,
                    EntitySetting = entitySetting
                });
            }
        }
Exemple #2
0
        public void SetGlobalAndEntitySpecificRepository()
        {
            // Arrange global settings
            var globalRepository = new InMemoryRepository();

            _configBuilder.WithRepository(globalRepository);

            // Arrange entity specific settings
            _configBuilder.ForEntity <EntityWithSimpleProperties>();

            var entitySpecificRepository = new InMemoryRepository();

            _configBuilder.ForEntity <EntityWithConformIntPk>()
            .WithRepository(entitySpecificRepository);

            // Act
            var config = _configBuilder.Build();

            // Assert
            Assert.AreEqual(globalRepository, config.EntitySettings.GetSetting <EntityWithSimpleProperties>().Repository);
            Assert.AreEqual(entitySpecificRepository, config.EntitySettings.GetSetting <EntityWithConformIntPk>().Repository);
        }