Beispiel #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);
        }
Beispiel #2
0
        public void CreateTest()
        {
            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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public void Setup()
 {
     _testDatabases = DataTools.Setup();
 }
Beispiel #5
0
 public void SetupTests()
 {
     OutLine("Setting up tests...", ConsoleColor.Green);
     _testDatabases = DataTools.Setup();
 }