public void ChildListTest() { Expect.IsTrue(_testDatabases.Count > 0); string methodName = MethodBase.GetCurrentMethod().Name; _testDatabases.Each(db => { OutLineFormat("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name); TestTable parent = new TestTable(db); parent.Name = "Parent Test"; parent.Save(db); TestFkTable child = parent.TestFkTablesByTestTableId.AddNew(); child.Name = "Child ({0})"._Format(6.RandomLetters()); parent.Save(db); TestTable retrieved = TestTable.OneWhere(c => c.Id == parent.Id, db); Expect.AreEqual(1, retrieved.TestFkTablesByTestTableId.Count); Expect.AreEqual(child.Name, retrieved.TestFkTablesByTestTableId[0].Name); TestFkTable child2 = new TestFkTable(); child2.Name = "Child 2 ({0})"._Format(6.RandomLetters()); parent.TestFkTablesByTestTableId.Add(child2); parent.Save(db); retrieved = TestTable.OneWhere(c => c.Id == parent.Id, db); Expect.AreEqual(2, retrieved.TestFkTablesByTestTableId.Count); List <string> names = retrieved.TestFkTablesByTestTableId.Select(c => c.Name).ToList(); Expect.IsTrue(names.Contains(child.Name)); Expect.IsTrue(names.Contains(child2.Name)); }); }
public void DeleteTest() { Expect.IsTrue(_testDatabases.Count > 0); string methodName = MethodBase.GetCurrentMethod().Name; _testDatabases.Each(db => { OutLineFormat("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name); string name = 6.RandomLetters(); TestTable test = new TestTable(db); test.Name = name; test.Save(db); TestTable toDelete = TestTable.OneWhere(t => t.Id == test.Id, db); Expect.IsNotNull(toDelete); toDelete.Delete(db); TestTable shouldBeNull = TestTable.OneWhere(t => t.Id == test.Id, db); Expect.IsNull(shouldBeNull); }); }
public void SqlStringBuilderCreateTest() { HashSet <Database> dbs = DataTools.Setup(); dbs.Each(db => { try { ObjectIdentifier id = new ObjectIdentifier(); string name = "Name_".RandomLetters(10); SqlStringBuilder sql = db.Sql().Insert(nameof(TestTable), new { Name = name, Uuid = id.Uuid, Cuid = id.Cuid }); db.ExecuteSql(sql); RetrieveByNameAndValidate(db, TestTable.OneWhere(c => c.Name == name, db)); Pass($"{db.GetType().Name} passed"); } catch (Exception ex) { Error($"{db.GetType().Name}: failed: {ex.Message}", ex); } }); DataTools.Cleanup(dbs); }
public void UpdateTest() { Expect.IsTrue(_testDatabases.Count > 0); string methodName = MethodBase.GetCurrentMethod().Name; _testDatabases.Each(db => { OutLineFormat("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name); string name = 6.RandomLetters(); TestTable test = new TestTable(db); test.Name = name; test.Save(db); TestTable toUpdate = TestTable.OneWhere(t => t.Name == name, db); string changeTo = 8.RandomLetters(); toUpdate.Name = changeTo; toUpdate.Save(db); TestTable check = TestTable.OneWhere(t => t.Name == changeTo, db); Expect.AreEqual(test.Id, check.Id); Expect.AreEqual(toUpdate.Id, check.Id); Expect.AreEqual(changeTo, check.Name); }); }
public void RetrieveTest() { Expect.IsTrue(_testDatabases.Count > 0); string methodName = MethodBase.GetCurrentMethod().Name; _testDatabases.Each(db => { OutLineFormat("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name); string name = 6.RandomLetters(); TestTable test = new TestTable(db); test.Name = name; test.Save(db); TestTable check = TestTable.OneWhere(t => t.Name == name, db); Expect.IsNotNull(check); Expect.AreEqual(test.Id, check.Id); Expect.AreEqual(name, check.Name); TestTable check2 = TestTable.OneWhere(t => t.Id == test.Id, db); Expect.IsNotNull(check2); Expect.AreEqual(test.Id, check2.Id); Expect.AreEqual(name, check2.Name); }); }