Ejemplo n.º 1
0
        public void Insert_And_Delete_Test()
        {
            // Arrange
            IDBConnector pConnector = new MySqlConnector();

            pConnector.DoOpen();

            testtable sTable = new testtable();

            sTable.intvalue    = 1;
            sTable.stringvalue = "asdf";



            // Act
            // Insert
            pConnector.PopCommand($"INSERT INTO {pConnector.ConvertQueryString(sTable)}").ExecuteNonQuery();


            // Assert
            DataTable pTable          = new DataTable();
            var       pCommand_Select = pConnector.PopCommand($"SELECT * FROM {sTable.GetTableName()} WHERE {nameof(testtable.stringvalue)} = '{sTable.stringvalue}';");

            using (MySqlDataAdapter adpt = new MySqlDataAdapter())
            {
                adpt.SelectCommand = (MySqlCommand)pCommand_Select;
                adpt.Fill(pTable);
            }
            Assert.IsTrue(pTable.Rows.Count > 0);



            // Act
            // Delete
            pConnector.PopCommand($"DELETE FROM {sTable.GetTableName()} WHERE {nameof(testtable.stringvalue)} = '{sTable.stringvalue}'; ").ExecuteNonQuery();
            pTable.Clear();


            // Assert
            pCommand_Select = pConnector.PopCommand($"SELECT * FROM {sTable.GetTableName()} WHERE {nameof(testtable.stringvalue)} = '{sTable.stringvalue}';");
            using (MySqlDataAdapter adpt = new MySqlDataAdapter())
            {
                adpt.SelectCommand = (MySqlCommand)pCommand_Select;
                adpt.Fill(pTable);
            }
            pCommand_Select.Dispose();

            Assert.IsTrue(pTable.Rows.Count == 0);


            pConnector.DoClose();
        }