我目前正在使用 EF Core 提供的内存数据库对我的存储库模式进行单元/集成测试。我使用的是 Microsoft.EntityFrameworkCore.InMemory nuget 版本 6.0.1,并使用 Visual Studio 2022。我在将数据保存到数据库时遇到问题。下面我包含了我的代码片段。
public class Example : IExample
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
Run Code Online (Sandbox Code Playgroud)
public class Repository<T> : IRepository<T> where T : class
private readonly DbSet<T> _dbSet;
private readonly DbContext _db;
public Repository(DbContext db)
{
_dbSet = db.Set<T>();
_db = db;
}
public virtual async Task Add(T entity)
{
await _dbSet.AddAsync(entity);
}
public virtual …Run Code Online (Sandbox Code Playgroud) c# integration-testing unit-testing entity-framework-core asp.net-core