private static SecondaryObject CreateFromFilter(IQueryFilter filter, Database database = null) { Database db = database ?? Db.For <SecondaryObject>(); var dao = new SecondaryObject(); filter.Parameters.Each(p => { dao.Property(p.ColumnName, p.Value); }); dao.Save(db); return(dao); }
public ActionResult Update(Bam.Net.Data.Repositories.Tests.SecondaryObject dao) { try { dao.Save(); return(Json(new { Success = true, Message = "", Dao = dao.ToJsonSafe() })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
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); } }
public ActionResult Delete(long id) { try { string msg = ""; Bam.Net.Data.Repositories.Tests.SecondaryObject dao = Bam.Net.Data.Repositories.Tests.SecondaryObject.OneWhere(c => c.KeyColumn == id); if (dao != null) { dao.Delete(); } else { msg = string.Format("The specified id ({0}) was not found in the table (SecondaryObject)", id); } return(Json(new { Success = true, Message = msg, Dao = "" })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
private static void FillDatabaseWithTestData(SQLiteDatabase toBackup) { 3.Times(i => { OutLineFormat("Creating main...", ConsoleColor.DarkCyan); MainObject m = new MainObject(); m.Created = DateTime.UtcNow; m.Name = "MainObject: {0}"._Format(i); m.Save(toBackup); OutLine(m.PropertiesToString(), ConsoleColor.Blue); OutLineFormat("\tAdding secondary...", ConsoleColor.Yellow); RandomNumber.Between(1, 3).Times(n => { SecondaryObject s = m.SecondaryObjectsByMainId.AddNew(); s.Created = DateTime.UtcNow; s.Name = "\tSecondaryObject: {0}"._Format(n + 1); }); m.Save(toBackup); m.SecondaryObjectsByMainId.Each(s => { OutLineFormat("\t\tAdding ternary...", ConsoleColor.Blue); OutLine(s.PropertiesToString(), ConsoleColor.Cyan); RandomNumber.Between(1, 3).Times(n => { TernaryObject t = s.TernaryObjects.AddNew(); t.Created = DateTime.UtcNow; t.Name = "\t\tTernaryObject: {0}"._Format(n + 1); }); s.Save(toBackup); s.TernaryObjects.Each(t => { OutLineFormat(t.PropertiesToString(), ConsoleColor.DarkGray); }); }); }); }
private static void SetupTestData(SQLiteDatabase testDatabase) { 10.Times(i => { MainObject o = new MainObject(); o.Name = 8.RandomLetters().Plus("::Main_Object {0}", i); o.Created = DateTime.UtcNow; o.Save(testDatabase); }); 10.Times(i => { SecondaryObject o = new SecondaryObject(); o.Name = 4.RandomLetters().Plus("::Secondary_object {0}", i); o.Created = DateTime.UtcNow; o.Save(testDatabase); }); 10.Times(i => { TernaryObject o = new TernaryObject(); o.Name = 3.RandomLetters().Plus("::Ternary_object ", i); o.Created = DateTime.UtcNow; o.Save(testDatabase); }); }
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); } }
public ActionResult Create(Bam.Net.Data.Repositories.Tests.SecondaryObject dao) { return(Update(dao)); }