在Startup类中,我向ConfigureServices方法添加了一些配置。例如,我添加了AutoMapper
public virtual void ConfigureServices(IServiceCollection services)
{
services.AddAutoMapper();
services.AddMvc();
}
我的类TestFixture为集成测试配置环境。
public class TestFixture : IDisposable
{
private readonly IContainer _container;
public TestFixture()
{
var server = new TestServer(new WebHostBuilder()
.UseStartup<TestStartup>()
.ConfigureServices(services => services.AddAutofac()));
var builder = new ContainerBuilder();
builder.RegisterModule(new TestModule());
_container = builder.Build();
}
public TEntity Resolve<TEntity>()
{
return _container.Resolve<TEntity>();
}
public void Dispose()
{
_container.Dispose();
OasisDataContext.Dispose();
}
}
如果没有ServiceFixture类中的services.AddAutoMapper(),AutoMapper将无法工作,但Startup类具有AutoMapper的配置。 如果TestStartup派生自Startup类,为什么集成测试不使用Startup服务的配置?