示例#1
0
        public void get_and_update_single_context()
        {
            UserTestData.PrepareUser(userId);
            string lastUsername = "";

            perfMeter.MeasurePerf(() =>
            {
                var newUsername = $"new-username-{Guid.NewGuid().ToString("n")}";
                using (var db = new MyContext())
                {
                    var user = db.Users.Find(userId);

                    if (user.UserName != newUsername)
                    {
                        user.UserName = newUsername;
                    }

                    db.SaveChanges();
                }

                lastUsername = newUsername;
            });

            using (var db = new MyContext())
            {
                var user1 = db.Users.Find(userId);
                Assert.AreEqual(lastUsername, user1.UserName);
            }
        }
示例#2
0
        public void rollback_transaction_in_multiple_same_contexts_perf()
        {
            PrepareUser(userId);

            var initialCount = GetUserOrdersCount(userId);

            perfMeter.MeasurePerf(() =>
            {
                using (var tran = new TransactionScope())
                {
                    using (var db = new MyContext())
                    {
                        IncreateUserOrdersCount(db);
                    }

                    using (var db = new MyContext())
                    {
                        AddOrder(db);
                    }
                }
            });
        }