Example #1
0
        public async Task SqlBulkTools_Update_CustomColumnMapping()
        {
            BulkOperations bulk = new BulkOperations();

            List <CustomColumnMappingTest> col = new List <CustomColumnMappingTest>();

            for (int i = 0; i < 30; i++)
            {
                col.Add(new CustomColumnMappingTest()
                {
                    NaturalId = i, ColumnXIsDifferent = "ColumnX " + i, ColumnYIsDifferentInDatabase = i
                });
            }

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalId                    = 1,
                ColumnXIsDifferent           = "ColumnX " + 1,
                ColumnYIsDifferentInDatabase = 1
            };

            _db.CustomColumnMappingTest.RemoveRange(_db.CustomColumnMappingTest.ToList());
            _db.SaveChanges();

            using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    await bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .Insert()
                    .CommitAsync(conn);

                    customColumn.ColumnXIsDifferent = "updated";


                    await bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .Update()
                    .Where(x => x.NaturalId == 1)
                    .CommitAsync(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.IsTrue(_db.CustomColumnMappingTest.First().ColumnXIsDifferent == "updated");
        }
        public void SqlBulkTools_Update_CustomColumnMapping()
        {
            BulkOperations bulk = new BulkOperations();

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalIdTest                = 1,
                ColumnXIsDifferent           = "ColumnX " + 1,
                ColumnYIsDifferentInDatabase = 1
            };

            using (TransactionScope trans = new TransactionScope())
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    bulk.Setup <CustomColumnMappingTest>()
                    .ForDeleteQuery()
                    .WithTable("CustomColumnMappingTests")
                    .Delete()
                    .AllRecords()
                    .Commit(conn);

                    bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Insert()
                    .Commit(conn);

                    customColumn.ColumnXIsDifferent = "updated";


                    bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Update()
                    .Where(x => x.NaturalIdTest == 1, "database_default")
                    .Commit(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.IsTrue(_dataAccess.GetCustomColumnMappingTests().First().ColumnXIsDifferent == "updated");
        }
Example #3
0
        public async Task SqlBulkTools_Insert_CustomColumnMapping()
        {
            BulkOperations bulk = new BulkOperations();

            List <CustomColumnMappingTest> col = new List <CustomColumnMappingTest>();

            for (int i = 0; i < 30; i++)
            {
                col.Add(new CustomColumnMappingTest()
                {
                    NaturalIdTest = i, ColumnXIsDifferent = "ColumnX " + i, ColumnYIsDifferentInDatabase = i
                });
            }

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalIdTest                = 1,
                ColumnXIsDifferent           = $"ColumnX 1",
                ColumnYIsDifferentInDatabase = 1
            };

            using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    bulk.Setup <CustomColumnMappingTest>()
                    .ForDeleteQuery()
                    .WithTable("CustomColumnMappingTests")
                    .Delete()
                    .AllRecords()
                    .Commit(conn);

                    await bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Insert()
                    .CommitAsync(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.IsTrue(_dataAccess.GetCustomColumnMappingTests().First().ColumnXIsDifferent == "ColumnX 1");
        }
Example #4
0
        public void SqlBulkTools_Insert_CustomColumnMapping()
        {
            var bulk = new BulkOperations();

            var col = new List <CustomColumnMappingTest>();

            for (var i = 0; i < 30; i++)
            {
                col.Add(new CustomColumnMappingTest()
                {
                    NaturalIdTest = i, ColumnXIsDifferent = "ColumnX " + i, ColumnYIsDifferentInDatabase = i
                });
            }

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalIdTest                = 1,
                ColumnXIsDifferent           = $"ColumnX 1",
                ColumnYIsDifferentInDatabase = 1
            };

            using (var trans = new TransactionScope())
            {
                using (var conn = new SqlConnection(_dataAccess.ConnectionString))
                {
                    bulk.Setup <CustomColumnMappingTest>()
                    .ForDeleteQuery()
                    .WithTable("CustomColumnMappingTests")
                    .Delete()
                    .AllRecords()
                    .Commit(conn);

                    bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Insert()
                    .Commit(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.True(_dataAccess.GetCustomColumnMappingTests().First().ColumnXIsDifferent == "ColumnX 1");
        }
Example #5
0
        public async Task SqlBulkTools_Upsert_CustomColumnMapping()
        {
            BulkOperations bulk = new BulkOperations();

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalIdTest                = 1,
                ColumnXIsDifferent           = "ColumnX " + 1,
                ColumnYIsDifferentInDatabase = 3
            };

            using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    bulk.Setup <CustomColumnMappingTest>()
                    .ForDeleteQuery()
                    .WithTable("CustomColumnMappingTests")
                    .Delete()
                    .AllRecords()
                    .Commit(conn);

                    await bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Upsert()
                    .MatchTargetOn(x => x.NaturalIdTest)
                    .CommitAsync(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.IsTrue(_dataAccess.GetCustomColumnMappingTests().First().ColumnYIsDifferentInDatabase == 3);
        }
Example #6
0
        public void SqlBulkTools_Upsert_CustomColumnMapping()
        {
            var bulk = new BulkOperations();

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalIdTest                = 1,
                ColumnXIsDifferent           = "ColumnX " + 1,
                ColumnYIsDifferentInDatabase = 3
            };

            using (var trans = new TransactionScope())
            {
                using (var conn = new SqlConnection(_dataAccess.ConnectionString))
                {
                    bulk.Setup <CustomColumnMappingTest>()
                    .ForDeleteQuery()
                    .WithTable("CustomColumnMappingTests")
                    .Delete()
                    .AllRecords()
                    .Commit(conn);

                    bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .CustomColumnMapping(x => x.NaturalIdTest, "NaturalId")
                    .Upsert()
                    .MatchTargetOn(x => x.NaturalIdTest)
                    .Commit(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.True(_dataAccess.GetCustomColumnMappingTests().First().ColumnYIsDifferentInDatabase == 3);
        }
Example #7
0
        public async Task SqlBulkTools_Upsert_CustomColumnMapping()
        {
            BulkOperations bulk = new BulkOperations();

            var customColumn = new CustomColumnMappingTest()
            {
                NaturalId                    = 1,
                ColumnXIsDifferent           = "ColumnX " + 1,
                ColumnYIsDifferentInDatabase = 3
            };

            _db.CustomColumnMappingTest.RemoveRange(_db.CustomColumnMappingTest.ToList());
            _db.SaveChanges();

            using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager
                                                              .ConnectionStrings["SqlBulkToolsTest"].ConnectionString))
                {
                    await bulk.Setup <CustomColumnMappingTest>()
                    .ForObject(customColumn)
                    .WithTable("CustomColumnMappingTests")
                    .AddAllColumns()
                    .CustomColumnMapping(x => x.ColumnXIsDifferent, "ColumnX")
                    .CustomColumnMapping(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                    .Upsert()
                    .MatchTargetOn(x => x.NaturalId)
                    .CommitAsync(conn);
                }

                trans.Complete();
            }

            // Assert
            Assert.IsTrue(_db.CustomColumnMappingTest.First().ColumnYIsDifferentInDatabase == 3);
        }