Esempio n. 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();
            }
        }
Esempio n. 2
0
        public void TestGetWorkOrders()
        {
            IConnectionStringResolver connectionStringResolver = new ConnectionStringResolver("Asmkt.WorkOrderSystem.Database");

            using (var uow = new EfUnitOfWork(connectionStringResolver))
            {
                var context = new EfDbContext <WorkOrderEntity, Guid>(uow.DbContext);
                var datas   = context.Entities.ToList();
                Console.WriteLine(context.CurrentContext.Database.Connection.GetHashCode());
                Assert.IsTrue(datas != null);
                var repository2 = new EfDbContext <WorkOrderFlowEntity, Guid>(uow.DbContext);
                var entity      = repository2.Entities.Find(Guid.Parse("07B60E03-1BFC-4C5C-9109-13CC6F77375B"));
                Console.WriteLine(repository2.CurrentContext.Database.Connection.GetHashCode());
                Assert.IsTrue(entity != null);

                uow.Begin();
            }
        }