Ejemplo n.º 1
0
        public void ApplyTo_NullICharacter_Throws()
        {
            // Arrange
            IItem item = Mock.Of <IItem>();
            Action <IEnchantment, IItem> action = Mock.Of <Action <IEnchantment, IItem> >();
            double costCoefficient = 1000;
            var    aggregator      = new Mock <EnchantmentAggregator <IEnchantment, IItem> >(MockBehavior.Loose, item, action, costCoefficient)
            {
                CallBase = true
            }.Object;

            // Act
            TestDelegate applyTo = () => aggregator.ApplyTo(null);

            // Assert
            Assert.Throws <ArgumentNullException>(applyTo);
        }
        public void ApplyTo_NullCharacter_Throws()
        {
            // Arrange
            string elementName     = "Force";
            var    forceResistance = Mock.Of <IModifierTracker>();
            Func <ICharacter, IModifierTracker> resistanceExpression = (character) => forceResistance;
            EnergyResistanceMagnitude           protectionLevel      = EnergyResistanceMagnitude.Regular;

            var energyResistance = new Mock <EnergyResistanceEnchantment>(MockBehavior.Loose, elementName, resistanceExpression, protectionLevel)
            {
                CallBase = true
            }.Object;

            // Act
            TestDelegate constructor = () => energyResistance.ApplyTo(null);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor);
        }
        public void Greater_ApplyTo_NullCharacter_Throws()
        {
            // Arrange
            string elementName     = "Force";
            var    forceResistance = Mock.Of <IModifierTracker>();
            Func <ICharacter, IModifierTracker> resistanceExpression = (c) => forceResistance;
            EnergyResistanceMagnitude           protectionLevel      = EnergyResistanceMagnitude.Greater;

            var energyResistance = new Mock <EnergyResistanceEnchantment>(MockBehavior.Loose, elementName, resistanceExpression, protectionLevel)
            {
                CallBase = true
            }.Object;

            // Act
            energyResistance.ApplyTo(Mock.Of <ICharacter>());

            // Assert
            Mock.Get(forceResistance)
            .Verify(er => er.Add(It.Is <Func <byte> >(calc => 30 == calc())),
                    "Greater Energy Resistance should add 30 to the character's energy resistance.");
        }
Ejemplo n.º 4
0
        public void ApplyTo_AllNewEnchantments()
        {
            // Arrange
            IItem item = Mock.Of <IItem>();
            Action <IEnchantment, IItem> action = Mock.Of <Action <IEnchantment, IItem> >();
            double costCoefficient = 1000;
            var    aggregator      = new Mock <EnchantmentAggregator <IEnchantment, IItem> >(MockBehavior.Loose, item, action, costCoefficient)
            {
                CallBase = true
            }.Object;
            var character        = Mock.Of <ICharacter>();
            var otherEnchantment = Mock.Of <IEnchantment>();

            // Act
            aggregator.EnchantWith(new EnhancementBonus(1));
            aggregator.ApplyTo(character);
            aggregator.EnchantWith(otherEnchantment);

            // Assert
            Mock.Get(otherEnchantment)
            .Verify(e => e.ApplyTo(It.Is <ICharacter>(c => c == character)),
                    "Applying the enchantment aggregator to a character, then adding a new enchantment should apply the new enchantment to the character.");
        }