Entity Framework教程-测试(Unit Testing, Integration Testing, and Mocking)
更新记录
转载请注明出处:
2022年10月25日 发布。
2022年10月22日 从笔记迁移到博客。
生成测试数据(seed data)
说明
有几种方法可以创建模拟数据:
使用Fluent API
OnModelCreating方法中触发创建数据
使用Fluent API
OnModelCreating方法中触发创建数据
modelBuilder.Entity<Genre>(x => {
x.HasData(
new Genre() { Id = 1, CreatedDate = DateTime.Now, IsActive = true, IsDeleted = false, Name = "Fantasy" },
new Genre() { Id = 2, CreatedDate = DateTime.Now, IsActive = true, IsDeleted = false, Name = "Sci/Fi" },
new Genre() { Id = 3, CreatedDate = DateTime.Now, IsActive = true, IsDeleted = false, Name = "Horror" },
new Genre() { Id = 4, CreatedDate = DateTime.Now, IsActive = true, IsDeleted = false, Name = "Comedy" },
new Genre() { Id = 5, CreatedDate = DateTime.Now, IsActive = true, IsDeleted = false, Name = "Drama" }
);
});
本文来自博客园,作者:重庆熊猫,转载请注明原文链接:https://www.cnblogs.com/cqpanda/p/16815266.html