public void MuiltChangeTest() { var unitOfWorkObj = new EfUnitOfWork();//{ DbContextFactory = _dbContextFactory }; var unitOfWorkDbContextFactory = new DefualtDbContextFactory() { UnitOfWork = unitOfWorkObj }; var orderRepo = new FakeOrderRepository() { DbContextFactory = unitOfWorkDbContextFactory }; var productRepo = new FakeProductRepository() { DbContextFactory = unitOfWorkDbContextFactory }; var userRepo = new FakeUserRepository() { DbContextFactory = unitOfWorkDbContextFactory }; unitOfWorkObj.BeginTransaction(new UnitOfWorkOptions()); try { //orderRepo.Insert(FakeOrder.Fake()); productRepo.Insert(FakeProduct.Fake()); userRepo.Insert(FakeUser.Fake()); unitOfWorkObj.Commit(); } catch (Exception ex) { unitOfWorkObj.RollBack(); Assert.Fail("发生异常:" + ex.Message); } finally { unitOfWorkObj.Dispose(); } }