Ejemplo n.º 1
0
        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));
            });
        }
Ejemplo n.º 2
0
        public void ChildCollectionsFunctionCorrectly()
        {
            SQLiteDatabase db = new SQLiteDatabase(nameof(XrefListTest));

            db.TryEnsureSchema <TestTable>();
            TestTable.LoadAll(db).Delete();
            TestFkTable.LoadAll(db).Delete();

            TestTable testTable = new TestTable {
                Name = "TestTable_".RandomLetters(4)
            };
            TestFkTable fkTable = new TestFkTable {
                Name = "TestFkTable_".RandomLetters(6)
            };

            testTable.Save(db);
            testTable.TestFkTablesByTestTableId.Add(fkTable);

            fkTable.Id.ShouldBeNull();
            testTable.Save(db);
            fkTable.Id.ShouldNotBeNull();

            TestTable retrieved = TestTable.GetById(testTable.Id, db);

            Expect.AreEqual(1, retrieved.TestFkTablesByTestTableId.Count);
            Expect.AreEqual(fkTable.ToJsonSafe().ToJson(), retrieved.TestFkTablesByTestTableId[0].ToJsonSafe().ToJson());
        }