U:调整所有代码格式
This commit is contained in:
1 parent
d133bacf55
commit
155b67e831
342 files changed
+9431
-9868
No files matched your search
@@ -27,8 +27,8 @@ public class _03_AuditFeatureTests
|
||||
// 创建启用审计功能的 DataContext
|
||||
var builder = new DataContextBuilder<TestDbContext>();
|
||||
builder.UseInMemoryDatabase($"AuditCreateDemo_{Guid.NewGuid()}")
|
||||
.UseAudit(true) // 启用审计
|
||||
.UseCurrentUser("zhang.san"); // 设置当前用户
|
||||
.UseAudit(true) // 启用审计
|
||||
.UseCurrentUser("zhang.san"); // 设置当前用户
|
||||
|
||||
using var db = builder.Build();
|
||||
var repo = db.Repository<Product>();
|
||||
@@ -49,7 +49,7 @@ public class _03_AuditFeatureTests
|
||||
Console.WriteLine($" CreatedBy: {product.CreatedBy ?? "(null)"}");
|
||||
|
||||
await repo.AddAsync(product);
|
||||
await db.SaveChangesAsync(); // SaveChanges 时自动填充审计信息
|
||||
await db.SaveChangesAsync(); // SaveChanges 时自动填充审计信息
|
||||
|
||||
var afterCreate = DateTime.UtcNow;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class _03_AuditFeatureTests
|
||||
// 验证
|
||||
Assert.IsTrue(product.CreatedAt >= beforeCreate && product.CreatedAt <= afterCreate);
|
||||
Assert.AreEqual("zhang.san", product.CreatedBy);
|
||||
Assert.IsNull(product.UpdatedAt); // 创建时 UpdatedAt 为 null
|
||||
Assert.IsNull(product.UpdatedAt); // 创建时 UpdatedAt 为 null
|
||||
Assert.IsNull(product.UpdatedBy);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class _03_AuditFeatureTests
|
||||
product.Name = "更新后的产品";
|
||||
product.Price = 200m;
|
||||
repo.Update(product);
|
||||
await db.SaveChangesAsync(); // SaveChanges 时自动填充 UpdatedAt 和 UpdatedBy
|
||||
await db.SaveChangesAsync(); // SaveChanges 时自动填充 UpdatedAt 和 UpdatedBy
|
||||
|
||||
Console.WriteLine("\n更新后的审计信息:");
|
||||
Console.WriteLine($" CreatedBy: {product.CreatedBy} (保持不变)");
|
||||
@@ -117,11 +117,11 @@ public class _03_AuditFeatureTests
|
||||
Console.WriteLine($" ✓ UpdatedAt: {product.UpdatedAt:yyyy-MM-dd HH:mm:ss}");
|
||||
|
||||
// 验证
|
||||
Assert.AreEqual(createdBy, product.CreatedBy); // 创建人不变
|
||||
Assert.AreEqual(createdAt, product.CreatedAt); // 创建时间不变
|
||||
Assert.AreEqual("editor", product.UpdatedBy); // 更新人是新用户
|
||||
Assert.AreEqual(createdBy, product.CreatedBy); // 创建人不变
|
||||
Assert.AreEqual(createdAt, product.CreatedAt); // 创建时间不变
|
||||
Assert.AreEqual("editor", product.UpdatedBy); // 更新人是新用户
|
||||
Assert.IsNotNull(product.UpdatedAt);
|
||||
Assert.IsTrue(product.UpdatedAt > product.CreatedAt); // 更新时间晚于创建时间
|
||||
Assert.IsTrue(product.UpdatedAt > product.CreatedAt); // 更新时间晚于创建时间
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -167,9 +167,9 @@ public class _03_AuditFeatureTests
|
||||
Console.WriteLine($"第2次更新: {product.UpdatedBy} 于 {product.UpdatedAt:HH:mm:ss}");
|
||||
|
||||
// 验证
|
||||
Assert.AreEqual("user1", product.CreatedBy); // 创建人始终不变
|
||||
Assert.AreEqual("user3", product.UpdatedBy); // 最后更新人
|
||||
Assert.IsTrue(product.UpdatedAt > firstUpdateTime); // 更新时间在变化
|
||||
Assert.AreEqual("user1", product.CreatedBy); // 创建人始终不变
|
||||
Assert.AreEqual("user3", product.UpdatedBy); // 最后更新人
|
||||
Assert.IsTrue(product.UpdatedAt > firstUpdateTime); // 更新时间在变化
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -215,8 +215,8 @@ public class _03_AuditFeatureTests
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
Console.WriteLine($"✓ 更新人: {product.UpdatedBy}");
|
||||
Assert.AreEqual("zhang.san", product.CreatedBy); // 创建人不变
|
||||
Assert.AreEqual("li.si", product.UpdatedBy); // 更新人改变
|
||||
Assert.AreEqual("zhang.san", product.CreatedBy); // 创建人不变
|
||||
Assert.AreEqual("li.si", product.UpdatedBy); // 更新人改变
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,7 +263,7 @@ public class _03_AuditFeatureTests
|
||||
{
|
||||
var builder = new DataContextBuilder<TestDbContext>();
|
||||
builder.UseInMemoryDatabase($"NoAuditDemo_{Guid.NewGuid()}")
|
||||
.UseAudit(true) // 即使启用了审计功能
|
||||
.UseAudit(true) // 即使启用了审计功能
|
||||
.UseCurrentUser("admin");
|
||||
|
||||
using var db = builder.Build();
|
||||
@@ -290,7 +290,7 @@ public class _03_AuditFeatureTests
|
||||
{
|
||||
var builder = new DataContextBuilder<TestDbContext>();
|
||||
builder.UseInMemoryDatabase($"DisableAuditDemo_{Guid.NewGuid()}")
|
||||
.UseAudit(false) // 禁用审计功能
|
||||
.UseAudit(false) // 禁用审计功能
|
||||
.UseCurrentUser("admin");
|
||||
|
||||
using var db = builder.Build();
|
||||
@@ -368,4 +368,4 @@ public class _03_AuditFeatureTests
|
||||
Console.WriteLine($" - 谁最后修改:{product.UpdatedBy}");
|
||||
Console.WriteLine($" - 何时修改:{product.UpdatedAt:yyyy-MM-dd HH:mm:ss}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user