private static TernaryObject CreateFromFilter(IQueryFilter filter, Database database = null) { Database db = database ?? Db.For <TernaryObject>(); var dao = new TernaryObject(); filter.Parameters.Each(p => { dao.Property(p.ColumnName, p.Value); }); dao.Save(db); return(dao); }
public ActionResult Update(Bam.Net.Data.Repositories.Tests.TernaryObject dao) { try { dao.Save(); return(Json(new { Success = true, Message = "", Dao = dao.ToJsonSafe() })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
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); } }