예제 #1
0
        public void TearDown()
        {
            if (dataLayer != null)
            {
                dataLayer.Dispose();
            }
//            if (dataSet != null) {
//                dataSet.Dispose();
//            }
            ReflectionHelper.Reset();
        }
예제 #2
0
        static void Main(string[] args)
        {
            SafePostgreSqlConnectionProvider.Register();
            SafePostgreSqlConnectionProvider dataStore = new SafePostgreSqlConnectionProvider(
                "user id=postgres;password=admin;server=donchakDBFarm;database=XpoUnitTests;port=5434",
                AutoCreateOption.DatabaseAndSchema
                );
            IDataLayer dal = new SimpleDataLayer(dataStore);
            int        id  = CreateData(dal);

            Console.WriteLine("restart the database, and press any key to continue ..");
            Console.ReadKey();
            new Session(dal).GetObjectByKey <Person>(id);
            ((IDisposable)dataStore).Dispose();
            dal.Dispose();
            Console.WriteLine("done\npress any key to exit ..");
            Console.ReadKey();
        }
        public void AutoScript()
        {
            // Создание скрипта
            const string path = "autoscript.txt";
            StreamWriter script = new StreamWriter(path);
            ReflectionDictionary dictionary = new ReflectionDictionary();
            XPDictionaryInformer.Register(dictionary);
            SimpleDataLayer dataLayer = new SimpleDataLayer(dictionary, new OracleConnectionProviderEx(
                ODPConnectionProvider.CreateConnection(Properties.Settings.Default.ConnectionAdmin), AutoCreateOption.SchemaOnly, script, UpdateSchemaOptions.Default));
            dataLayer.UpdateSchema(false, new Type[] {
                typeof(AutoIdClass), typeof(StringIdClass), typeof(ComplexIdClass), typeof(NoIdClass),
                typeof(NotNullClass), typeof(ReadOnlyClass),
                typeof(ConsistentPeriodClass), typeof(ConsistentPeriodClass2), typeof(ContinuousPeriodClass), typeof(HierarchyClass),
                typeof(SimpleConstraintClass), typeof(ConstraintClass), typeof(CategoryClass), typeof(SecurityClass),
                typeof(UniqueBaseClass), typeof(UniqueClass),
                typeof(DevExpress.Xpo.XPObjectType)
            }.Select(c => dictionary.GetClassInfo(c)).ToArray());
            script.Close();

            // Проверка непустого содержания файла
            FileStream file = new FileStream(path, FileMode.Open);
            Assert.IsFalse(file.Length == 0, "File of autoscript is empty.");
            file.Close();

            // Проверка валидности скрипта
            Connection.ExecuteFile(path);
            dataLayer.Dispose();
        }