Is there anyway I can load the data to the in-memory instead of using.csv files in effort for unit-testing?

csv effort entity-framework nunit unit-testing

Question

Is there anyway I can load the data to the in-memory instead of using.csv files in effort for unit-testing?

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. Instead of using Dataloader and .csv files I need to load the data programatically.

Sample code which works fine with .csv files:

        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

Popular Answer

You could create a Transient/Persistent DbConnection without a DataLoader, use it in your DbContext, then programmatically push your generated data into the context.

See: https://tflamichblog.wordpress.com/2012/11/04/factory-methods-in-effort-createtransient-vs-createpersistent




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why