Beispiel #1
0
        public void Insert系_Insert_キー重複エラーEntity()
        {
            var ex = Assert.Throws <MySqlException>(() =>
            {
                using (var db = new DB())
                {
                    db.BeginTransaction();

                    var rec = new PtTable01
                    {
                        Key01      = "02",
                        ColBool    = true,
                        ColInt     = 123,
                        ColDec     = 987654.32m,
                        ColVarchar = "Insert'テスト'その2",
                        CreateBy   = "pt_test001",
                        CreateDt   = DateTime.Now,
                        UpdateBy   = "pt_test001",
                        UpdateDt   = DateTime.Now,
                    };
                    db.Insert(rec);
                }
            });

            _output.WriteLine(ex.ToString());
            Assert.Equal(1062, ex.Number);
        }
Beispiel #2
0
        public void Insert系_Transaction_Commit()
        {
            using (var db = new DB())
            {
                db.BeginTransaction();

                var rec = new PtTable01
                {
                    Key01      = "95",
                    ColBool    = true,
                    ColInt     = 123,
                    ColDec     = 987654.32m,
                    ColVarchar = "Transactionテスト",
                    CreateBy   = "pt_test001",
                    CreateDt   = DateTime.Parse("2018/12/18 18:00:00"),
                    UpdateBy   = "pt_test001",
                    UpdateDt   = DateTime.Parse("2018/12/18 18:00:00"),
                };
                db.Insert(rec);

                //db.CompleteTransaction();
                var rec2 = db.SingleById <PtTable01>("95");
                Assert.True(rec2.ColBool);
                Assert.Equal(123, rec2.ColInt.Value);
                Assert.Equal(987654.32m, rec2.ColDec.Value);
                Assert.Equal("Transactionテスト", rec2.ColVarchar);
                Assert.Equal("pt_test001", rec2.CreateBy);
                Assert.Equal(DateTime.Parse("2018/12/18 18:00:00"), rec2.CreateDt);
            }
        }
Beispiel #3
0
        public void Insert系_Transaction_Rollback()
        {
            using (var db = new DB())
            {
                db.BeginTransaction();

                var rec = new PtTable01
                {
                    Key01      = "96",
                    ColBool    = true,
                    ColInt     = 123,
                    ColDec     = 987654.32m,
                    ColVarchar = "Transactionテスト",
                    CreateBy   = "pt_test001",
                    CreateDt   = DateTime.Parse("2018/12/18 18:00:00"),
                    UpdateBy   = "pt_test001",
                    UpdateDt   = DateTime.Parse("2018/12/18 18:00:00"),
                };
                db.Insert(rec);

                db.AbortTransaction();

                var rec2 = db.SingleOrDefaultById <PtTable01>("96");
                Assert.Null(rec2);
            }
        }
Beispiel #4
0
        public void Update系_変更列のみ更新_NewRec_PK引数なし_列引数なし()
        {
            using (var db = new DB())
            {
                db.BeginTransaction();

                // レコード内にPK値も持つ
                var rec = new PtTable01
                {
                    Key01      = "13",
                    ColVarchar = "1234567890",
                };

                var cnt = db.Update(rec);       // PKはレコード内にあるパターン
                _output.WriteLine(db.LastCommand);

                Assert.Equal(1, cnt);

                var sql = db.LastSQL;

                // これは含まれるべき文字列
                Assert.Contains("ColVarchar", sql);

                // 含まれてはいけない文字列
                Assert.DoesNotContain("ColBool", sql);
                Assert.DoesNotContain("ColInt", sql);
                Assert.DoesNotContain("ColDec", sql);
                Assert.DoesNotContain("CreateBy", sql);
                Assert.DoesNotContain("UpdateDt", sql);
            }
        }