Ejemplo n.º 1
0
        public void TestBatchQueryWithClassHandler()
        {
            // Setup
            var tables = CreateClassHandlerIdentityTables(10).AsList();

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

                // Setup
                var handler = ClassHandlerCache.Get <ClassHandlerIdentityTableClassHandler>(typeof(ClassHandlerIdentityTable));
                handler.Reset();

                // Act
                var result = connection.BatchQuery <ClassHandlerIdentityTable>(page: 0,
                                                                               rowsPerBatch: 10,
                                                                               orderBy: OrderField.Parse(new { Id = Order.Ascending }),
                                                                               where : (object)null);

                // Assert
                Assert.AreEqual(tables.Count, handler.GetMethodCallCount);
                Assert.AreEqual(tables.Count, result.Count());
                result.AsList().ForEach(item =>
                {
                    var target = tables.First(t => t.Id == item.Id);
                    Helper.AssertPropertiesEquality(target, item);
                });
            }
        }
Ejemplo n.º 2
0
 public void TestSqlTransactionForBatchQuery()
 {
     using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb))
     {
         // Prepare
         using (var transaction = connection.EnsureOpen().BeginTransaction())
         {
             // Act
             connection.BatchQuery <IdentityTable>(0, 10, OrderField.Parse(new { Id = Order.Ascending }), it => it.Id != 0, transaction: transaction);
         }
     }
 }
Ejemplo n.º 3
0
        public void TestSqlServerConnectionBatchQueryThirdBatchDescending()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new SqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.BatchQuery <CompleteTable>(2,
                                                                   3,
                                                                   OrderField.Descending <CompleteTable>(c => c.Id).AsEnumerable(),
                                                                   (object)null);

                // Assert
                Helper.AssertPropertiesEquality(tables.ElementAt(3), result.ElementAt(0));
                Helper.AssertPropertiesEquality(tables.ElementAt(1), result.ElementAt(2));
            }
        }
Ejemplo n.º 4
0
        public void TestSqlServerConnectionBatchQueryViaTableNameThirdBatchAscending()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new SqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.BatchQuery(ClassMappedNameCache.Get <CompleteTable>(),
                                                   2,
                                                   3,
                                                   OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(),
                                                   (object)null);

                // Assert
                Helper.AssertMembersEquality(tables.ElementAt(6), result.ElementAt(0));
                Helper.AssertMembersEquality(tables.ElementAt(8), result.ElementAt(2));
            }
        }
Ejemplo n.º 5
0
        public void TestSqlServerConnectionBatchQueryFirstBatchAscendingWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new SqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.BatchQuery <CompleteTable>(page: 0,
                                                                   rowsPerBatch: 3,
                                                                   orderBy: OrderField.Ascending <CompleteTable>(c => c.Id).AsEnumerable(),
                                                                   where : (object)null,
                                                                   hints: SqlServerTableHints.NoLock);

                // Assert
                Helper.AssertPropertiesEquality(tables.ElementAt(0), result.ElementAt(0));
                Helper.AssertPropertiesEquality(tables.ElementAt(2), result.ElementAt(2));
            }
        }
Ejemplo n.º 6
0
        public void ThrowExceptionOnBatchQueryWithClassHandlerWithDifferentModel()
        {
            // Setup
            var tables = Helper.CreateIdentityTables(10).AsList();

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

                // Setup
                var handler = ClassHandlerCache.Get <ClassHandlerTestModelClassHandler>(typeof(ClassHandlerIdentityTableWithTestModel));

                // Act
                connection.BatchQuery <ClassHandlerIdentityTableWithTestModel>(page: 0,
                                                                               rowsPerBatch: 10,
                                                                               orderBy: OrderField.Parse(new { Id = Order.Ascending }),
                                                                               where : (object)null);
            }
        }