示例#1
0
 /// <summary>
 /// Initializes a new instance of the StructuralDataGenerator class.
 /// </summary>
 /// <param name="dataAdapter">The data adapter.</param>
 /// <param name="dataGenerator">The data generator.</param>
 public StructuralDataGenerator(IStructuralDataAdapter dataAdapter, INamedValuesGenerator dataGenerator)
 {
     ExceptionUtilities.CheckArgumentNotNull(dataAdapter, "dataAdapter");
     ExceptionUtilities.CheckArgumentNotNull(dataGenerator, "dataGenerator");
     this.dataAdapter           = dataAdapter;
     this.memberValuesGenerator = dataGenerator;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the NullableNamedValuesGeneratorProxy class
 /// </summary>
 /// <param name="underlying">The underlying named-values generator</param>
 /// <param name="random">The random number generator to use when deciding whether to generate null</param>
 /// <param name="hints">The data generation hints</param>
 internal NullableNamedValuesGeneratorProxy(INamedValuesGenerator underlying, IRandomNumberGenerator random, IEnumerable <DataGenerationHint> hints)
 {
     ExceptionUtilities.CheckArgumentNotNull(underlying, "underlying");
     ExceptionUtilities.CheckArgumentNotNull(random, "random");
     ExceptionUtilities.CheckArgumentNotNull(hints, "hints");
     this.underlying          = underlying;
     this.random              = random;
     this.hints               = hints.ToList().AsReadOnly();
     this.noNullsHintPresent  = this.hints.OfType <NoNullsHint>().Any();
     this.allNullsHintPresent = this.hints.OfType <AllNullsHint>().Any();
 }
        /// <summary>
        /// Creates the object services.
        /// </summary>
        /// <param name="modelSchema">The entity model schema.</param>
        /// <param name="conceptualDataServices">The structural generators for the specified entity model schema</param>
        /// <param name="assemblies">The assemblies that contain data classes for the specified entity model schema.</param>
        /// <returns>Entity model object services.</returns>
        public IEntityModelObjectServices CreateObjectServices(EntityModelSchema modelSchema, IEntityModelConceptualDataServices conceptualDataServices, IEnumerable <Assembly> assemblies)
        {
            ExceptionUtilities.CheckArgumentNotNull(modelSchema, "modelSchema");
            ExceptionUtilities.CheckArgumentNotNull(conceptualDataServices, "conceptualDataServices");
            ExceptionUtilities.CheckArgumentNotNull(assemblies, "assemblies");

            EntityModelObjectServices services = new EntityModelObjectServices(conceptualDataServices);

            this.RegisterDataGeneratorAndAdaptersForComplexTypes(modelSchema, conceptualDataServices, services, assemblies);

            List <EntityType> processedEntityTypes = new List <EntityType>();

            foreach (EntityContainer entityContainer in modelSchema.EntityContainers)
            {
                var graphCreator = new EntityGraphCreator(entityContainer)
                {
                    ConceptualDataServices = conceptualDataServices,
                    ObjectServices         = services,
                    Random = this.Random
                };

                services.RegisterGraphCreator(graphCreator, entityContainer);

                foreach (EntitySet entitySet in entityContainer.EntitySets)
                {
                    string entitySetName = entityContainer.Name + "." + entitySet.Name;
                    foreach (EntityType entityType in modelSchema.EntityTypes.Where(t => t.IsKindOf(entitySet.EntityType) && !t.IsAbstract))
                    {
                        INamedValuesGenerator structuralGenerator = conceptualDataServices.GetStructuralGenerator(entityType.FullName, entitySetName);
                        Type clrType = this.GetClrType(entityType, assemblies);

                        IStructuralDataAdapter adapter = new ObjectStructuralDataAdapter(clrType);

                        IDataGenerator objectDataGen = this.CreateObjectDataGenerator(clrType, adapter, structuralGenerator);

                        EntitySetObjectDataGenerator entitySetObjectDataGen = new EntitySetObjectDataGenerator(entitySetName, objectDataGen);

                        services.RegisterEntitySetDataGenerator(entitySetObjectDataGen, entityType, entitySetName);
                        services.RegisterDataGenerator(objectDataGen, entityType, entitySetName);

                        if (!processedEntityTypes.Contains(entityType))
                        {
                            services.RegisterDataAdapter(adapter, entityType);
                            this.RegisterEnumTypes(entityType, services, assemblies);
                        }

                        processedEntityTypes.Add(entityType);
                    }
                }
            }

            return(services);
        }
        private void RegisterDataGeneratorAndAdaptersForComplexTypes(EntityModelSchema model, IEntityModelConceptualDataServices structuralDataServices, EntityModelObjectServices services, IEnumerable <Assembly> assemblies)
        {
            foreach (ComplexType complexType in model.ComplexTypes)
            {
                INamedValuesGenerator structuralGenerator = structuralDataServices.GetStructuralGenerator(complexType.FullName);
                Type clrType = this.GetClrType(complexType, assemblies);
                IStructuralDataAdapter adapter       = new ObjectStructuralDataAdapter(clrType);
                IDataGenerator         objectDataGen = this.CreateObjectDataGenerator(clrType, adapter, structuralGenerator);

                services.RegisterDataGenerator(objectDataGen, complexType);
                services.RegisterDataAdapter(adapter, complexType);
            }
        }
示例#5
0
 /// <summary>
 /// Registers the member values generator.
 /// </summary>
 /// <param name="dataGenerator">The data generator.</param>
 /// <param name="complexType">The complex type.</param>
 public void RegisterStructuralGenerator(INamedValuesGenerator dataGenerator, ComplexType complexType)
 {
     this.Register <INamedValuesGenerator>(complexType, dataGenerator, this.complexTypeMemberValuesGenerators);
 }
示例#6
0
 /// <summary>
 /// Registers the member values generator.
 /// </summary>
 /// <param name="dataGenerator">The data generator.</param>
 /// <param name="entityType">Type of the entity.</param>
 /// <param name="entitySetName">Name of the entity set.</param>
 public void RegisterStructuralGenerator(INamedValuesGenerator dataGenerator, EntityType entityType, string entitySetName)
 {
     this.Register <INamedValuesGenerator>(entityType, entitySetName, dataGenerator, this.entitySetMemberValuesGenerators);
 }
示例#7
0
 /// <summary>
 /// Tries to get members' values generator.
 /// </summary>
 /// <param name="complexType">Complex type.</param>
 /// <param name="dataGenerator">The data generator.</param>
 /// <returns>True if values generator is found, false otherwise.</returns>
 public bool TryGetStructuralGenerator(ComplexType complexType, out INamedValuesGenerator dataGenerator)
 {
     return(this.complexTypeMemberValuesGenerators.TryGetValue(complexType.FullName, out dataGenerator));
 }
        private IDataGenerator CreateObjectDataGenerator(Type clrType, IStructuralDataAdapter dataManager, INamedValuesGenerator memberValuesGenerator)
        {
            ConstructorInfo ci = typeof(StructuralDataGenerator <>).MakeGenericType(clrType).GetInstanceConstructor(true, new Type[] { typeof(IStructuralDataAdapter), typeof(INamedValuesGenerator) });

            IDataGenerator objectDataGen = (IDataGenerator)ci.Invoke(new object[] { dataManager, memberValuesGenerator });

            return(objectDataGen);
        }