无论如何我可以将数据加载到内存而不是使用.csv文件来进行单元测试吗?
场景:我想将数据加载到内存中以使用Effort框架,该框架创建伪dbcontext并执行操作。我需要以编程方式加载数据,而不是使用Dataloader和.csv文件。
与.csv文件一起使用的示例代码:
IDataLoader loader = new Effort.DataLoaders.CsvDataLoader("D:\\csv");
var dataLoader = new CachingDataLoader(loader, false);
DbConnection connection = Effort.DbConnectionFactory.CreateTransient(dataLoader);
DbContext mockedDbContext = new NopObjectContext(connection);
EfRepository<Shelf> _shelEfRepository = new EfRepository<Shelf>(mockedDbContext);
EfRepository<ProductVariant> _productVariantEfRepository = new EfRepository<ProductVariant>(mockedDbContext);
EfRepository<Product> _productEfRepository = new EfRepository<Product>(mockedDbContext);
_shelfService = new ShelfService(_shelEfRepository, _productVariantEfRepository, _productEfRepository);
我只是在寻找替代加载数据而不是使用.csv文件加载数据的东西
您可以在没有 DataLoader的情况下创建Transient / Persistent DbConnection
,在DbContext
使用它,然后以编程方式将生成的数据推送到上下文中。
请参阅: https : //tflamichblog.wordpress.com/2012/11/04/factory-methods-in-effort-createtransient-vs-createpersistent