public void OneTimeTearDown()
 {
     using (ConnStringOnConfiguringContext context = new ConnStringOnConfiguringContext())
         context.Database.EnsureDeleted();
     using (KeyConventionsContext context = new KeyConventionsContext())
         context.Database.EnsureDeleted();
     using (WorldContext context = new WorldContext())
         context.Database.EnsureDeleted();
 }
        public void CharsetTest()
        {
            using (ConnStringOnConfiguringContext context = new ConnStringOnConfiguringContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                using (MySqlConnection conn = (MySqlConnection)context.Database.GetDbConnection())
                {
                    conn.Open();
                    MySqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SHOW CREATE TABLE `TestCharsetDA`";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        string createTable = reader.GetString(1);
                        createTable = Regex.Replace(createTable, @"\t|\n|\r", string.Empty);
                        string txt = "CREATE TABLE `testcharsetda` (  `TestCharsetDAId` varbinary(255) NOT NULL,  PRIMARY KEY (`TestCharsetDAId`)) ENGINE=InnoDB DEFAULT CHARSET=ascii";
                        StringAssert.AreEqualIgnoringCase(txt, createTable);
                    }

                    cmd.CommandText = "SHOW CREATE TABLE `TestCharsetFA`";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        string createTable = reader.GetString(1);
                        string txt         = string.Empty;
                        createTable = Regex.Replace(createTable, @"\t|\n|\r", string.Empty);

                        //Adding "COLLATION" to the string validation at table creation (this happens since MySql 8.0.5 Server)
                        if (createTable.Contains("COLLATE latin7_general_ci"))
                        {
                            txt = "CREATE TABLE `testcharsetfa` (  `TestCharsetFAId` varchar(255) CHARACTER SET latin7 COLLATE latin7_general_ci NOT NULL,  PRIMARY KEY (`TestCharsetFAId`)) ENGINE=InnoDB DEFAULT CHARSET=utf16";
                            StringAssert.AreEqualIgnoringCase(txt, createTable);
                        }
                        else
                        {
                            txt = "CREATE TABLE `testcharsetfa` (  `TestCharsetFAId` varchar(255) CHARACTER SET latin7 NOT NULL,  PRIMARY KEY (`TestCharsetFAId`)) ENGINE=InnoDB DEFAULT CHARSET=utf16";
                            StringAssert.AreEqualIgnoringCase(txt, createTable);
                        }
                    }

                    cmd.CommandText = "SHOW CREATE TABLE `TestCollationDA`";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        string createTable = reader.GetString(1);
                        createTable = Regex.Replace(createTable, @"\t|\n|\r", string.Empty);
                        string txt = "CREATE TABLE `testcollationda` (  `TestCollationDAId` varchar(255) CHARACTER SET greek COLLATE greek_bin NOT NULL,  PRIMARY KEY (`TestCollationDAId`)) ENGINE=InnoDB DEFAULT CHARSET=cp932 COLLATE=cp932_bin";
                        StringAssert.AreEqualIgnoringCase(txt, createTable);
                    }

                    cmd.CommandText = "SHOW CREATE TABLE `TestCollationFA`";
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        string createTable = reader.GetString(1);
                        createTable = Regex.Replace(createTable, @"\t|\n|\r", string.Empty);
                        string txt = "CREATE TABLE `testcollationfa` (  `TestCollationFAId` varchar(255) CHARACTER SET ucs2 COLLATE ucs2_bin NOT NULL,  PRIMARY KEY (`TestCollationFAId`)) ENGINE=InnoDB DEFAULT CHARSET=koi8u COLLATE=koi8u_bin";
                        StringAssert.AreEqualIgnoringCase(txt, createTable);
                    }
                }
            }
        }