Beispiel #1
0
        public void ThrowExceptionOnPostgreSqlConnectionCountWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                connection.Count <CompleteTable>((object)null,
                                                 hints: "WhatEver");
            }
        }
Beispiel #2
0
 public void TestSqlTransactionForCount()
 {
     using (var connection = new NpgsqlConnection(Database.ConnectionString))
     {
         // Prepare
         using (var transaction = connection.EnsureOpen().BeginTransaction())
         {
             // Act
             connection.Count <CompleteTable>(it => it.Id != 0, transaction: transaction);
         }
     }
 }
Beispiel #3
0
        public void TestPostgreSqlConnectionCountViaQueryField()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Count <CompleteTable>(new QueryField("Id", tables.First().Id));

                // Assert
                Assert.AreEqual(tables.Where(e => e.Id == tables.First().Id).Count(), result);
            }
        }
Beispiel #4
0
        public void TestPostgreSqlConnectionCountWithoutExpression()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Count <CompleteTable>((object)null);

                // Assert
                Assert.AreEqual(tables.Count(), result);
            }
        }
Beispiel #5
0
        public void TestPostgreSqlConnectionCountViaExpression()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);
            var ids    = new[] { tables.First().Id, tables.Last().Id };

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Count <CompleteTable>(e => ids.Contains(e.Id));

                // Assert
                Assert.AreEqual(tables.Where(e => ids.Contains(e.Id)).Count(), result);
            }
        }
Beispiel #6
0
        public void TestPostgreSqlConnectionCountViaTableNameViaDynamic()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Count(ClassMappedNameCache.Get <CompleteTable>(),
                                              new { tables.First().Id });

                // Assert
                Assert.AreEqual(tables.Where(e => e.Id == tables.First().Id).Count(), result);
            }
        }
Beispiel #7
0
        public void TestPostgreSqlConnectionCountViaQueryFields()
        {
            // Setup
            var tables      = Database.CreateCompleteTables(10);
            var queryFields = new[]
            {
                new QueryField("Id", Operation.GreaterThan, tables.First().Id),
                new QueryField("Id", Operation.LessThan, tables.Last().Id)
            };

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.Count <CompleteTable>(queryFields);

                // Assert
                Assert.AreEqual(tables.Where(e => e.Id > tables.First().Id&& e.Id < tables.Last().Id).Count(), result);
            }
        }