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 Dispose() { _firstUow.WarehouseRepository.Delete(_testEntityId); _firstUow.SaveChanges(); _firstUow.Dispose(); _secondUow.Dispose(); }
public override void Dispose() { base.Dispose(); EfUnitOfWork?.Dispose(); EfUnitOfWork = null; ContextFactory?.Dispose(); ContextFactory = null; }
[Fact] public void Dispose_ShouldDisposeDbContext() { _unitOfWork.Dispose(); Action action = () => _inMemoryContext.SaveChanges(); action.Should().Throw <ObjectDisposedException>("because the DbContext has should have been disposed"); }
protected override void Dispose(bool disposing) { if (disposing) { uow.Dispose(); } base.Dispose(disposing); }
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(); } }
public void Dispose() { _unitOfWork?.Dispose(); }
public void EfUnitOfWork_Should_Throw_When_Not_SetContext_and_call_Dispose() { EfUnitOfWork unitOfWork = new EfUnitOfWork(); Assert.Throws <NullReferenceException>(() => unitOfWork.Dispose()); }