- 增加 Aop.AuditValue 事件,在插入/更新数据时审计属性值;

This commit is contained in:
28810
2019-08-25 18:13:02 +08:00
parent baa6c413a0
commit b57d35ae9b
12 changed files with 344 additions and 9 deletions

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Xunit;
namespace FreeSql.Tests.MySqlConnector
{
public class MySqlAop
{
class TestAuditValue
{
public Guid id { get; set; }
[Now]
public DateTime createtime { get; set; }
}
class NowAttribute: Attribute { }
[Fact]
public void AuditValue()
{
var now = DateTime.Now;
var item = new TestAuditValue();
EventHandler<Aop.AuditValueEventArgs> audit = (s, e) =>
{
if (e.Property.GetCustomAttribute<NowAttribute>(false) != null)
e.Value = DateTime.Now;
};
g.mysql.Aop.AuditValue += audit;
g.mysql.Insert(item).ExecuteAffrows();
g.mysql.Aop.AuditValue -= audit;
Assert.Equal(item.createtime.Date, now.Date);
}
}
}