public async Task Z_Test_0110() { Helper.CleanDatabase(); var single1 = new SingleMany { ColumnInt = 1 }; var single2 = new SingleMany { ColumnInt = 8 }; var single3 = new SingleMany { ColumnInt = 64 }; var many1 = new List <SingleMany> { new SingleMany { ColumnInt = 512 }, new SingleMany { ColumnInt = 1024 }, new SingleMany { ColumnInt = 2048 } }; var many2 = new List <SingleMany> { new SingleMany { ColumnInt = 4096 }, new SingleMany { ColumnInt = 8192 }, new SingleMany { ColumnInt = 16384 } }; var many3 = new List <SingleMany> { new SingleMany { ColumnInt = 32768 }, new SingleMany { ColumnInt = 65536 }, new SingleMany { ColumnInt = 131072 } }; Helper.LinkSingleMany(single1, single2, single3, many1, many2, many3); Helper.InsertFromMetas("BulkInsertAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3); Helper.UpdateFromMetas("BulkInsertAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3); // GET count before int columnInt_before = 0; int columnUpdateInt_before = 0; int columnInt_Key_before = 0; int columnUpdateInt_Key_before = 0; using (var connection = Helper.GetConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)"; columnInt_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)"; columnUpdateInt_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)"; columnInt_Key_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)"; columnUpdateInt_Key_before = Convert.ToInt32(command.ExecuteScalar()); } } using (var cn = Helper.GetConnection()) { cn.Open(); // PreTest // Action await cn.BulkActionAsync(action => action.BulkDelete(single1, x => x.Single2, x => x.Single3)); } // GET count int columnInt = 0; int columnUpdateInt = 0; int columnInt_Key = 0; int columnUpdateInt_Key = 0; using (var connection = Helper.GetConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)"; columnInt = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)"; columnUpdateInt = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)"; columnInt_Key = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)"; columnUpdateInt_Key = Convert.ToInt32(command.ExecuteScalar()); } } // Test Assert.AreEqual(columnInt_before - single1.ColumnInt - single2.ColumnInt - single3.ColumnInt, columnInt); Assert.AreEqual(columnUpdateInt_before, columnUpdateInt); Assert.AreEqual(columnInt_Key_before, columnInt_Key); Assert.AreEqual(columnUpdateInt_Key_before, columnUpdateInt_Key); }
public void Z_Test_0161() { Helper.CleanDatabase(); var single1 = new SingleMany { ColumnInt = 1 }; var single2 = new SingleMany { ColumnInt = 8 }; var single3 = new SingleMany { ColumnInt = 64 }; var many1 = new List <SingleMany> { new SingleMany { ColumnInt = 512 }, new SingleMany { ColumnInt = 1024 }, new SingleMany { ColumnInt = 2048 } }; var many2 = new List <SingleMany> { new SingleMany { ColumnInt = 4096 }, new SingleMany { ColumnInt = 8192 }, new SingleMany { ColumnInt = 16384 } }; var many3 = new List <SingleMany> { new SingleMany { ColumnInt = 32768 }, new SingleMany { ColumnInt = 65536 }, new SingleMany { ColumnInt = 131072 } }; Helper.LinkSingleMany(single1, single2, single3, many1, many2, many3); Helper.InsertFromMetas("BulkInsert2;BulkInsert3;UpdateValue2;UpdateValue3".Split(';').ToList(), single1, single2, single3, many1, many2, many3); Helper.UpdateFromMetas("BulkInsert2;BulkInsert3;UpdateValue2;UpdateValue3".Split(';').ToList(), single1, single2, single3, many1, many2, many3); // GET count before int columnInt_before = 0; int columnUpdateInt_before = 0; int columnInt_Key_before = 0; int columnUpdateInt_Key_before = 0; using (var connection = Helper.GetConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)"; columnInt_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)"; columnUpdateInt_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)"; columnInt_Key_before = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)"; columnUpdateInt_Key_before = Convert.ToInt32(command.ExecuteScalar()); } } using (var cn = Helper.GetConnection()) { cn.Open(); // PreTest // Action cn.BulkMerge(single1, x => x.Many1, x => x.Many2, x => x.Many3); } // GET count int columnInt = 0; int columnUpdateInt = 0; int columnInt_Key = 0; int columnUpdateInt_Key = 0; using (var connection = Helper.GetConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)"; columnInt = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)"; columnUpdateInt = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)"; columnInt_Key = Convert.ToInt32(command.ExecuteScalar()); command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)"; columnUpdateInt_Key = Convert.ToInt32(command.ExecuteScalar()); } } // Test Assert.AreEqual(columnInt_before + single1.ColumnInt + many1.Sum(x => x.ColumnInt), columnInt); Assert.AreEqual(many2.Sum(x => x.ColumnInt) + many3.Sum(x => x.ColumnInt), columnUpdateInt); Assert.AreEqual(columnInt_Key_before, columnInt_Key); Assert.AreEqual(columnUpdateInt_Key_before, columnUpdateInt_Key); }
public void Z_Test_0041() { // Title2: IdentityMany_IdentityManyDestination Helper.CleanDatabase(); var singleBefore = new EntitySimple_Mapper { Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40 }; var single = new EntitySimple_Mapper { Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40 }; using (var cn = Helper.GetConnection()) { cn.Open(); // PreTest // Action DapperPlusManager.Entity <EntitySimple_Mapper>("23804ec2-fa4d-4868-9682-7b942278c464").Table("EntitySimple_TriggerOutput").Identity(x => new { x.Many1, x.Many2 }).Identity(x => new { Many3_Destination = x.Many3, Many4_Destination = x.Many4 }); cn.BulkInsert("23804ec2-fa4d-4868-9682-7b942278c464", single); } // GET count int single1 = 0; int single2 = 0; int many1 = 0; int many2 = 0; int many3 = 0; int many4 = 0; int single1_Destination = 0; int single2_Destination = 0; int many1_Destination = 0; int many2_Destination = 0; int many3_Destination = 0; int many4_Destination = 0; using (var connection = Helper.GetConnection()) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @" SELECT TOP 1 [Single1] , [Single2] , [Many1] , [Many2] , [Many3] , [Many4] , [Single1_Destination] , [Single2_Destination] , [Many1_Destination] , [Many2_Destination] , [Many3_Destination] , [Many4_Destination] " + "FROM [Z.Dapper.Plus].[dbo].[EntitySimple_TriggerOutput]"; using (var reader = command.ExecuteReader()) { reader.Read(); single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0); single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1); many1 = reader.IsDBNull(2) ? 0 : reader.GetInt32(2); many2 = reader.IsDBNull(3) ? 0 : reader.GetInt32(3); many3 = reader.IsDBNull(4) ? 0 : reader.GetInt32(4); many4 = reader.IsDBNull(5) ? 0 : reader.GetInt32(5); single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6); single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7); many1_Destination = reader.IsDBNull(8) ? 0 : reader.GetInt32(8); many2_Destination = reader.IsDBNull(9) ? 0 : reader.GetInt32(9); many3_Destination = reader.IsDBNull(10) ? 0 : reader.GetInt32(10); many4_Destination = reader.IsDBNull(11) ? 0 : reader.GetInt32(11); } } } // Test Assert.AreEqual(singleBefore.Single1, single.Single1); Assert.AreEqual(singleBefore.Single2, single.Single2); Assert.AreEqual(-singleBefore.Many1, single.Many1); Assert.AreEqual(-singleBefore.Many2, single.Many2); Assert.AreEqual(-singleBefore.Many3 * 100, single.Many3); Assert.AreEqual(-singleBefore.Many4 * 100, single.Many4); }