Beispiel #1
0
 public static void ExecuteNonQuery(string databaseName, string sql)
 {
     using (Database database = new Database())
     {
         if (databaseName != null)
         {
             database.Use(databaseName);
         }
         DbCommand command = database.CreateCommand(sql);
         database.ExecuteNonQuery(command);
         database.Commit();
     }
 }
        public void Setup()
        {
            if (DeleteSection == null && CreateSection == null)
            {
                return;
            }

            using (Database database = new Database())
            {
                if (DeleteSection != null && DeleteSection.HasTable())
                {
                    DataSet dataSet = GetDataSet(Section.SectionType.DataToDelete);
                    database.Delete(dataSet, DeleteSection);
                }

                if (CreateSection != null && CreateSection.HasTable())
                {
                    UpdateColumnTypes(database, Section.SectionType.DataToCreate);
                    DataSet dataSet = GetDataSet(Section.SectionType.DataToCreate);
                    database.Insert(dataSet, CreateSection);
                }
                database.Commit();
            }
        }
Beispiel #3
0
        public void Setup()
        {
            if (DeleteSection == null && CreateSection == null)
            {
                return;
            }

            using (Database database = new Database())
            {
                if (DeleteSection != null && DeleteSection.HasTable())
                {
                    DataSet dataSet = GetDataSet(Section.SectionType.DataToDelete);
                    database.Delete(dataSet, DeleteSection);
                }

                if (CreateSection != null && CreateSection.HasTable())
                {
                    UpdateColumnTypes(database, Section.SectionType.DataToCreate);
                    DataSet dataSet = GetDataSet(Section.SectionType.DataToCreate);
                    database.Insert(dataSet, CreateSection);
                }
                database.Commit();
            }
        }
 private void UpdateDatabase(int expect)
 {
     using (Database database = new Database())
     {
         database.ExecuteNonQuery("update TypesTable set int1 = " + expect);
         database.Commit();
     }
 }
Beispiel #5
0
        public void ValidateメソッドはSetupメソッドの暗黙呼び出しを行わないこと()
        {
            // setup
            Loggi.DebugEnabled = true;
            using (Database database = new Database())
            {
                database.ExecuteNonQuery("delete from TypesTable");
                database.Commit();
            }
            FixtureBook fixtureBook = new FixtureBook();

            // when
            Dictionary<string, string> obj = new Dictionary<string, string>();
            obj["Id"] = "1";
            fixtureBook.Validate(obj);

            // then
            using (Database database = new Database())
            {
                Assert.AreEqual(0, database.ExecuteQuery("select * from TypesTable").Rows.Count);
            }

            // when
            fixtureBook.Setup();

            // then
            using (Database database = new Database())
            {
                Assert.AreEqual(1, database.ExecuteQuery("select * from TypesTable").Rows.Count);
            }
        }
Beispiel #6
0
        public void ValidateStorageの呼び出し時にはSetupメソッドの暗黙呼び出しはされないこと()
        {
            // setup
            Loggi.DebugEnabled = true;
            using (Database database = new Database())
            {
                database.ExecuteNonQuery("delete from TypesTable");
                database.Commit();
            }
            FixtureBook fixtureBook = new FixtureBook();

            // when
            try
            {
                fixtureBook.ValidateStorage();
                throw new Exception("ここにはこない");
            }
            catch (AssertFailedException e)
            {
                Console.WriteLine(e);
            }
        }
        private void 検索列指定をしてデータベーステーブルの状態が予想結果と異なることをチェックできる_SQLServer(string column, object value, string valueAsText)
        {
            // setup
            fixtureBook.Setup();
            using (Database database = new Database())
            {
                DbCommand command = database.CreateCommand("update TypesTable set " + column + "=@" + column + " where Id=2");
                database.AddParameter(command, column, null, value);
                database.ExecuteNonQuery(command);
                database.Commit();
            }

            try
            {
                // when
                fixtureBook.ValidateStorage();
                Assert.Fail("ここにはこない");
            }
            catch (Exception e)
            {
                // then
                string message = e.Message;
                Console.WriteLine(message);
                Assert.IsTrue(message.IndexOf(column) > -1);
                Assert.IsTrue(message.IndexOf("<" + valueAsText + ">") > -1);
            }
        }
        public void 検索列指定をせずにデータベーステーブルの状態が予想結果と異なることをチェックできる_SQLServer()
        {
            // setup
            Loggi.DebugEnabled = true;
            fixtureBook.Setup();
            using (Database database = new Database())
            {
                database.ExecuteNonQuery("update TypesTable set bigint1=2 where Id=2");
                database.Commit();
            }

            try
            {
                // when
                fixtureBook.ValidateStorage();
                Assert.Fail("ここにはこない");
            }
            catch (Exception e)
            {
                // then
                string message = e.Message;
                Console.WriteLine(message);
                Assert.IsTrue(Regex.IsMatch(message, ".*TypesTable.*TypesTable.*"));
                Assert.IsTrue(message.IndexOf("*") > -1);
            }
        }
        public void 指定した検索列が存在しない場合はエラー_SQLServer()
        {
            // setup
            Loggi.DebugEnabled = true;
            fixtureBook.Setup();
            using (Database database = new Database())
            {
                database.ExecuteNonQuery("delete from TypesTable");
                database.Commit();
            }

            try
            {
                // when
                fixtureBook.ValidateStorage();
                Assert.Fail("ここにはこない");
            }
            catch (Exception e)
            {
                // then
                string message = e.Message;
                Console.WriteLine(message);
                Assert.IsTrue(Regex.IsMatch(message, ".*TypesTable.*TypesTable.*"));
                Assert.IsTrue(message.IndexOf("*") == -1);
            }
        }
        public void 削除済み指定のデータが存在しない場合は正常終了となるその2_Oracle()
        {
            // setup
            Loggi.DebugEnabled = true;
            fixtureBook.Setup();
            using (Database database = new Database())
            {
                database.Use("Oracle");
                database.ExecuteNonQuery("delete from TYPES_TABLE where ID = 2");
                database.Commit();
            }

            // expect
            fixtureBook.ValidateStorage();
        }