示例#1
0
        public void AddColumnPrescriptions()
        {
            var fileName = Temporary.GetTempFilePath();
            var project  = CreateProject();

            ValueFactoryManager.Initialize();

            var i = 0;

            foreach (var tableDescription in project.Descriptor.TableDescriptions)
            {
                var tablePrescription = new TablePrescription(tableDescription);

                foreach (var columnDescription in tableDescription.ColumnDescriptions)
                {
                    if (columnDescription.Identity != null || !columnDescription.IsWritable())
                    {
                        continue;
                    }

                    var type = columnDescription.UserType switch
                    {
                        "sql_variant" => typeof(int),
                        _ => SqlTypeUtility.GetDataType(columnDescription.UserType, columnDescription.MaxLength),
                    };

                    var factory = ValueFactoryManager.ValueFactoryInfos.FilterByType(type).FirstOrDefault();
                    Assert.NotNull(factory);
                    var configuration            = factory.Configurator.CreateConfiguration();
                    var valueFactoryPrescription = new ValueFactoryPrescription(factory.Name + i++, factory.Name, configuration);
                    project.Prescriptor.AddValueFactory(valueFactoryPrescription);

                    var columnPrescription = new ColumnPrescription(columnDescription, valueFactoryPrescription, null);
                    tablePrescription.AddColumn(columnPrescription);
                }

                project.Prescriptor.AddTable(tablePrescription);
            }

            ProjectManager.SaveToFile(project, fileName);

            Output.WriteLine(File.ReadAllText(fileName));
            var project2 = ProjectManager.LoadFromFile(fileName);

            IoAssert.AsExpected(project2);
        }
示例#2
0
        public void AddAllValueFactories()
        {
            var fileName = Temporary.GetTempFilePath();
            var project  = CreateProject();

            ValueFactoryManager.Initialize();

            foreach (var factory in ValueFactoryManager.ValueFactoryInfos)
            {
                var configuration            = factory.Configurator.CreateConfiguration();
                var valueFactoryPrescription = new ValueFactoryPrescription("default-" + factory.Name, factory.Name, configuration);
                project.Prescriptor.AddValueFactory(valueFactoryPrescription);
            }

            ProjectManager.SaveToFile(project, fileName);

            Output.WriteLine(File.ReadAllText(fileName));
            var project2 = ProjectManager.LoadFromFile(fileName);

            IoAssert.AsExpected(project2);
        }
示例#3
0
 private static void AsExpected(ValueFactoryPrescription valueFactoryPrescription)
 {
     Assert.NotNull(valueFactoryPrescription.Name);
     Assert.NotNull(valueFactoryPrescription.Factory);
     AsExpected(valueFactoryPrescription.Configuration);
 }