Beispiel #1
0
        void CreateDbWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string xmlPath             = ResourcesHelper.GetXmlDbFileFromResource();
            string xmlConnectionString = string.Format("XpoProvider=XmlDataSet;data source={0};read only = true", xmlPath);

            using (UnitOfWork xmlSession = new UnitOfWork()) {
                xmlSession.ConnectionString = xmlConnectionString;
                xmlSession.Connect();
                UnitOfWork dbSession = OpenDb(false, false);
                if (dbSession == null)
                {
                    unableToCreateDb = true;
                }
                else
                {
                    IDGenerator.DisableGeneration(dbSession);
                    SessionHelper.CopySession(xmlSession, dbSession,
                                              xmlSession.Dictionary.CollectClassInfos(Assembly.GetAssembly(typeof(VideoRentBaseObject))), createInitialDbDialog.CreateDbWorker, 90);
                    SessionHelper.CommitInBackground(dbSession, exceptionProcesser, createInitialDbDialog.CreateDbWorker, 100);
                    IDGenerator.EnableGeneration();
                    CorrectCustomersBirthDate(dbSession);
                    XpoDefault.Session = dbSession;
                }
            }
            File.Delete(xmlPath);
        }
Beispiel #2
0
        public void CopySession()
        {
            Postal.CountriesAsString = "ru, us";
            Session.CommitChanges();
            IDGenerator.DisableGeneration(copy);
            SessionHelper.CopySession(Session, copy, Session.Dictionary.CollectClassInfos(typeof(VideoRentBaseObject).Assembly), null, 0);
            copy.CommitChanges();
            IDGenerator.EnableGeneration();
            var copyPostal = copy.FindObject <Movie>(CriteriaOperator.Parse("Title = ?", "Postal"));

            Assert.AreEqual("Postal", copyPostal.Title);
            Assert.AreEqual("ru, us", copyPostal.CountriesAsString);
            Assert.IsNotNull(MovieCategory.GetDefaultCategory(copy));
            Assert.AreEqual(MovieCategory.GetDefaultCategory(copy), copyPostal.Category);
            var copyAnton = copy.FindObject <Customer>(CriteriaOperator.Parse("FirstName = ? and LastName = ?", "Anton", "Abanin"));

            Assert.AreEqual(3, copyAnton.CustomerId);
        }