Beispiel #1
0
        public void IndexesShouldMatch()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);

            Index expectedFirstIndex = new Index()
            {
                Name = "PRIMARY",
                Type = IndexType.PrimaryKey
            };

            Index expectedSecondIndex = new Index()
            {
                Name = "idx_b",
                Type = IndexType.NonUnique
            };

            var actualTable      = database.Tables.Skip(1).First();
            var actualFirstIndex = actualTable.Indexes.Single(i => i.Name == "PRIMARY");

            AssertHelper.HasEqualFieldValues(expectedFirstIndex, actualFirstIndex,
                                             new string[] { "Table", "Columns", "IsClustered" });

            var actualSecondIndex = actualTable.Indexes.Single(i => i.Name == "idx_b");

            AssertHelper.HasEqualFieldValues(expectedSecondIndex, actualSecondIndex,
                                             new string[] { "Table", "Columns", "IsClustered" });
        }
Beispiel #2
0
        public void ColumnDefault()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);
            var tableb     = database.Tables.Skip(1).First();
            var column     = tableb.Columns.First(c => c.Name == "colc");

            Assert.AreEqual("5", column.Default);
        }
Beispiel #3
0
        public void GenerationExpression()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);
            var tableb     = database.Tables.Skip(1).First();
            var column     = tableb.Columns.First(c => c.Name == "cold");

            Assert.AreEqual("(`colb` + `colc`)", column.Expression);
        }
Beispiel #4
0
        public void ForeignKeyColumnsShouldMatch()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);

            var expected = new ForeignKey.Column()
            {
                ReferencedName  = "cola",
                ReferencingName = "colb"
            };

            Assert.AreEqual(1, database.ForeignKeys.Count());
            var actual = database.ForeignKeys.Single(fk => fk.Name == "fk_table_a");

            Assert.AreEqual(1, actual.Columns.Count());
            var actualColumn = actual.Columns.First();

            AssertHelper.HasEqualFieldValues(expected, actualColumn, new string[] {  });
        }
Beispiel #5
0
        public void SchemasShouldMatch()
        {
            const string connectionString = "server=localhost;user=root;port=3306;database=mysql;password=password";

            using (var connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                try
                {
                    using (var command = new MySqlCommand("DROP DATABASE IF EXISTS `a`; CREATE DATABASE `a`;", connection))
                    {
                        command.ExecuteNonQuery();
                    }

                    using (var command = new MySqlCommand("DROP DATABASE IF EXISTS `b`; CREATE DATABASE `b`;", connection))
                    {
                        command.ExecuteNonQuery();
                    }

                    var dbProvider = new MySqlDbProvider();
                    var database   = dbProvider.GetDatabase(connectionString);
                    var expected   = new string[] { "a", "b" };
                    var actual     = database.Schemas
                                     .Select(s => s.Name)
                                     .OrderBy(s => s)
                                     .ToList();
                    CollectionAssert.AreEqual(expected, actual);
                }
                finally
                {
                    using (var command = new MySqlCommand("DROP DATABASE IF EXISTS `a`;", connection))
                    {
                        command.ExecuteNonQuery();
                    }

                    using (var command = new MySqlCommand("DROP DATABASE IF EXISTS `b`;", connection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
Beispiel #6
0
        public void TableShouldMatch()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);

            Table expected = new Table()
            {
                Schema         = "a",
                Name           = "tablea",
                IdentityColumn = "cola",
                ClusteredIndex = "PRIMARY",
                RowCount       = 0,
                ObjectId       = 0,
            };

            Assert.AreEqual(2, database.Tables.Count());
            var actual = database.Tables.First();

            AssertHelper.HasEqualFieldValues(expected, actual, new string[] { "Columns", "InternalId", "Indexes" });
        }
Beispiel #7
0
        public void ForeignKeysShouldMatch()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);

            var expected = new ForeignKey()
            {
                Name          = "fk_table_a",
                CascadeDelete = true,
                CascadeUpdate = true
            };

            Assert.AreEqual(1, database.ForeignKeys.Count());
            var actual = database.ForeignKeys.Single(fk => fk.Name == "fk_table_a");

            AssertHelper.HasEqualFieldValues(expected, actual, new string[] { "ReferencedTable", "ReferencingTable", "ObjectId", "InternalId", "Columns" });

            Assert.AreEqual("tableb", actual.ReferencingTable.Name);
            Assert.AreEqual("tablea", actual.ReferencedTable.Name);
        }
Beispiel #8
0
        public void ColumnsShouldMatch()
        {
            var dbProvider = new MySqlDbProvider();
            var database   = dbProvider.GetDatabase(connectionString);

            Column expectedFirstColumn = new Column()
            {
                Name       = "cola",
                DataType   = "int(11)",
                IsNullable = false,
                Collation  = null,
                MaxLength  = 0,
                Precision  = 10,
                Scale      = 0,
                Expression = ""
            };

            Column expectedSecondColumn = new Column()
            {
                Name       = "colb",
                DataType   = "varchar(255)",
                IsNullable = true,
                Collation  = "utf8mb4_0900_ai_ci",
                MaxLength  = 255,
                Precision  = 0,
                Scale      = 0,
                Expression = ""
            };

            var actualTable       = database.Tables.First();
            var actualFirstColumn = actualTable.Columns.First();

            AssertHelper.HasEqualFieldValues(expectedFirstColumn, actualFirstColumn,
                                             new string[] { "Table" });

            var actualSecondColumn = actualTable.Columns.Skip(1).First();

            AssertHelper.HasEqualFieldValues(expectedSecondColumn, actualSecondColumn,
                                             new string[] { "Table" });
        }
Beispiel #9
0
 private void Init()
 {
     //DbProvider = new SqlServerDbProvider();
     DbProvider = new MySqlDbProvider();
 }
Beispiel #10
0
 internal MySqlDbTransactionContext(MySqlDbProvider provider)
 {
     Provider   = provider ?? throw new ArgumentNullException(nameof(provider));
     Connection = new MySqlConnection(provider.ConnectionString);
 }
Beispiel #11
0
 public MySqlDbExecutor(MySqlDbProvider provider, string connectionString) : base(provider)
 {
     ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
 }