Exemplo n.º 1
0
        public void ShouldNotHaveSameId()
        {
            string sourceName = "{0}_{1}"._Format(MethodBase.GetCurrentMethod().Name, "Source");
            string destName   = "{0}_{1}"._Format(MethodBase.GetCurrentMethod().Name, "Destintation");

            SQLiteDatabase source;
            SQLiteDatabase dest;

            CreateTestDatabases(sourceName, destName, out source, out dest);

            MainObject one = new MainObject();

            one.Name    = "One: ".RandomLetters(8);
            one.Created = DateTime.UtcNow;
            one.Save(source);
            Expect.IsTrue(one.Id > 0);
            3.Times(i =>
            {
                MainObject existing = new MainObject();
                existing.Name       = "Existing in destintation: ".RandomLetters(6);
                existing.Created    = DateTime.UtcNow;
                existing.Save(dest);
            });
            MainObject check = MainObject.OneWhere(c => c.Name == one.Name, source);

            Expect.IsNotNull(check);
            check = MainObject.OneWhere(c => c.Name == one.Name, dest);
            Expect.IsNull(check, "Should have been null");

            string methodName = MethodBase.GetCurrentMethod().Name;

            List <IRepository> repos = new List <IRepository>();

            repos.Add(new DaoRepository(new SQLiteDatabase("BackupRepo_{0}"._Format(methodName), "BackupRepoDb")));
            repos.Add(new ObjectRepository("ObjectRepo_{0}"._Format(methodName)));

            foreach (IRepository repo in repos)
            {
                DaoBackup backup = new DaoBackup(typeof(MainObject).Assembly, source, repo);
                backup.Backup();
                HashSet <OldToNewIdMapping> wasIs = backup.Restore(dest);
                OutputWasIs(wasIs);
                check = MainObject.OneWhere(c => c.Uuid == one.Uuid, dest);
                Expect.IsNotNull(check);
                Expect.IsFalse(one.Id == check.Id);
                Expect.IsFalse(one.Id.Equals(check.Id));
                OutLineFormat(check.PropertiesToString());
            }
        }
Exemplo n.º 2
0
        public void ShouldBeAbleToRestore()
        {
            SQLiteDatabase toBackup = GetTestDatabase(MethodBase.GetCurrentMethod().Name);

            toBackup.MaxConnections = 500;
            FillDatabaseWithTestData(toBackup);

            MainObjectCollection      main      = MainObject.LoadAll(toBackup);
            SecondaryObjectCollection secondary = SecondaryObject.LoadAll(toBackup);
            TernaryObjectCollection   ternary   = TernaryObject.LoadAll(toBackup);

            List <IRepository> repos = new List <IRepository>();

            repos.Add(new DaoRepository(new SQLiteDatabase("BackupRepo_{0}"._Format(MethodBase.GetCurrentMethod().Name), "BackupRepoDb")));
            repos.Add(new ObjectRepository("ObjectRepo_{0}"._Format(MethodBase.GetCurrentMethod().Name)));

            foreach (IRepository repo in repos)
            {
                DaoBackup backup = new DaoBackup(typeof(MainObject).Assembly, toBackup, repo);
                backup.Backup();
                SQLiteDatabase restored = GetTestDatabase("{0}_Restored_For_{1}"._Format(MethodBase.GetCurrentMethod().Name, repo.GetType().Name));
                //MsSqlDatabase restored = new MsSqlDatabase("192.168.0.59", "DaoRef", new MsSqlCredentials { UserName = "******", Password = "******" });
                HashSet <OldToNewIdMapping> restoreInfo = backup.Restore(restored);
                List <string> keys = restoreInfo.Select(i => i.Uuid).ToList();
                main.Each(new { Uuids = keys }, (ctx, m) =>
                {
                    Expect.IsTrue(ctx.Uuids.Contains(m.Uuid));
                });
                secondary.Each(new { Uuids = keys }, (ctx, s) =>
                {
                    Expect.IsTrue(ctx.Uuids.Contains(s.Uuid));
                });
                ternary.Each(new { Uuids = keys }, (ctx, t) =>
                {
                    Expect.IsTrue(ctx.Uuids.Contains(t.Uuid));
                });
                restoreInfo.Each(ri =>
                {
                    OutLineFormat(ri.PropertiesToString(), ConsoleColor.DarkYellow);
                });
                OutLineFormat("Repository of type {0} passed restore test", ConsoleColor.Green, repo.GetType().Name);
            }
        }
Exemplo n.º 3
0
        public void ChildCollectionsShouldRestoreProperly()
        {
            string sourceName = "{0}_{1}"._Format(MethodBase.GetCurrentMethod().Name, "Source");
            string destName   = "{0}_{1}"._Format(MethodBase.GetCurrentMethod().Name, "Destintation");

            Dao.GlobalInitializer = (dao) =>
            {
                dao.Property("Created", DateTime.UtcNow, false);
            };
            Dao.BeforeCommitAny += (db, dao) =>
            {
                dao.Property("Modified", DateTime.UtcNow, false);
            };

            SQLiteDatabase source;
            SQLiteDatabase dest;

            CreateTestDatabases(sourceName, destName, out source, out dest);

            MainObject main = new MainObject();

            main.Name = "The Main Parent";
            main.Save(source);
            SecondaryObject secondary        = main.SecondaryObjectsByMainId.AddNew();
            string          secondaryOneName = 8.RandomLetters();

            secondary.Name = secondaryOneName;
            SecondaryObject secondary2       = main.SecondaryObjectsByMainId.AddNew();
            string          secondaryTwoName = 6.RandomLetters();

            secondary2.Name = secondaryTwoName;
            main.Save(source);
            Expect.IsNotNullOrEmpty(main.Uuid);
            TernaryObject ternary = secondary2.TernaryObjects.AddNew();

            ternary.Name = 4.RandomLetters();
            ternary.Save(source);
            secondary2.Save(source);
            ternary = TernaryObject.OneWhere(c => c.Uuid == ternary.Uuid, source);
            Expect.AreEqual(1, ternary.SecondaryObjects.Count);
            string     uuid  = main.Uuid;
            MainObject check = MainObject.OneWhere(c => c.Id == main.Id, source);

            Expect.IsTrue(check.SecondaryObjectsByMainId.Count == 2);

            string             methodName = MethodBase.GetCurrentMethod().Name;
            List <IRepository> repos      = new List <IRepository>();

            repos.Add(new DaoRepository(new SQLiteDatabase("BackupRepo_{0}"._Format(methodName), "BackupRepoDb")));
            //repos.Add(new ObjectRepository("ObjectRepo_{0}"._Format(methodName)));

            foreach (IRepository repo in repos)
            {
                DaoBackup backup = new DaoBackup(typeof(MainObject).Assembly, source, repo);
                backup.Backup();
                HashSet <OldToNewIdMapping> wasIs = backup.Restore(dest);
                OutputWasIs(wasIs);
                MainObject toValidate = MainObject.OneWhere(c => c.Uuid == uuid, dest);
                Expect.IsTrue(toValidate.SecondaryObjectsByMainId.Count == 2);
                List <string> names = toValidate.SecondaryObjectsByMainId.Select(s => s.Name).ToList();
                Expect.IsTrue(names.Contains(secondaryOneName));
                Expect.IsTrue(names.Contains(secondaryTwoName));
                SecondaryObject secondary2Check = SecondaryObject.OneWhere(c => c.Uuid == secondary2.Uuid, dest);
                Expect.IsNotNull(secondary2Check);
                Expect.AreEqual(1, secondary2Check.TernaryObjects.Count);
                Expect.IsTrue(secondary2Check.TernaryObjects[0].Name.Equals(ternary.Name));
                TernaryObject ternaryCheck = TernaryObject.OneWhere(c => c.Uuid == secondary2.TernaryObjects[0].Uuid, dest);
                Expect.IsTrue(ternaryCheck.SecondaryObjects.Count == 1);
            }
        }