Tag: 单元

unit testing异步操作

我想unit testing我执行的方法和异步操作: Task.Factory.StartNew(() => { // method to test and return value var result = LongRunningOperation(); }); 我在unit testing中编写必要的方法等(用c#编写),但问题是在断言测试之前异步操作没有完成。 我怎么能绕过这个? 我应该创建TaskFactory的模拟或任何其他unit testing异步操作的技巧吗?

如何使用构造函数dependency injectionunit testingasp.net核心应用程序

我有一个asp.net核心应用程序,它使用在应用程序的startup.cs类中定义的dependency injection: public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlServer(Configuration[“Data:FotballConnection:DefaultConnection”])); // Repositories services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // Services services.AddScoped(); services.AddScoped(); // new repos services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); 这允许这样的事情: [Route(“api/[controller]”)] public class MatchController : AuthorizedController { private readonly IMatchService _matchService; private readonly IMatchRepository _matchRepository; private readonly IMatchBetRepository _matchBetRepository; private readonly IUserRepository _userRepository; private readonly ILoggingRepository […]