Esempio n. 1
0
        public void CardsTransation()
        {
            DeckManager dm = createDM();

            var deckID = dm.CreateDeck("测试卡组");

            var instID1 = dm.AddCard(deckID, 1000);
            var instID2 = dm.AddCard(deckID, 1001);

            // 进入事务
            dm.EnterTransaction();

            var instID3 = dm.AddCard(deckID, 1003);

            dm.RemoveCard(instID1);

            Assert.AreEqual(-1, dm.GetCardID(instID1));
            Assert.AreEqual(1003, dm.GetCardID(instID3));

            // 尝试回滚
            dm.Rollback();
            Assert.AreEqual(1000, dm.GetCardID(instID1));
            Assert.AreEqual(-1, dm.GetCardID(instID3));

            // 进入事务
            dm.EnterTransaction();
            instID3 = dm.AddCard(deckID, 1003);
            dm.RemoveCard(instID2);

            Assert.AreEqual(-1, dm.GetCardID(instID2));
            Assert.AreEqual(1003, dm.GetCardID(instID3));

            // 提交
            dm.Commit();
            Assert.AreEqual(-1, dm.GetCardID(instID2));
            Assert.AreEqual(1003, dm.GetCardID(instID3));
        }