public void MuiltChangeTest() { var unitOfWorkObj = new EfUnitOfWork(null /*ILogger*/); //{ DbContextFactory = _dbContextFactory }; var uoWdbContextProvider = new EfUnitOfWorkDbContextProvider(new EfUnitOfWorkManager(IoCManager, null /*ILogger*/), IoCManager, null /*ILogger*/); var orderRepo = new FakeOrderRepository(uoWdbContextProvider); var productRepo = new FakeProductRepository(uoWdbContextProvider); var userRepo = new FakeUserRepository(uoWdbContextProvider); unitOfWorkObj.Begin(new UnitOfWorkOption()); try { //orderRepo.Insert(FakeOrder.Fake()); productRepo.InsertAsync(FakeProduct.Fake()).GetAwaiter(); userRepo.InsertAsync(FakeUser.Fake()).GetAwaiter(); unitOfWorkObj.CommitAsync().GetAwaiter().GetResult(); } catch (Exception ex) { //Assert.F("发生异常:" + ex.Message); } finally { unitOfWorkObj.Dispose(); } }
public void InsertTest() { var item = FakeUser.Fake(); normalEfCoreRepos.InsertAsync(item).GetAwaiter().GetResult(); var num = normalEfCoreRepos.SaveChanges(); Assert.True(num == 1); }
public void InsertRangeTest() { var list = new List <FakeUser>() { FakeUser.Fake(), FakeUser.Fake() }; normalEfCoreRepos.InsertRangeAsync(list).GetAwaiter().GetResult(); var num = normalEfCoreRepos.SaveChanges(); Assert.True(num == list.Count); }
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(); } }