コード例 #1
0
ファイル: TransactionTest.cs プロジェクト: radtek/ReportMS
        public void TransactionScop_Test()
        {
            var transResult0 = new Transaction0();
            var transResult1 = new Transaction0();
            //var transResult2 = new Transaction0();

            var transOption = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (var trans = new TransactionScope(TransactionScopeOption.Required, transOption))
            {
                transResult0.Value = 1;

                using (var trans1 = new TransactionScope())
                {
                    transResult1.Value = 1;

                    //trans1.Dispose();
                }

                //using (var trans2 = new TransactionScope())
                //{
                //    transResult2 = 1;

                //    //throw new InvalidOperationException();

                //    trans2.Complete();
                //}

                //trans.Complete();
            }

            Assert.IsTrue(transResult0.Value == 1);
            Assert.IsTrue(transResult1.Value == 1);
            //Assert.IsTrue(transResult2 == 1);
        }
コード例 #2
0
        public void TransactionScop_Test()
        {
            var transResult0 = new Transaction0();
            var transResult1 = new Transaction0();
            //var transResult2 = new Transaction0();

            var transOption = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (var trans = new TransactionScope(TransactionScopeOption.Required, transOption))
            {
                transResult0.Value = 1;

                using (var trans1 = new TransactionScope())
                {
                    transResult1.Value = 1;

                    //trans1.Dispose();
                }

                //using (var trans2 = new TransactionScope())
                //{
                //    transResult2 = 1;

                //    //throw new InvalidOperationException();

                //    trans2.Complete();
                //}

                //trans.Complete();
            }

            Assert.IsTrue(transResult0.Value == 1);
            Assert.IsTrue(transResult1.Value == 1);
            //Assert.IsTrue(transResult2 == 1);
        }