public void DistributedTransactionTest()
        {
            //失败事务
            BaseBusiness <Base_UnitTest> _bus1 = new BaseBusiness <Base_UnitTest>();
            BaseBusiness <Base_UnitTest> _bus2 = new BaseBusiness <Base_UnitTest>("BaseDb_Test");

            _bus1.DeleteAll();
            _bus2.DeleteAll();
            Base_UnitTest data1 = new Base_UnitTest
            {
                Id       = Guid.NewGuid().ToString(),
                UserId   = "1",
                UserName = Guid.NewGuid().ToString()
            };
            Base_UnitTest data2 = new Base_UnitTest
            {
                Id       = Guid.NewGuid().ToString(),
                UserId   = "1",
                UserName = Guid.NewGuid().ToString()
            };
            Base_UnitTest data3 = new Base_UnitTest
            {
                Id       = Guid.NewGuid().ToString(),
                UserId   = "2",
                UserName = Guid.NewGuid().ToString()
            };
            DistributedTransaction distributedTransaction = new DistributedTransaction(_bus1.Service, _bus2.Service);

            distributedTransaction.BeginTransaction();
            _bus1.ExecuteSql("insert into Base_UnitTest(Id) values('10') ");
            _bus1.Insert(data1);
            _bus1.Insert(data3);
            _bus2.Insert(data1);
            _bus2.Insert(data2);
            bool succcess = distributedTransaction.EndTransaction();
            int  count1   = _bus1.GetIQueryable().Count();
            int  count2   = _bus2.GetIQueryable().Count();

            Assert.AreEqual(succcess, false);
            Assert.AreEqual(count1, 0);
            Assert.AreEqual(count2, 0);

            //成功事务
            _bus1.DeleteAll();
            _bus2.DeleteAll();
            distributedTransaction = new DistributedTransaction(_bus1.Service, _bus2.Service);
            distributedTransaction.BeginTransaction();
            _bus1.ExecuteSql("insert into Base_UnitTest(Id) values('10') ");
            _bus1.Insert(data1);
            _bus1.Insert(data3);
            _bus2.Insert(data1);
            _bus2.Insert(data3);
            succcess = distributedTransaction.EndTransaction();
            count1   = _bus1.GetIQueryable().Count();
            count2   = _bus2.GetIQueryable().Count();
            Assert.AreEqual(succcess, true);
            Assert.AreEqual(count1, 3);
            Assert.AreEqual(count2, 2);
        }
Esempio n. 2
0
        public ActionResult Synchronize(string PaymentNumber)
        {
            ViewBag.TopButtons = new List <TopButton> {
                new TopButton {
                    Direction = Enumerators.ButtonDirection.Left,
                    Link      = Url.Action("Index", "Home"),
                    Text      = "< Voltar"
                }
            };

            var loggedUser = (Session["loggedUSer"] as Customer);

            var billingGroup = _billingGroupBusiness.SelectSingle(
                w => w.UniqueIdentifier == PaymentNumber
                );

            IList <BillingGroup_Customer_Product> products = null;

            if (billingGroup != null && loggedUser != null)
            {
                var customer = new BillingGroup_Customer
                {
                    IdUser          = loggedUser.IdUser,
                    IdPaymentType   = (int)Enumerators.PaymentType.Master,
                    IndividualPrice = 0,
                    CreatedAt       = DateTime.Now,
                    IdBillingGroup  = billingGroup.IdBillingGroup
                };

                _billingGroupCustomerBusiness.Delete(customer);
                _billingGroupCustomerBusiness.Insert(customer);

                products = _billingGroupCustomerProductBusiness.Select(
                    p => p.IdBillingGroup == billingGroup.IdBillingGroup,
                    n => n.Product
                    );


                // return View(products);
            }
            else
            {
                this.ModelState.AddModelError(
                    "merchant-not-found",
                    "Estabelecimento não encontrado."
                    );
            }

            ViewBag.ViewCount = true;

            Session["products"] = products;
            return(View(products));
        }