Пример #1
0
        public void TestPostgreSqlConnectionMergeAllAsyncAsExpandoObjectViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var entities = Database.CreateCompleteTables(10).AsList();

            using (var connection = new NpgsqlConnection(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>());

                // 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));
            }
        }
Пример #2
0
        public void TestPostgreSqlConnectionMergeAsyncAsExpandoObjectViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

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

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

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

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

                // Assert
                Helper.AssertMembersEquality(queryResult.First(), entity);
            }
        }
Пример #3
0
        public void TestPostgreSqlConnectionMergeForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var table      = Database.CreateCompleteTables(1).First();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Setup
                Helper.UpdateCompleteTableProperties(table);
                table.ColumnInteger   = 0;
                table.ColumnCharacter = "C";

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

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

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

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Пример #4
0
        public void TestPostgreSqlConnectionMergeAsyncAsDynamicViaTableNameForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var table      = Database.CreateCompleteTables(1).First();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

            using (var connection = new NpgsqlConnection(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, result);

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

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Пример #5
0
        public void TestPostgreSqlConnectionMergeAllForIdentityForNonEmptyTableWithQualifiers()
        {
            // Setup
            var tables     = Database.CreateCompleteTables(10).AsList();
            var qualifiers = new[]
            {
                new Field("Id", typeof(long))
            };

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

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

                // 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)));
            }
        }
Пример #6
0
        public void TestPostgreSqlConnectionMergeViaTableNameForIdentityForNonEmptyTable()
        {
            // Setup
            var table = Database.CreateCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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, result);

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

                // Assert
                Helper.AssertPropertiesEquality(table, queryResult.First());
            }
        }
Пример #7
0
        public void TestPostgreSqlConnectionMergeAllAsyncAsDynamicsViaTableNameForNonIdentityForNonEmptyTable()
        {
            // Setup
            var tables = Database.CreateNonIdentityCompleteTables(10).AsList();

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

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

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

                // 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)));
            }
        }
Пример #8
0
        public void ThrowExceptionOnPostgreSqlConnectionCountAllWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                connection.CountAll <CompleteTable>(hints: "WhatEver");
            }
        }
Пример #9
0
        public void ThrowExceptionOnPostgreSqlConnectionCountAllViaTableNameWithHints()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                connection.CountAll(ClassMappedNameCache.Get <CompleteTable>(),
                                    hints: "WhatEver");
            }
        }
Пример #10
0
 public void TestSqlTransactionForCountAll()
 {
     using (var connection = new NpgsqlConnection(Database.ConnectionString))
     {
         // Prepare
         using (var transaction = connection.EnsureOpen().BeginTransaction())
         {
             // Act
             connection.CountAll <CompleteTable>(transaction: transaction);
         }
     }
 }
Пример #11
0
        public void TestPostgreSqlConnectionCountAll()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

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

                // Assert
                Assert.AreEqual(tables.Count(), result);
            }
        }
Пример #12
0
        public void TestPostgreSqlConnectionTruncateAsyncViaTableNameWithoutExpression()
        {
            // Setup
            var tables = Database.CreateCompleteTables(10);

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

                // Assert
                Assert.AreEqual(0, countResult);
            }
        }
Пример #13
0
        public void TestPostgreSqlConnectionMergeForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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());
            }
        }
Пример #14
0
        public void TestPostgreSqlConnectionMergeAsyncAsExpandoObjectViaTableNameForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTablesAsExpandoObjects(1).First();

            using (var connection = new NpgsqlConnection(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.AreEqual(((dynamic)table).Id, result);
                Helper.AssertMembersEquality(queryResult.First(), table);
            }
        }
Пример #15
0
        public void TestNpgsqlConnectionForInsertForNpgsqlTypeMapAttribute()
        {
            // Setup
            var table = CreateAttributeTables(1).First();

            using (var connection = new NpgsqlConnection(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);
            }
        }
Пример #16
0
        public void TestNpgsqlConnectionForInsertAllForNpgsqlTypeMapAttribute()
        {
            // Setup
            var tables = CreateAttributeTables(10).AsList();

            using (var connection = new NpgsqlConnection(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)));
            }
        }
Пример #17
0
        public void TestSqlTransactionForMergeAsyncAsRolledBack()
        {
            // Setup
            var entity = Helper.CreateCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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>());
            }
        }
Пример #18
0
        public void TestSqlTransactionForInsertAsCommitted()
        {
            // Setup
            var entity = Helper.CreateCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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>());
            }
        }
Пример #19
0
        public void TestPostgreSqlConnectionInsertAllForNonIdentity()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTables(10);

            using (var connection = new NpgsqlConnection(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)));
            }
        }
Пример #20
0
        public void TestSqlTransactionForInsertAllAsRolledBack()
        {
            // Setup
            var entities = Helper.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(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>());
            }
        }
Пример #21
0
        public void TestSqlTransactionForMergeAllAsyncAsCommitted()
        {
            // Setup
            var entities = Helper.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(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>());
            }
        }
Пример #22
0
        public void TestPostgreSqlConnectionInsertAllAsyncViaTableNameAsExpandoObjectsForNonIdentity()
        {
            // Setup
            var tables = Helper.CreateNonIdentityCompleteTablesAsExpandoObjects(10);

            using (var connection = new NpgsqlConnection(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));
            }
        }
Пример #23
0
        public void TestPostgreSqlConnectionMergeAllViaTableNameAsyncForIdentityForEmptyTable()
        {
            // Setup
            var tables = Helper.CreateCompleteTables(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // 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)));
            }
        }
Пример #24
0
        public void TestPostgreSqlConnectionMergeAsyncAsDynamicViaTableNameForIdentityForEmptyTable()
        {
            // Setup
            var table = Helper.CreateCompleteTablesAsDynamics(1).First();

            using (var connection = new NpgsqlConnection(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());
            }
        }
Пример #25
0
        public void TestPostgreSqlConnectionInsertForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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());
            }
        }
Пример #26
0
        public void TestPostgreSqlConnectionInsertViaTableNameAsExpandoObjectForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTablesAsExpandoObjects(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.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 TestPostgreSqlConnectionInsertAsyncViaTableNameAsDynamicForNonIdentity()
        {
            // Setup
            var table = Helper.CreateNonIdentityCompleteTablesAsDynamics(1).First();

            using (var connection = new NpgsqlConnection(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);
            }
        }
Пример #28
0
        public void TestPostgreSqlConnectionInsertAsyncForIdentity()
        {
            // Setup
            var table = Helper.CreateCompleteTables(1).First();

            using (var connection = new NpgsqlConnection(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());
            }
        }
Пример #29
0
        public void TestPostgreSqlConnectionMergeAllAsyncAsExpandoObjectViaTableNameForIdentityForEmptyTable()
        {
            // Setup
            var tables = Helper.CreateCompleteTablesAsExpandoObjects(10);

            using (var connection = new NpgsqlConnection(Database.ConnectionString))
            {
                // Act
                var result = connection.MergeAllAsync(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
                Assert.AreEqual(tables.Count, queryResult.Count());
                tables.ForEach(table => Helper.AssertMembersEquality(queryResult.First(e => e.Id == ((dynamic)table).Id), table));
            }
        }