示例#1
0
        public void Does_call_Filters_on_Save()
        {
            var insertDate = new DateTime(2014, 1, 1);
            var updateDate = new DateTime(2015, 1, 1);

            OrmLiteConfig.InsertFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                {
                    auditRow.CreatedDate = auditRow.ModifiedDate = insertDate;
                }
            };

            OrmLiteConfig.UpdateFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                {
                    auditRow.ModifiedDate = updateDate;
                }
            };

            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <AuditTableA>();
                db.DropAndCreateTable <AuditTableB>();

                var a = new AuditTableA();
                var b = new AuditTableB();
                db.Save(a);
                db.Save(b);

                var insertRowA = db.SingleById <AuditTableA>(a.Id);
                var insertRowB = db.SingleById <AuditTableB>(b.Id);

                Assert.That(insertRowA.CreatedDate, Is.EqualTo(insertDate));
                Assert.That(insertRowA.ModifiedDate, Is.EqualTo(insertDate));

                Assert.That(insertRowB.CreatedDate, Is.EqualTo(insertDate));
                Assert.That(insertRowB.ModifiedDate, Is.EqualTo(insertDate));

                a.ModifiedBy = "Updated";
                db.Save(a);

                a = db.SingleById <AuditTableA>(a.Id);
                Assert.That(a.ModifiedDate, Is.EqualTo(updateDate));
            }

            OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = null;
        }
        public void Does_call_Filters_on_Save()
        {
            var insertDate = new DateTime(2014, 1, 1);
            var updateDate = new DateTime(2015, 1, 1);

            OrmLiteConfig.InsertFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                {
                    auditRow.CreatedDate = auditRow.ModifiedDate = insertDate;
                }
            };

            OrmLiteConfig.UpdateFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                {
                    auditRow.ModifiedDate = updateDate;
                }
            };

            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable<AuditTableA>();
                db.DropAndCreateTable<AuditTableB>();

                var a = new AuditTableA();
                var b = new AuditTableB();
                db.Save(a);
                db.Save(b);

                var insertRowA = db.SingleById<AuditTableA>(a.Id);
                var insertRowB = db.SingleById<AuditTableB>(b.Id);

                Assert.That(insertRowA.CreatedDate, Is.EqualTo(insertDate));
                Assert.That(insertRowA.ModifiedDate, Is.EqualTo(insertDate));

                Assert.That(insertRowB.CreatedDate, Is.EqualTo(insertDate));
                Assert.That(insertRowB.ModifiedDate, Is.EqualTo(insertDate));

                a.ModifiedBy = "Updated";
                db.Save(a);

                a = db.SingleById<AuditTableA>(a.Id);
                Assert.That(a.ModifiedDate, Is.EqualTo(updateDate));
            }

            OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = null;
        }