private static (IQueryable <Order>, IDisposable) BuildOrdersLinq2DbContext() { var connection = new SqliteConnection("DataSource=:memory:"); try { connection.Open(); var linq2Db = new OrderLinq2Db(connection); linq2Db.CreateTable <Employee>(); foreach (var employee in TestSamples.GetEmployees()) { linq2Db.Insert(employee); } linq2Db.CreateTable <Order>(); foreach (var order in TestSamples.GetOrders()) { linq2Db.Insert(order); } return(linq2Db.Orders, connection); } catch { connection.Dispose(); throw; } }
public IEnumerator <object[]> GetEnumerator() { var employees = TestSamples.GetEmployees(); yield return(new object[] { TestSamples.GetOrders().Select( (o) => { o.Manager = employees.FirstOrDefault(e => e.Id == o.ManagerId); return o; }).AsQueryable(), new DisposableMock() }); var(efQueryable, efConnection) = OrderQueryableGenerator.BuildOrdersEfContext(); yield return(new object[] { efQueryable, efConnection }); var(linq2dbQueryable, linq2dbConnection) = OrderQueryableGenerator.BuildOrdersLinq2DbContext(); yield return(new object[] { linq2dbQueryable, linq2dbConnection }); }
private static (IQueryable <Order>, IDisposable) BuildOrdersEfContext() { var connection = new SqliteConnection("DataSource=:memory:"); try { connection.Open(); var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseSqlite(connection) .Options; var context = new OrdersDbContext(options); var databaseCreator = (RelationalDatabaseCreator)context.Database.GetService <IDatabaseCreator>(); databaseCreator.CreateTables(); context.Employees.AddRange(TestSamples.GetEmployees()); context.Orders.AddRange(TestSamples.GetOrders()); context.SaveChanges(); return(context.Orders, connection); } catch { connection.Dispose(); throw; } }