예제 #1
0
        public void Test_AllTransactionsSuccessful()
        {
            var modificationManager = new ModificationManager();

            var character           = new Character("Alice", 10, 14, 12);
            var modificationAgility = new Modification(
                character,
                StatisticType.Agility,
                8);

            var modificationStrength = new Modification(
                character,
                StatisticType.Strength,
                -4);

            modificationManager.AddModification(modificationAgility);

            modificationManager.AddModification(modificationStrength);

            modificationManager.ProcessQueue();

            modificationManager.RevertModification(modificationAgility);

            modificationManager.RevertModification(modificationStrength.Id);
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Create a manager.
            var manager = new ModificationManager();

            // Create a character with initial stats.
            var alice = new Character("Alice", 10, 14, 12);
            // Create another character with default stats.
            var bob = new Character("Bob");

            // Create some modifications for Alice.
            var agilityAlice  = new Modification(alice, StatisticType.Agility, 8);
            var charismaAlice = new Modification(alice, StatisticType.Charisma, -4);
            var strengthAlice = new Modification(alice, StatisticType.Strength, 0.75m);

            // Create modifications for Bob.
            var agilityBob  = new Modification(bob, StatisticType.Agility, 99.99m);
            var charismaBob = new Modification(bob, StatisticType.Charisma, -42);

            // Add modifications to queue.
            manager.AddModification(agilityAlice);
            manager.AddModification(strengthAlice);
            manager.AddModification(agilityBob);
            manager.AddModification(charismaBob);
            manager.AddModification(charismaAlice);

            // Process queue.
            manager.ProcessQueue();

            // Revert agility modification.
            manager.RevertModification(agilityAlice);

            // Confirm that we can revert in any order, regardless of queue order.
            Assert.Equal(bob.Charisma.Value, charismaBob.Value);
            manager.RevertModification(charismaBob);
            Assert.Equal(bob.Charisma.Value, 0);

            // Confirm that passing by Id also works.
            Assert.Equal(alice.Strength.Value, 12 + strengthAlice.Value);
            manager.RevertModification(strengthAlice.Id);
            Assert.Equal(alice.Strength.Value, 12);
        }