示例#1
0
        public void ApplyTo_NullICharacter_Throws()
        {
            // Arrange
            var armor = new ElvenChain();

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

            // Assert
            Assert.Throws <ArgumentNullException>(applyTo);
        }
示例#2
0
        public void ApplyTo_ArmorBonusAndArmorCheckPenalty()
        {
            // Arrange
            var unaffectedPenalty   = Mock.Of <IModifierTracker>();
            var mockUnaffectedSkill = new Mock <ISkill>();

            mockUnaffectedSkill.Setup(s => s.ArmorCheckPenaltyApplies)
            .Returns(false);
            mockUnaffectedSkill.Setup(s => s.Penalties)
            .Returns(unaffectedPenalty);

            var affectedPenalty   = Mock.Of <IModifierTracker>();
            var mockAffectedSkill = new Mock <ISkill>();

            mockAffectedSkill.Setup(s => s.ArmorCheckPenaltyApplies)
            .Returns(true);
            mockAffectedSkill.Setup(s => s.Penalties)
            .Returns(affectedPenalty);

            var armorBonusTracker    = Mock.Of <IModifierTracker>();
            var maxDexPenaltyTracker = Mock.Of <IModifierTracker>();

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.ArmorClass.ArmorBonuses)
            .Returns(armorBonusTracker);
            mockCharacter.Setup(c => c.ArmorClass.MaxKeyAbilityScore)
            .Returns(maxDexPenaltyTracker);
            mockCharacter.Setup(c => c.Skills.GetAllSkills())
            .Returns(new ISkill[] { mockUnaffectedSkill.Object, mockAffectedSkill.Object });

            var armor = new ElvenChain();

            // Act
            armor.ApplyTo(mockCharacter.Object);

            // Assert
            Mock.Get(armorBonusTracker)
            .Verify(bt => bt.Add(It.Is <Func <byte> >(calc => 6 == calc())),
                    "Elven Chain should add a +6 armor bonus to a character's armor class.");
            Mock.Get(maxDexPenaltyTracker)
            .Verify(bt => bt.Add(It.Is <Func <byte> >(calc => 4 == calc())),
                    "Elven Chain should inflict a +1 max dex bonus to a character's armor class.");
            Mock.Get(unaffectedPenalty)
            .Verify(bt => bt.Add(It.Is <Func <byte> >(calc => 0 == calc())),
                    "Elven Chain should not add penalties to skills where armor check penalties do not apply.");
            Mock.Get(affectedPenalty)
            .Verify(bt => bt.Add(It.Is <Func <byte> >(calc => 2 == calc())),
                    "Elven Chain should add a -2 penalty to skills where armor check penalties apply.");
        }