[英]Is there anyway I can load the data to the in-memory instead of using.csv files in effort for unit-testing?
Is there anyway I can load the data to the in-memory instead of using.csv files in effort for unit-testing? 无论如何,我可以将数据加载到内存中,而不是使用.csv文件进行单元测试吗?
Scenario: I want to load the data to the in-memory to use the Effort framework which creates the fake dbcontext and performs the operation. 场景:我想将数据加载到内存中,以使用Effort框架创建虚假的dbcontext并执行操作。 Instead of using Dataloader and .csv files I need to load the data programatically.
而不是使用Dataloader和.csv文件,我需要以编程方式加载数据。
Sample code which works fine with .csv files: 与.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);
I am just looking for something replacement to load the data instead of loading the data using .csv files 我只是在寻找替代方法来加载数据,而不是使用.csv文件加载数据
You could create a Transient/Persistent DbConnection
without a DataLoader, use it in your DbContext
, then programmatically push your generated data into the context. 您可以创建一个不带DataLoader的暂态/持久性
DbConnection
,在DbContext
使用它,然后以编程方式将生成的数据推送到上下文中。
See: https://tflamichblog.wordpress.com/2012/11/04/factory-methods-in-effort-createtransient-vs-createpersistent 参见: https : //tflamichblog.wordpress.com/2012/11/04/factory-methods-in-effort-createtransient-vs-createpersistent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.