从 IdentityDbContext<T> 继承会减慢测试速度
inheriting from IdentityDbContext<T> slows down tests
我有一个 运行 我正在使用的工厂 dbcontext,然后我开始实施 .net Identity(Microsoft.AspNet.Identity.Core,Microsoft.AspNet.Identity.EntityFramework)并想到 "oh look, its based on dbcontext, I'll just attach that to my existing context"。
所以这个...
public class SomeContext : DbContext {
public SomeContext() : base("DefaultConnection"){ }
}
干脆翻到这个...
public class SomeContext : IdentityDbContext<ApplicationUser> {
public SomeContext() : base("DefaultConnection") {}
}
一切都很好,站点 运行 完全没有问题...但是测试时间从大约 1 秒缩短到大约 2 分钟。如果我将其切换回去,它会立即返回到简短测试 运行s,所以我想我可能遗漏了一些东西,或者发生了其他我不完全了解的事情。
有什么想法吗?
改变
public SomeContext() : base("DefaultConnection") {}
到
public SomeContext() : base("DefaultConnection", false) {}
这个额外的布尔值将使 IdentityDbContext<ApplicationUser>
不检查身份表的连接。这将加快测试速度。
我有一个 运行 我正在使用的工厂 dbcontext,然后我开始实施 .net Identity(Microsoft.AspNet.Identity.Core,Microsoft.AspNet.Identity.EntityFramework)并想到 "oh look, its based on dbcontext, I'll just attach that to my existing context"。
所以这个...
public class SomeContext : DbContext {
public SomeContext() : base("DefaultConnection"){ }
}
干脆翻到这个...
public class SomeContext : IdentityDbContext<ApplicationUser> {
public SomeContext() : base("DefaultConnection") {}
}
一切都很好,站点 运行 完全没有问题...但是测试时间从大约 1 秒缩短到大约 2 分钟。如果我将其切换回去,它会立即返回到简短测试 运行s,所以我想我可能遗漏了一些东西,或者发生了其他我不完全了解的事情。
有什么想法吗?
改变
public SomeContext() : base("DefaultConnection") {}
到
public SomeContext() : base("DefaultConnection", false) {}
这个额外的布尔值将使 IdentityDbContext<ApplicationUser>
不检查身份表的连接。这将加快测试速度。