Esempio n. 1
0
        public void ShouldBeAbleToRetrieveWithDynamicReturn()
        {
            HashSet <Database> dbs = DataTools.Setup();

            dbs.Each(db =>
            {
                try
                {
                    string name        = "Name_".RandomLetters(8);
                    TestTable instance = new TestTable();
                    instance.Name      = name;
                    instance.Save(db);
                    TestTable retrieved = RetrieveByNameAndValidate(db, instance);

                    SqlStringBuilder sql = db.Sql().Select(nameof(TestTable)).Where(new { Name = name });
                    dynamic queried      = sql.ExecuteDynamicReader(db).SingleOrDefault();
                    OutLineFormat("Result type is ({0})", queried.GetType().Name, ConsoleColor.Cyan);

                    Expect.AreEqual(retrieved.Id, (long)queried.Id);
                    Expect.AreEqual(retrieved.Uuid, queried.Uuid);
                    Expect.AreEqual(retrieved.Name, queried.Name);

                    Pass($"{db.GetType().Name} passed");
                }
                catch (Exception ex)
                {
                    Error($"{db.GetType().Name}: failed: {ex.Message}", ex);
                }
            });
            DataTools.Cleanup(dbs);
        }
        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");
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void ShouldBeAbleToUpdateWithDynamicParameters()
        {
            HashSet <Database> dbs = DataTools.Setup();

            dbs.Each(db =>
            {
                try
                {
                    string name        = "Name_".RandomLetters(8);
                    TestTable instance = new TestTable();
                    instance.Name      = name;
                    instance.Save(db);
                    TestTable retrieved = RetrieveByNameAndValidate(db, instance);

                    string updatedName    = "Updated+".RandomLetters(5);
                    SqlStringBuilder sql2 = db.Sql().Update(nameof(TestTable), new { Name = updatedName }).Where(new { Id = retrieved.Id });
                    db.ExecuteSql(sql2);

                    SqlStringBuilder sql3 = db.Sql();
                    sql3.Select(nameof(TestTable), "*").Where(new { Name = updatedName });
                    TestTable retrieved2 = db.ExecuteReader <TestTable>(sql3).SingleOrDefault();
                    Expect.IsNotNull(retrieved2);
                    Expect.AreEqual(instance.Id, retrieved2.Id);
                    Expect.AreEqual(instance.Uuid, retrieved2.Uuid);
                    Expect.AreEqual(instance.Cuid, retrieved2.Cuid);
                    Expect.AreEqual(updatedName, retrieved2.Name);

                    Pass($"{db.GetType().Name} passed");
                }
                catch (Exception ex)
                {
                    Error($"{db.GetType().Name}: failed: {ex.Message}", ex);
                }
            });
            DataTools.Cleanup(dbs);
        }
Esempio n. 5
0
 public void Setup()
 {
     _testDatabases = DataTools.Setup();
 }
 public void SetupTests()
 {
     OutLine("Setting up tests...", ConsoleColor.Green);
     _testDatabases = DataTools.Setup();
 }