無論如何我可以將數據加載到內存而不是使用.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