Exemple #1
0
        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();
            }
        }
Exemple #2
0
 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;
 }
Exemple #4
0
        [Fact] public void Dispose_ShouldDisposeDbContext()
        {
            _unitOfWork.Dispose();

            Action action = () => _inMemoryContext.SaveChanges();

            action.Should().Throw <ObjectDisposedException>("because the DbContext has should have been disposed");
        }
Exemple #5
0
 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();
 }
Exemple #8
0
        public void EfUnitOfWork_Should_Throw_When_Not_SetContext_and_call_Dispose()
        {
            EfUnitOfWork unitOfWork = new EfUnitOfWork();

            Assert.Throws <NullReferenceException>(() => unitOfWork.Dispose());
        }