public void Shield_PlusFive_Enchant() { // Arrange var armorEnhancementBonus = Mock.Of <IModifierTracker>(); var mockShieldBonusAgg = new Mock <IArmorClassAggregator>(); mockShieldBonusAgg.Setup(agg => agg.EnhancementBonuses) .Returns(armorEnhancementBonus); IArmorClassAggregator shieldBonus = mockShieldBonusAgg.Object; var hardnessEnhancementBonus = Mock.Of <IModifierTracker>(); var mockHardnessAgg = new Mock <IHardnessAggregator>(); mockHardnessAgg.Setup(agg => agg.EnhancementBonuses) .Returns(hardnessEnhancementBonus); IHardnessAggregator hardness = mockHardnessAgg.Object; var hitPointsEnhancementBonus = Mock.Of <IModifierTracker>(); var mockHitPointAgg = new Mock <IHitPointsAggregator>(); mockHitPointAgg.Setup(agg => agg.EnhancementBonuses) .Returns(hitPointsEnhancementBonus); IHitPointsAggregator hitPoints = mockHitPointAgg.Object; IEnchantmentAggregator <IShieldEnchantment, Shield> enchantments = null; var shield = new Mock <Shield>(MockBehavior.Loose, shieldBonus, hardness, hitPoints, enchantments) { CallBase = true }.Object; IShieldEnchantment enchantment = new EnhancementBonus(5); // Act enchantment.Enchant(shield); // Assert Mock.Get(armorEnhancementBonus) .Verify(ac => ac.Add(It.Is <Func <byte> >(calc => 5 == calc())), "A +5 bonus was not applied to the shield's armor class bonus correctly."); Mock.Get(hardnessEnhancementBonus) .Verify(bhn => bhn.Add(It.Is <Func <byte> >(calc => 10 == calc())), "A +10 bonus was not applied to the shield's hardness correctly."); Mock.Get(hitPointsEnhancementBonus) .Verify(hp => hp.Add(It.Is <Func <byte> >(calc => 50 == calc())), "A +50 bonus was not applied to the shield's hit points correctly."); }
public void Armor_PlusOne_Enchant() { // Arrange var armorEnhancementBonus = Mock.Of <IModifierTracker>(); var mockArmorBonusAgg = new Mock <IArmorClassAggregator>(); mockArmorBonusAgg.Setup(agg => agg.EnhancementBonuses) .Returns(armorEnhancementBonus); IArmorClassAggregator armorBonus = mockArmorBonusAgg.Object; var hardnessEnhancementBonus = Mock.Of <IModifierTracker>(); var mockHardnessAgg = new Mock <IHardnessAggregator>(); mockHardnessAgg.Setup(agg => agg.EnhancementBonuses) .Returns(hardnessEnhancementBonus); IHardnessAggregator hardness = mockHardnessAgg.Object; var hitPointsEnhancementBonus = Mock.Of <IModifierTracker>(); var mockHitPointAgg = new Mock <IHitPointsAggregator>(); mockHitPointAgg.Setup(agg => agg.EnhancementBonuses) .Returns(hitPointsEnhancementBonus); IHitPointsAggregator hitPoints = mockHitPointAgg.Object; var armor = new Mock <Core.Domain.Items.Armor.Armor>(MockBehavior.Loose, armorBonus, hardness, hitPoints, null) { CallBase = true }.Object; IArmorEnchantment enchantment = new EnhancementBonus(1); // Act enchantment.Enchant(armor); // Assert Mock.Get(armorEnhancementBonus) .Verify(ac => ac.Add(It.Is <Func <byte> >(calc => 1 == calc())), "A +1 bonus was not applied to the armor's armor class bonus correctly."); Mock.Get(hardnessEnhancementBonus) .Verify(bhn => bhn.Add(It.Is <Func <byte> >(calc => 2 == calc())), "A +2 bonus was not applied to the armor's hardness correctly."); Mock.Get(hitPointsEnhancementBonus) .Verify(hp => hp.Add(It.Is <Func <byte> >(calc => 10 == calc())), "A +10 bonus was not applied to the armor's hit points correctly."); }
/// <summary> /// Dependency injection constructor (used for testing). /// Initializes a new instance of the <see cref="T:Core.Domain.Items.Shields.Shield"/> class. /// </summary> /// <param name="shieldBonus">Tied to the ArmorClass property; cannot be null.</param> /// <param name="hardness">Tied to the Hardness property; cannot be null.</param> /// <param name="hitPoints">Tied to the HitPoints property; cannot be null.</param> /// <param name="enchantments">If this is null, this will assign a new instance of ShieldEnchantmentAggregator to the Enchantments property.</param> /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception> internal Shield(IArmorClassAggregator shieldBonus, IHardnessAggregator hardness, IHitPointsAggregator hitPoints, IEnchantmentAggregator <IShieldEnchantment, Shield> enchantments) { _armorClass = shieldBonus ?? throw new ArgumentNullException(nameof(shieldBonus), "Argument may not be null."); _hardness = hardness ?? throw new ArgumentNullException(nameof(hardness), "Argument cannot be null."); _hitPoints = hitPoints ?? throw new ArgumentNullException(nameof(hitPoints), "Argument cannot be null."); _enchantments = enchantments ?? new ShieldEnchantmentAggregator(this); // Adds shields bonus to character's armor class. this.OnApplied += (sender, e) => { e.Character?.ArmorClass?.ShieldBonuses?.Add(this.GetShieldBonus); }; // Adds armor check penalty to skills this.OnApplied += (sender, e) => { foreach (var skill in e.Character?.Skills?.GetAllSkills() ?? Enumerable.Empty <ISkill>()) { skill.Penalties?.Add(() => skill.ArmorCheckPenaltyApplies ? this.GetArmorCheckPenalty() : (byte)0); } }; }
/// <summary> /// Dependency injection constructor (used for testing). /// Initializes a new instance of the <see cref="T:Core.Domain.Items.Armor.Armor"/> class. /// </summary> /// <param name="armorClass">Tied to the ArmorClass property; cannot be null.</param> /// <param name="hardness">Tied to the Hardness property; cannot be null.</param> /// <param name="hitPoints">Tied to the HitPoints property; cannot be null.</param> /// <param name="enchantments">If this is null, this will assign a new instance of ArmorEnchantmentAggregator to the Enchantments property.</param> internal Armor(IArmorClassAggregator armorClass, IHardnessAggregator hardness, IHitPointsAggregator hitPoints, IEnchantmentAggregator <IArmorEnchantment, Armor> enchantments) { _armorClass = armorClass ?? throw new ArgumentNullException(nameof(armorClass), "Argument may not be null."); _hardness = hardness ?? throw new ArgumentNullException(nameof(hardness), "Argument may not be null."); _hitPoints = hitPoints ?? throw new ArgumentNullException(nameof(hitPoints), "Argument may not be null."); _enchantments = enchantments ?? new ArmorEnchantmentAggregator(this); // Applies armor bonus to armor class this.OnApplied += (sender, e) => { e.Character?.ArmorClass?.ArmorBonuses?.Add(this.GetArmorBonus); }; // Applies dex cap to AC this.OnApplied += (sender, e) => { e.Character?.ArmorClass?.MaxKeyAbilityScore?.Add(this.GetMaximumDexterityBonus); }; // Applies armor check penalty to skills this.OnApplied += (sender, e) => { foreach (var skill in e.Character?.Skills?.GetAllSkills() ?? Enumerable.Empty <ISkill>()) { skill.Penalties?.Add(() => skill.ArmorCheckPenaltyApplies ? this.GetArmorCheckPenalty() : (byte)0); } }; // Applies movement penalties to movement speeds this.OnApplied += (sender, e) => { foreach (IMovement movement in e.Character?.MovementModes?.GetAll() ?? Enumerable.Empty <IMovement>()) { movement.Penalties.Add(() => { if (!movement.BaseSpeed.HasValue) { return(0); } var finalSpeed = Math.Floor((1f - this.SpeedPenalty) * movement.BaseSpeed.Value); return(Convert.ToByte(movement.BaseSpeed.Value - finalSpeed)); }); } }; }