Example #1
0
        public async Task MoreProvider_CannotReused_Async()
        {
            var provider = GetServiceProvider(AddTwoSameTypeProvider);

            var uowManager         = provider.GetService <IUnitOfWorkManager>();
            var currentDbExecutor  = new ScopeDbExecutor(new FakeDbContext());
            var currentDbExecutor2 = new DemoDbExecutor(new DemoDbContext());

            using (var uow = uowManager.Create())
            {
                await uow.TryAddDbExecutorAsync(currentDbExecutor);

                //此时工作单元中已经有一个事务,但是由于类型不同currentDbExecutor2不能复用
                uow.TryAddDbExecutor(currentDbExecutor2);

                Assert.True(currentDbExecutor.HasTransaction);
                Assert.False(currentDbExecutor2.HasTransaction);

                await uow.SaveChangesAsync();
            }

            //但是会被添加到工作单元,最后于工作单元一同释放
            Assert.True(currentDbExecutor.IsDispose);
            Assert.True(currentDbExecutor2.IsDispose);
        }
Example #2
0
        public void MoreProvider_ButNoSuitable_ShouldNoTransaction()
        {
            var provider = GetServiceProvider(AddTwoSameTypeProvider);

            //两个provider都不接受类型为DemoDbExecutor
            var uowManager        = provider.GetService <IUnitOfWorkManager>();
            var currentDbExecutor = new DemoDbExecutor(new DemoDbContext());

            using (var uow = uowManager.Create())
            {
                uow.TryAddDbExecutor(currentDbExecutor);
                //没有事务提供程序为它提供事务
                Assert.False(currentDbExecutor.HasTransaction);

                uow.SaveChanges();
            }

            //但是会被添加到工作单元,最后于工作单元一同释放
            Assert.True(currentDbExecutor.IsDispose);
        }