Exemple #1
0
        public void TestMySqlConnectionMergeAllAsDynamicsViaTableNameForNonIdentityForEmptyTable()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTablesAsDynamics(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.MergeAll(ClassMappedNameCache.Get <NonIdentityCompleteTable>(),
                                                 tables);

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <NonIdentityCompleteTable>());

                // Assert
                Assert.AreEqual(tables.Count, result);

                // Act
                var queryResult = connection.QueryAll <NonIdentityCompleteTable>();

                // Assert
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertMembersEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #2
0
        public void TestMySqlConnectionMergeAllAsyncAsDynamicsViaTableNameForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var tables     = Database.CreateCompleteTables(10).AsList();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                tables.ForEach(table => Helper.UpdateCompleteTableProperties(table));

                // Act
                var result = connection.MergeAllAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                      tables,
                                                      qualifiers).Result;

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <CompleteTable>());

                // Act
                var queryResult = connection.QueryAll <CompleteTable>();

                // Assert
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #3
0
        public void TestMySqlConnectionMergeAsyncAsExpandoObjectViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                var entity = Helper.CreateCompleteTablesAsExpandoObjects(1).First();
                ((IDictionary <string, object>)entity)["Id"] = table.Id;

                // Act
                var result = connection.MergeAsync <long>(ClassMappedNameCache.Get <CompleteTable>(),
                                                          entity).Result;

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.AreEqual(table.Id, result);
                Assert.AreEqual(((dynamic)table).Id, result);

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Helper.AssertMembersEquality(queryResult.First(), entity);
            }
        }
Exemple #4
0
        public void TestMySqlConnectionMergeAsyncAsDynamicViaTableNameForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var table      = Database.CreateCompleteTables(1).First();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                Helper.UpdateCompleteTableProperties(table);

                // Act
                var result = connection.MergeAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                   table,
                                                   qualifiers: qualifiers).Result;

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.AreEqual(table.Id, Convert.ToInt64(result));

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #5
0
        public void TestMySqlConnectionMergeForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var table      = Database.CreateCompleteTables(1).First();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                Helper.UpdateCompleteTableProperties(table);
                table.ColumnInt  = 0;
                table.ColumnChar = "C";

                // Act
                var result = connection.Merge <CompleteTable>(table,
                                                              qualifiers: qualifiers);

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.AreEqual(table.Id, Convert.ToInt64(result));

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #6
0
        public void TestMySqlConnectionMergeViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                Helper.UpdateCompleteTableProperties(table);

                // Act
                var result = connection.Merge(ClassMappedNameCache.Get <CompleteTable>(),
                                              table);

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.AreEqual(table.Id, Convert.ToInt64(result));

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #7
0
        public void TestMySqlConnectionMergeAllViaTableNameAsyncForIdentityForNonEmptyTable()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10).AsList();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                tables.ForEach(table => Helper.UpdateCompleteTableProperties(table));

                // Act
                var result = connection.MergeAllAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                      tables).Result;

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <CompleteTable>());

                // Act
                var queryResult = connection.QueryAll <CompleteTable>();

                // Assert
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertMembersEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #8
0
        public void TestMySqlConnectionMergeAllAsyncAsExpandoObjectViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var entities = Database.CreateCompleteTables(10).AsList();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Setup
                var tables = Helper.CreateCompleteTablesAsExpandoObjects(10).AsList();
                tables.ForEach(e => ((IDictionary <string, object>)e)["Id"] = entities[tables.IndexOf(e)].Id);

                // Act
                var result = connection.MergeAllAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                      tables).Result;

                // Assert
                Assert.AreEqual(entities.Count, connection.CountAll <CompleteTable>());
                Assert.IsTrue(tables.All(table => ((dynamic)table).Id > 0));

                // Act
                var queryResult = connection.QueryAll <CompleteTable>();

                // Assert
                Assert.AreEqual(entities.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertMembersEquality(queryResult.First(e => e.Id == ((dynamic)table).Id), table));
            }
        }
Exemple #9
0
        public void ThrowExceptionOnMySqlConnectionCountAllWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                connection.CountAll <CompleteTable>(hints: "WhatEver");
            }
        }
Exemple #10
0
        public void ThrowExceptionOnMySqlConnectionCountAllViaTableNameWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                connection.CountAll(ClassMappedNameCache.Get <CompleteTable>(),
                                    hints: "WhatEver");
            }
        }
Exemple #11
0
 public void TestSqlTransactionForCountAll()
 {
     using (var connection = new MySqlConnection(Database.ConnectionString))
     {
         // Prepare
         using (var transaction = connection.EnsureOpen().BeginTransaction())
         {
             // Act
             connection.CountAll <CompleteTable>(transaction: transaction);
         }
     }
 }
Exemple #12
0
        public void TestMySqlConnectionCountAll()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.CountAll <CompleteTable>();

                // Assert
                Assert.AreEqual(tables.Count(), result);
            }
        }
Exemple #13
0
        public void TestMySqlConnectionTruncateAsyncViaTableNameWithoutExpression()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result      = connection.TruncateAsync(ClassMappedNameCache.Get <CompleteTable>()).Result;
                var countResult = connection.CountAll <CompleteTable>();

                // Assert
                Assert.AreEqual(0, countResult);
            }
        }
Exemple #14
0
        public void TestMySqlConnectionMergeForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result      = connection.Merge <CompleteTable>(table);
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #15
0
        public void TestMySqlConnectionMergeAsyncAsExpandoObjectViaTableNameForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTablesAsExpandoObjects(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.MergeAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                   table).Result;
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.IsTrue(((dynamic)table).Id == Convert.ToInt64(result));
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }
Exemple #16
0
        public void TestMySqlConnectionForInsertForMySqlMapAttribute()
        {
            // Setup
            var table = CreateAttributeTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                connection.Insert <AttributeTable>(table);

                // Assert
                Assert.AreEqual(1, connection.CountAll <AttributeTable>());

                // Query
                var queryResult = connection.QueryAll <AttributeTable>().First();

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult);
            }
        }
Exemple #17
0
        public void TestSqlTransactionForMergeAsyncAsRolledBack()
        {
            // Setup
            var entity = Helper.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Prepare
                var transaction = connection.EnsureOpen().BeginTransaction();

                // Act
                connection.MergeAsync <CompleteTable>(entity, transaction: transaction).Wait();

                // Act
                transaction.Rollback();

                // Assert
                Assert.AreEqual(0, connection.CountAll <CompleteTable>());
            }
        }
Exemple #18
0
        public void TestMySqlConnectionForInsertAllForMySqlMapAttribute()
        {
            // Setup
            var tables = CreateAttributeTables(10).AsList();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                connection.InsertAll <AttributeTable>(tables);

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <AttributeTable>());

                // Query
                var queryResult = connection.QueryAll <AttributeTable>();

                // Assert
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #19
0
        public void TestSqlTransactionForInsertAsCommitted()
        {
            // Setup
            var entity = Helper.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Prepare
                using (var transaction = connection.EnsureOpen().BeginTransaction())
                {
                    // Act
                    connection.Insert <CompleteTable>(entity, transaction: transaction);

                    // Act
                    transaction.Commit();
                }

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
            }
        }
Exemple #20
0
        public void TestSqlTransactionForInsertAllAsRolledBack()
        {
            // Setup
            var entities = Helper.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Prepare
                using (var transaction = connection.EnsureOpen().BeginTransaction())
                {
                    // Act
                    connection.InsertAll <CompleteTable>(entities, transaction: transaction);

                    // Act
                    transaction.Rollback();
                }

                // Assert
                Assert.AreEqual(0, connection.CountAll <CompleteTable>());
            }
        }
Exemple #21
0
        public void TestMySqlConnectionInsertAllForNonIdentity()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAll <NonIdentityCompleteTable>(tables);

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <NonIdentityCompleteTable>());
                Assert.AreEqual(tables.Count, result);

                // Act
                var queryResult = connection.QueryAll <NonIdentityCompleteTable>();

                // Assert
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #22
0
        public void TestSqlTransactionForMergeAllAsyncAsCommitted()
        {
            // Setup
            var entities = Helper.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Prepare
                using (var transaction = connection.EnsureOpen().BeginTransaction())
                {
                    // Act
                    connection.MergeAllAsync <CompleteTable>(entities, transaction: transaction).Wait();

                    // Act
                    transaction.Commit();
                }

                // Assert
                Assert.AreEqual(entities.Count, connection.CountAll <CompleteTable>());
            }
        }
Exemple #23
0
        public void TestMySqlConnectionInsertForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Insert <NonIdentityCompleteTable>(table);

                // Assert
                Assert.AreEqual(1, connection.CountAll <NonIdentityCompleteTable>());
                Assert.AreEqual(table.Id, result);

                // Act
                var queryResult = connection.Query <NonIdentityCompleteTable>(result);

                // Assert
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #24
0
        public void TestMySqlConnectionMergeAsyncAsDynamicViaTableNameForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTablesAsDynamics(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.MergeAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                   (object)table).Result;

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.IsTrue(Convert.ToInt64(result) > 0);

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #25
0
        public void TestMySqlConnectionInsertAllAsyncViaTableNameAsExpandoObjectsForNonIdentity()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTablesAsExpandoObjects(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAllAsync(ClassMappedNameCache.Get <NonIdentityCompleteTable>(),
                                                       tables).Result;

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <NonIdentityCompleteTable>());
                Assert.AreEqual(tables.Count, result);

                // Act
                var queryResult = connection.QueryAll <NonIdentityCompleteTable>();

                // Assert
                tables.ForEach(table => Helper.AssertMembersEquality(queryResult.First(e => e.Id == ((dynamic)table).Id), table));
            }
        }
Exemple #26
0
        public void TestMySqlConnectionInsertAllViaTableNameAsyncForIdentity()
        {
            // Setup
            var tables = Helper.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAllAsync(ClassMappedNameCache.Get <CompleteTable>(),
                                                       tables).Result;

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <CompleteTable>());
                Assert.AreEqual(tables.Count, result);

                // Act
                var queryResult = connection.QueryAll <CompleteTable>();

                // Assert
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #27
0
        public void TestMySqlConnectionMergeAllAsyncForIdentityForEmptyTable()
        {
            // Setup
            var tables = Helper.CreateCompleteTables(10);

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.MergeAllAsync <CompleteTable>(tables).Result;

                // Assert
                Assert.AreEqual(tables.Count, connection.CountAll <CompleteTable>());
                Assert.AreEqual(tables.Count, result);

                // Act
                var queryResult = connection.QueryAll <CompleteTable>();

                // Assert
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
Exemple #28
0
        public void TestMySqlConnectionInsertAsyncForIdentity()
        {
            // Setup
            var table = Helper.CreateCompleteTables(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAsync <CompleteTable>(table).Result;

                // Assert
                Assert.AreEqual(1, connection.CountAll <CompleteTable>());
                Assert.IsTrue(Convert.ToInt64(result) > 0);
                Assert.IsTrue(table.Id > 0);

                // Act
                var queryResult = connection.Query <CompleteTable>(result);

                // Assert
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Exemple #29
0
        public void TestMySqlConnectionInsertAsyncViaTableNameAsDynamicForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTablesAsDynamics(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAsync(ClassMappedNameCache.Get <NonIdentityCompleteTable>(),
                                                    (object)table).Result;

                // Assert
                Assert.AreEqual(1, connection.CountAll <NonIdentityCompleteTable>());
                Assert.AreEqual(table.Id, result);

                // Act
                var queryResult = connection.Query <NonIdentityCompleteTable>(result);

                // Assert
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }
Exemple #30
0
        public void TestMySqlConnectionInsertViaTableNameAsExpandoObjectForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTablesAsExpandoObjects(1).First();

            using (var connection = new MySqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Insert(ClassMappedNameCache.Get <NonIdentityCompleteTable>(),
                                               table);

                // Assert
                Assert.AreEqual(1, connection.CountAll <NonIdentityCompleteTable>());
                Assert.IsTrue(Convert.ToInt64(result) > 0);

                // Act
                var queryResult = connection.Query <NonIdentityCompleteTable>(result);

                // Assert
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }