public void TestSqlConnectionExecuteNonQueryFromQueryBuilderCreateBatchQuery() { // Setup var tables = Helper.CreateIdentityTables(10); var where = new QueryGroup(new QueryField("Id", Operation.GreaterThanOrEqual, 0)); var fields = FieldCache.Get <IdentityTable>(); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Setup var builder = connection.GetStatementBuilder(); var sql = builder.CreateBatchQuery(null, ClassMappedNameCache.Get <IdentityTable>(), fields: fields, page: 2, rowsPerBatch: 2, orderBy: OrderField.Ascending <IdentityTable>(e => e.Id).AsEnumerable(), where : where); // Act var result = connection.ExecuteQuery <IdentityTable>(sql, where); // Assert Assert.AreEqual(2, result.Count()); result.AsList().ForEach(item => { Helper.AssertPropertiesEquality(tables.First(v => v.Id == item.Id), item); }); } }
public void TestDbHelperForBatchQueryViaTableName() { // Prepare var dbHelper = GetMockedDbHelper(); var connection = new DbHelperDbConnection(); // Act CommandTextCache.Flush(); DbFieldCache.Flush(); DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true); // Act connection.BatchQuery(ClassMappedNameCache.Get <DbHelperDataEntity>(), 0, 10, OrderField.Ascending <DbHelperDataEntity>(e => e.Id).AsEnumerable(), new { Id = 1 }); // 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)); }
public void TestDbHelperForBatchQuery() { // Prepare var dbHelper = new Mock <IDbHelper>(); var connection = new CustomDbConnectionForDbHelper(); // Setup dbHelper.Setup(builder => builder.GetFields( It.Is <IDbConnection>(s => s == connection), It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()), It.IsAny <IDbTransaction>()) ).Returns(GetDbFields()); // Act CommandTextCache.Flush(); DbFieldCache.Flush(); StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlServerStatementBuilder(), true); DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true); // Act connection.BatchQuery <DataEntityForDbHelper>(0, 10, OrderField.Ascending <DataEntityForDbHelper>(e => e.Id).AsEnumerable(), e => e.Id == 1); // Assert dbHelper.Verify(builder => builder.GetFields( It.Is <IDbConnection>(s => s == connection), It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()), It.IsAny <IDbTransaction>()), Times.Exactly(1)); }
public void TestOrderFieldForAscending() { // Act var parsed = OrderField.Ascending <OrderFieldTestClass>(p => p.Id); // Assert Assert.AreEqual(Order.Ascending, parsed.Order); }
public void TestOrderFieldAscendingFromMappedProperty() { // Act var parsed = OrderField.Ascending <OrderFieldTestMappedClass>(p => p.PropertyString); // Assert Assert.AreEqual("PropertyText", parsed.Name); Assert.AreEqual(Order.Ascending, parsed.Order); }
public void ThrowExceptionOnMySqlConnectionBatchQueryAsyncWithHints() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act connection.BatchQueryAsync <CompleteTable>(0, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), (object)null, hints: "WhatEver").Wait(); } }
public void ThrowExceptionOnSqLiteConnectionBatchQueryWithHints() { using (var connection = new SQLiteConnection(Database.ConnectionStringSDS)) { // Setup var tables = Database.CreateSdsCompleteTables(10, connection); // Act connection.BatchQuery <SdsCompleteTable>(0, 3, OrderField.Ascending <SdsCompleteTable>(c => c.Id).AsEnumerable(), (object)null, hints: "WhatEver"); } }
public void ThrowExceptionOnMySqlConnectionBatchQueryViaTableNameWithHints() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act connection.BatchQuery(ClassMappedNameCache.Get <CompleteTable>(), 0, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), (object)null, hints: "WhatEver"); } }
public void ThrowExceptionOnSqLiteConnectionBatchQueryAsyncViaTableNameWithHints() { using (var connection = new SQLiteConnection(Database.ConnectionStringSDS)) { // Setup var tables = Database.CreateSdsCompleteTables(10, connection); // Act connection.BatchQueryAsync(ClassMappedNameCache.Get <SdsCompleteTable>(), 0, 3, OrderField.Ascending <SdsCompleteTable>(c => c.Id).AsEnumerable(), (object)null, hints: "WhatEver").Wait(); } }
public void TestMySqlConnectionBatchQueryThirdBatchAscending() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.BatchQuery <CompleteTable>(2, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), (object)null); // Assert Helper.AssertPropertiesEquality(tables.ElementAt(6), result.ElementAt(0)); Helper.AssertPropertiesEquality(tables.ElementAt(8), result.ElementAt(2)); } }
public void TestSqLiteConnectionBatchQueryFirstBatchAscending() { using (var connection = new SQLiteConnection(Database.ConnectionStringSDS)) { // Setup var tables = Database.CreateSdsCompleteTables(10, connection); // Act var result = connection.BatchQuery <SdsCompleteTable>(0, 3, OrderField.Ascending <SdsCompleteTable>(c => c.Id).AsEnumerable(), (object)null); // Assert Helper.AssertPropertiesEquality(tables.ElementAt(0), result.ElementAt(0)); Helper.AssertPropertiesEquality(tables.ElementAt(2), result.ElementAt(2)); } }
public void TestSqlServerConnectionBatchQueryAsyncFirstBatchAscending() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var result = connection.BatchQueryAsync <CompleteTable>(0, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), (object)null).Result; // Assert Helper.AssertPropertiesEquality(tables.ElementAt(0), result.ElementAt(0)); Helper.AssertPropertiesEquality(tables.ElementAt(2), result.ElementAt(2)); } }
public void TestSqLiteConnectionBatchQueryAsyncThirdBatchAscending() { using (var connection = new SqliteConnection(Database.ConnectionStringMDS)) { // Setup var tables = Database.CreateMdsCompleteTables(10, connection); // Act var result = connection.BatchQueryAsync <MdsCompleteTable>(2, 3, OrderField.Ascending <MdsCompleteTable>(c => c.Id).AsEnumerable(), (object)null).Result; // Assert Helper.AssertPropertiesEquality(tables.ElementAt(6), result.ElementAt(0)); Helper.AssertPropertiesEquality(tables.ElementAt(8), result.ElementAt(2)); } }
public void TestMySqlConnectionBatchQueryViaTableNameAsyncThirdBatchAscending() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.BatchQueryAsync(ClassMappedNameCache.Get <CompleteTable>(), 2, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), (object)null).Result; // Assert Helper.AssertMembersEquality(tables.ElementAt(6), result.ElementAt(0)); Helper.AssertMembersEquality(tables.ElementAt(8), result.ElementAt(2)); } }
public void TestSqLiteConnectionBatchQueryViaTableNameAsyncFirstBatchAscending() { using (var connection = new SQLiteConnection(Database.ConnectionStringSDS)) { // Setup var tables = Database.CreateSdsCompleteTables(10, connection); // Act var result = connection.BatchQueryAsync(ClassMappedNameCache.Get <SdsCompleteTable>(), 0, 3, OrderField.Ascending <SdsCompleteTable>(c => c.Id).AsEnumerable(), (object)null).Result; // Assert Helper.AssertMembersEquality(tables.ElementAt(0), result.ElementAt(0)); Helper.AssertMembersEquality(tables.ElementAt(2), result.ElementAt(2)); } }
public void TestSqlServerConnectionBatchQueryAsyncFirstBatchAscendingWithHints() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var result = connection.BatchQueryAsync <CompleteTable>(page: 0, rowsPerBatch: 3, orderBy: OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), where : (object)null, hints: SqlServerTableHints.NoLock).Result; // Assert Helper.AssertPropertiesEquality(tables.ElementAt(0), result.ElementAt(0)); Helper.AssertPropertiesEquality(tables.ElementAt(2), result.ElementAt(2)); } }
public void TestSqlServerConnectionBatchQueryViaTableNameAsyncFirstBatchAscendingWithHints() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var result = connection.BatchQueryAsync(ClassMappedNameCache.Get <CompleteTable>(), 0, 3, OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(), where : (object)null, hints: SqlServerTableHints.NoLock).Result; // Assert Helper.AssertMembersEquality(tables.ElementAt(0), result.ElementAt(0)); Helper.AssertMembersEquality(tables.ElementAt(2), result.ElementAt(2)); } }