예제 #1
0
        public void TestSqLiteConnectionMergeViaTableNameForIdentityForNonEmptyTable()
        {
            using (var connection = new SqliteConnection(Database.ConnectionString))
            {
                // Setup
                var table = Database.CreateCompleteTables(1, connection).First();
                Helper.UpdateCompleteTableProperties(table);

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

                // Assert
                Assert.AreEqual(table.Id, result);

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

                // Assert
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertMembersEquality(table, queryResult.First());
            }
        }
예제 #2
0
        public void TestPostgreSqlConnectionInsertAsyncViaTableNameAsDynamicForIdentity()
        {
            // Setup
            var table = Helper.CreateCompleteTablesAsDynamics(1).First();

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.InsertAsync(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
                Assert.AreEqual(1, queryResult?.Count());
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }
예제 #3
0
        public void TestMicrosoftSqlConnectionDbRepositoryBulkDeleteAsyncForTableNameEntities()
        {
            // Setup
            var tables = Helper.CreateBulkOperationIdentityTables(10);

            using (var repository = new BulkOperationIdentityTableRepository())
            {
                // Act
                repository.InsertAll(tables);

                // Act
                var bulkDeleteResult = repository.BulkDeleteAsync(ClassMappedNameCache.Get <BulkOperationIdentityTable>(), tables).Result;

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

                // Act
                var countResult = repository.CountAll();

                // Assert
                Assert.AreEqual(0, countResult);
            }
        }
예제 #4
0
        public void TestSqlConnectionQueryAllAsyncViaTableNameWithFields()
        {
            // Setup
            var tables = Helper.CreateIdentityTables(10);

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAll(tables);

                // Act
                var result = connection.QueryAllAsync(ClassMappedNameCache.Get <IdentityTable>(),
                                                      Field.From(nameof(IdentityTable.Id), nameof(IdentityTable.ColumnNVarChar))).Result;

                // Assert
                Assert.AreEqual(tables.Count, result.Count());
                result.AsList().ForEach(item =>
                {
                    var entity = tables.First(t => t.Id == item.Id);
                    Assert.AreEqual(entity.ColumnNVarChar, item.ColumnNVarChar);
                });
            }
        }
예제 #5
0
        public void TestPostgreSqlConnectionInsertViaTableNameForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Insert(ClassMappedNameCache.Get <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());
            }
        }
예제 #6
0
        public void TestSqlConnectionQueryAllViaEntityTableNameWithFields()
        {
            // Setup
            var tables = Helper.CreateIdentityTables(10);

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAll(tables);

                // Act
                var result = connection.QueryAll <IdentityTable>(ClassMappedNameCache.Get <IdentityTable>(),
                                                                 fields: Field.From(nameof(IdentityTable.Id), nameof(IdentityTable.ColumnNVarChar)));

                // Assert
                Assert.AreEqual(tables.Count, result.Count());
                tables.ForEach(table =>
                {
                    var entity = result.FirstOrDefault(item => item.Id == table.Id);
                    Assert.AreEqual(table.ColumnNVarChar, entity.ColumnNVarChar);
                });
            }
        }
예제 #7
0
        public void TestSqlConnectionSharedQueryAsyncForNonIdentityTable()
        {
            // Setup
            var tables = Helper.CreateNonIdentityTables(10);

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAll(tables);

                // Act
                var result = connection.QueryAsync <SharedIdentityTable>(ClassMappedNameCache.Get <NonIdentityTable>(),
                                                                         (object)null).Result;

                // Assert
                Assert.AreEqual(tables.Count, result.Count());
                result.AsList().ForEach(item =>
                {
                    var target = tables.First(t => t.ColumnInt == item.ColumnInt);
                    Helper.AssertPropertiesEquality(target, item);
                });
            }
        }
예제 #8
0
        public void TestDbHelperForInsert()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new CustomDbConnectionForDbHelper();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlStatementBuilder(), true);
            DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true);

            // Act
            connection.Insert <DataEntityForDbHelper>(new DataEntityForDbHelper {
                Id = 1, Name = "Name"
            });

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <string>(s => s == connection.ConnectionString),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>())), Times.Exactly(1));
        }
예제 #9
0
        public void TestSqlConnectionExecuteNonQueryFromQueryBuilderCreateMaxAll()
        {
            // Setup
            var tables = Helper.CreateIdentityTables(10);

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAll(tables);

                // Setup
                var builder = connection.GetStatementBuilder();
                var sql     = builder.CreateMaxAll(null,
                                                   ClassMappedNameCache.Get <IdentityTable>(),
                                                   field: Field.Parse <IdentityTable>(e => e.ColumnInt).First());

                // Act
                var result = connection.ExecuteScalar <int>(sql);

                // Assert
                Assert.AreEqual(tables.Max(e => e.ColumnInt), result);
            }
        }
예제 #10
0
        public void TestPostgreSqlConnectionMergeAllAsDynamicsViaTableNameForIdentityForEmptyTable()
        {
            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Setup
                var tables = Helper.CreateCompleteTablesAsDynamics(10);

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

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

                // Assert
                Assert.AreEqual(tables.Count(), queryResult.Count());
                tables.ForEach(table =>
                {
                    Helper.AssertMembersEquality(table,
                                                 queryResult.OrderBy(e => e.Id).ElementAt((int)tables.IndexOf(table)));
                });
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
 /// <summary>
 /// Creates a new instance of <see cref="BatchQueryRequest"/> object.
 /// </summary>
 /// <param name="type">The target type.</param>
 /// <param name="connection">The connection object.</param>
 /// <param name="transaction">The transaction object.</param>
 /// <param name="fields">The list of the target fields.</param>
 /// <param name="page">The page of the batch.</param>
 /// <param name="rowsPerBatch">The number of rows per batch.</param>
 /// <param name="orderBy">The list of order fields.</param>
 /// <param name="where">The query expression.</param>
 /// <param name="hints">The hints for the table.</param>
 /// <param name="statementBuilder">The statement builder.</param>
 public BatchQueryRequest(Type type,
                          IDbConnection connection,
                          IDbTransaction transaction,
                          IEnumerable <Field> fields,
                          int?page,
                          int?rowsPerBatch,
                          IEnumerable <OrderField> orderBy,
                          QueryGroup where = null,
                          string hints     = null,
                          IStatementBuilder statementBuilder = null)
     : this(ClassMappedNameCache.Get(type),
            connection,
            transaction,
            fields,
            page,
            rowsPerBatch,
            orderBy,
            where,
            hints,
            statementBuilder)
 {
     Type = type;
 }
 /// <summary>
 /// Creates a new instance of <see cref="QueryMultipleRequest"/> object.
 /// </summary>
 /// <param name="index">The index value.</param>
 /// <param name="type">The target type.</param>
 /// <param name="connection">The connection object.</param>
 /// <param name="transaction">The transaction object.</param>
 /// <param name="fields">The list of the target fields.</param>
 /// <param name="where">The query expression.</param>
 /// <param name="orderBy">The list of order fields.</param>
 /// <param name="top">The filter for the rows.</param>
 /// <param name="hints">The hints for the table.</param>
 /// <param name="statementBuilder">The statement builder.</param>
 public QueryMultipleRequest(int?index,
                             Type type,
                             IDbConnection connection,
                             IDbTransaction transaction,
                             IEnumerable <Field> fields       = null,
                             QueryGroup where                 = null,
                             IEnumerable <OrderField> orderBy = null,
                             int?top      = null,
                             string hints = null,
                             IStatementBuilder statementBuilder = null)
     : this(index,
            ClassMappedNameCache.Get(type),
            connection,
            transaction,
            fields,
            where,
            orderBy,
            top,
            hints,
            statementBuilder)
 {
     Type = type;
 }
예제 #14
0
        public void TestSqlServerConnectionUpdateAsyncViaTableNameViaQueryField()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

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

                // Act
                var result = connection.UpdateAsync(ClassMappedNameCache.Get <CompleteTable>(), table, new QueryField("Id", table.Id)).Result;

                // Assert
                Assert.AreEqual(1, result);

                // Act
                var queryResult = connection.Query <CompleteTable>(table.Id).First();

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult);
            }
        }
예제 #15
0
        public void TestSqLiteConnectionUpdateAllAsyncAsExpandoObjectViaTableName()
        {
            using (var connection = new SQLiteConnection(Database.ConnectionStringSDS))
            {
                // Setup
                Database.CreateSdsCompleteTables(10, connection);
                var tables = Helper.CreateSdsCompleteTablesAsExpandoObjects(10);

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

                // Assert
                Assert.AreEqual(10, result);

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

                // Assert
                tables.AsList().ForEach(table =>
                                        Helper.AssertMembersEquality(queryResult.First(e => e.Id == ((dynamic)table).Id), table));
            }
        }
예제 #16
0
        public void TestSqlConnectionCountViaAsyncViaTableNameViaQueryFields()
        {
            // Setup
            var tables = Helper.CreateIdentityTables(10);
            var fields = new[]
            {
                new QueryField(nameof(IdentityTable.ColumnInt), Operation.GreaterThan, 5),
                new QueryField(nameof(IdentityTable.ColumnInt), Operation.LessThanOrEqual, 8)
            };

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAll(tables);

                // Act
                var result = connection.CountAsync(ClassMappedNameCache.Get <IdentityTable>(),
                                                   fields).Result;

                // Assert
                Assert.AreEqual(3, result);
            }
        }
예제 #17
0
        public void TestSQLiteConnectionMergeViaTableNameAsExpandoObjectForIdentityForNonEmptyTable()
        {
            using (var connection = new SQLiteConnection(Database.ConnectionStringMDS))
            {
                // Setup
                Database.CreateSdsCompleteTables(1, connection).First();
                var table = Helper.CreateSdsCompleteTablesAsExpandoObjects(1).First();

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

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

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

                // Assert
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }
예제 #18
0
        public void TestSQLiteConnectionMergeAsyncAsDynamicViaTableNameForIdentityForNonEmptyTable()
        {
            using (var connection = new SQLiteConnection(Database.ConnectionStringMDS))
            {
                // Setup
                var table = Database.CreateSdsCompleteTables(1, connection).First();
                Helper.UpdateSdsCompleteTableProperties(table);

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

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

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

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
예제 #19
0
        public void TestSqlConnectionInsertAsyncViaTableNameWithFields()
        {
            // Setup
            var table = Helper.CreateIdentityTable();

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                var id = connection.InsertAsync <long>(ClassMappedNameCache.Get <IdentityTable>(),
                                                       table,
                                                       fields: Field.From(nameof(IdentityTable.Id), nameof(IdentityTable.RowGuid), nameof(IdentityTable.ColumnNVarChar))).Result;

                // Assert
                Assert.IsTrue(id > 0);

                // Act
                var result = connection.Query <IdentityTable>(id)?.FirstOrDefault();

                // Assert
                Assert.AreEqual(table.RowGuid, result.RowGuid);
                Assert.AreEqual(table.ColumnNVarChar, result.ColumnNVarChar);
            }
        }
예제 #20
0
        public void TestMySqlConnectionUpdateViaTableNameViaDynamic()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

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

                // Act
                var result = DbConnectionExtension.Update(connection, ClassMappedNameCache.Get <CompleteTable>(), table, new { table.Id });

                // Assert
                Assert.AreEqual(1, result);

                // Act
                var queryResult = connection.Query(ClassMappedNameCache.Get <CompleteTable>(), table.Id).First();

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult);
            }
        }
예제 #21
0
        public void TestSqlConnectionInsertAllAsyncForIdentityTableViaTableName()
        {
            // Setup
            var tables = Helper.CreateDynamicIdentityTables(10);

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                connection.InsertAllAsync(ClassMappedNameCache.Get <IdentityTable>(),
                                          tables).Wait();

                // Act
                var result = connection.QueryAll <IdentityTable>().AsList();

                // Assert
                Assert.AreEqual(tables.Count, result.Count);
                tables.ForEach(table =>
                {
                    var entity = result.FirstOrDefault(item => item.Id == table.Id);
                    Helper.AssertPropertiesEquality(table, entity);
                });
            }
        }
예제 #22
0
        public void TestSqlConnectionInsertAllAsyncViaTableNameAsExpandoObjectForIdentity()
        {
            // Setup
            var tables = Helper.CreateCompleteTablesAsExpandoObjects(10);

            using (var connection = new SqlConnection(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);
                Assert.IsTrue(tables.All(table => ((dynamic)table).Id > 0));

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

                // Assert
                tables.ForEach(table => Helper.AssertMembersEquality(queryResult.First(e => e.Id == ((dynamic)table).Id), table));
            }
        }
예제 #23
0
        public void TestSQLiteConnectionMergeAllAsyncAsDynamicsViaTableNameForNonIdentityForNonEmptyTable()
        {
            using (var connection = new SQLiteConnection(Database.ConnectionStringMDS))
            {
                // Setup
                var tables = Database.CreateSdsNonIdentityCompleteTables(10, connection).AsList();
                tables.ForEach(table => Helper.UpdateSdsNonIdentityCompleteTableProperties(table));

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

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

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

                // Assert
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
예제 #24
0
        public void TestPostgreSqlConnectionMergeAllViaTableNameForNonIdentityForEmptyTable()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTables(10);

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

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

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

                // Assert
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertPropertiesEquality(table, queryResult.First(e => e.Id == table.Id)));
            }
        }
예제 #25
0
        public void TestDbHelperForInsert()
        {
            // Prepare
            var dbHelper   = GetMockedDbHelper();
            var connection = new DbHelperDbConnection();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true);

            // Act
            connection.Insert <DbHelperDataEntity>(new DbHelperDataEntity {
                Id = 1, Name = "Name"
            });

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <IDbConnection>(s => s == connection),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DbHelperDataEntity>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
예제 #26
0
        public void TestSqlConnectionInsertViaTableNameAsExpandoObjectForNonIdentityTable()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTablesAsExpandoObjects(1).First();

            using (var connection = new SqlConnection(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);
            }
        }
예제 #27
0
        public void TestMySqlConnectionInsertViaTableNameAsyncForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTables(1).First();

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

                // 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.AssertPropertiesEquality(table, queryResult.First());
            }
        }
예제 #28
0
        public void TestSqlConnectionExecuteNonQueryFromQueryBuilderCreateMerge()
        {
            // Setup
            var table  = Helper.CreateIdentityTables(1).First();
            var fields = FieldCache.Get <IdentityTable>();

            using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
            {
                // Act
                var id = connection.Insert(table);

                // Set the properties
                table.ColumnNVarChar = $"{table.ColumnNVarChar}-Merged";

                // Setup
                var dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get <IdentityTable>(), null);
                var builder  = connection.GetStatementBuilder();
                var sql      = builder.CreateMerge(null,
                                                   ClassMappedNameCache.Get <IdentityTable>(),
                                                   fields: fields,
                                                   qualifiers: fields.Where(f => dbFields.FirstOrDefault(df => (df.IsPrimary || df.IsIdentity) && df.Name == f.Name) != null),
                                                   primaryField: dbFields.FirstOrDefault(e => e.IsPrimary),
                                                   identityField: dbFields.FirstOrDefault(e => e.IsIdentity));

                // Act
                var affectedRow = connection.ExecuteNonQuery(sql, table);

                // Assert
                Assert.AreEqual(1, affectedRow);

                // Setup
                var result = connection.QueryAll <IdentityTable>().First();

                // Assert
                Helper.AssertPropertiesEquality(table, result);
            }
        }
예제 #29
0
        public void TestMySqlConnectionInsertAllAsyncViaTableNameAsDynamicsForNonIdentity()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTablesAsDynamics(10);

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

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

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

                // Assert
                tables.ForEach(table =>
                {
                    Helper.AssertMembersEquality(table, queryResult.ElementAt((int)tables.IndexOf(table)));
                });
            }
        }
예제 #30
0
        public void TestMySqlConnectionMergeAllAsyncAsDynamicsViaTableNameForNonIdentityForNonEmptyTable()
        {
            // Setup
            var tables   = Database.CreateNonIdentityCompleteTables(10).AsList();
            var entities = tables.Select(table => new
            {
                Id        = table.Id,
                ColumnInt = int.MaxValue
            }).AsList();

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

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

                // Assert
                Assert.AreEqual(tables.Count(), queryResult.Count());
                entities.ForEach(table => Assert.AreEqual(table.ColumnInt, queryResult.ElementAt((int)entities.IndexOf(table)).ColumnInt));
            }
        }