我正在我的 RepositoryFunctionalTest 中运行测试,但是当我运行所有程序时出现错误我遇到了这个错误:
System.InvalidOperationException :
在上一个操作完成之前,在此上下文实例上启动了第二个操作。这通常是由不同的线程同时使用同一个 DbContext 实例引起的。
情况是我正在将存储库从 .NET Core 3.1 升级到 .NET 6.0.
public class ZipCodeContext : DbContext
{
public ZipCodeContext(DbContextOptions<ZipCodeContext> options) : base(options)
{ }
public DbSet<CountryEntity> Countries { get; set; }
public DbSet<StateEntity> States { get; set; }
public DbSet<CountyEntity> Counties { get; set; }
public DbSet<ZipCodeEntity> ZipCodes { get; set; }
public DbSet<ImportReportEntity> ImportReports { get; set; }
这是我出错的地方
[Fact]
public async Task GetStates()
{
using (var server = CreateServer())
using (var stream = File.OpenRead(Path.Combine(Environment.CurrentDirectory,
@"../../../TestFiles/USA-5Digit-CAN-6Digit-TEST-A.csv")))
{
var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name));
await Execute(file, server);
var response = await server.CreateClient().GetAsync(Get.GetStates("&sorts=''&filters=statecode==NH"));
var jsonString = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<PaginatedResponse<State>>(jsonString, serializerOptions);
Assert.Equal(1, result.Data.Count);
}
}