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());
        }
        public void AsyncQueryManualTest()
        {
            _testDatabases = DataTools.Setup();
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod()?.Name;
            string one        = 4.RandomLetters();
            string two        = 4.RandomLetters();

            foreach (Database db in _testDatabases)
            {
                Counter connectionCounter = Stats.Count("ConnectionCount", GetConnectionCount);
                ulong   initialCount      = connectionCounter.Count;
                foreach (IDbConnectionManager conMan in new IDbConnectionManager[]
                {
                    new PerThreadDbConnectionManager(db),
                    new DefaultDbConnectionManager(db)
                }
                         )
                {
                    db.ConnectionManager           = conMan;
                    conMan.StateChangeEventHandler = (o, sce) => Message.PrintLine("***** {0} Current state {1}, Original state {2} *****", ConsoleColor.DarkYellow, o.GetType().Name, sce.CurrentState.ToString(), sce.OriginalState.ToString());
                    db.IsNotNull();

                    Message.PrintLine("{0} Connection Count before write {1}", ConsoleColor.Yellow, db.GetType().Name, connectionCounter.Count);

                    List <TestTable> entries = new List <TestTable>();
                    string           name    = $"{nameof(AsyncQueryManualTest)}.CreateTestData";
                    Timer            timer   = Stats.Start(name);
                    100.Times((i) => entries.Add(DataTools.CreateTestTable("{0}_{1}"._Format(one, 4.RandomLetters()), db)));
                    timer = Stats.End(name);
                    Message.PrintLine("{0} Writes took {1}", ConsoleColor.Cyan, db.GetType().Name, timer.Duration);

                    Message.PrintLine("Count after write {0}", ConsoleColor.Yellow, connectionCounter.Count);

                    Console.WriteLine(connectionCounter.Count);

                    Message.PrintLine("Count before read {0}", ConsoleColor.Yellow, connectionCounter.Count);
                    name  = $"{nameof(AsyncQueryManualTest)}.ReadTestData";
                    timer = Stats.Start(name);
                    Parallel.ForEach(entries, (tt) =>
                    {
                        TestTable val = TestTable.FirstOneWhere(c => c.Name == tt.Name, db);
                        Message.PrintLine("{0}", ConsoleColor.Cyan, val.Name);
                    });
                    timer = Stats.End(name);
                    Message.PrintLine("Parallel reads took {0}", ConsoleColor.Cyan, timer.Duration);
                    Message.PrintLine("Count after read {0}", ConsoleColor.Yellow, connectionCounter.Count);
                    Console.WriteLine("{0}: {1}", db.GetType().Name, connectionCounter.Count);

                    Stats.Start("Deleting");
                    TestTable.LoadAll(db).ToList().ForEach(tt => tt.Delete(db));
                    Message.PrintLine("{0}: Deletes took {1} milliseconds", ConsoleColor.Yellow, db.GetType().Name, Stats.End("Deleting").Value);
                    (connectionCounter.Count <= initialCount + ((ulong)(conMan.MaxConnections * 2))).IsTrue("Connection count higher than expected");
                }
            }
        }
Beispiel #3
0
 private static void ClearTestTable(Database db)
 {
     TestTable.LoadAll(db).Delete(db);
 }