/// <summary> /// Registers a spell. /// </summary> /// <returns>The registered spell.</returns> /// <param name="spell">The spell to register.</param> /// <param name="keyAbilityScore">The ability score which powers the spell.</param> /// <param name="baseCasterLevel">The spell's caster level.</param> /// <exception cref="System.ArgumentNullException"></exception> public ICastableSpell Register(ISpell spell, IAbilityScore keyAbilityScore, Func <byte> baseCasterLevel) { if (null == spell) { throw new ArgumentNullException(nameof(spell), "Argument cannot be null."); } if (null == keyAbilityScore) { throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null."); } if (null == baseCasterLevel) { throw new ArgumentNullException(nameof(baseCasterLevel), "Argument cannot be null."); } ICastableSpell existingSpell = this.RegisteredSpells.Where(rs => rs.Spell == spell) .FirstOrDefault(); if (null != existingSpell) { return(existingSpell); } ICastableSpell newSpell = new CastableSpell(spell, keyAbilityScore, baseCasterLevel); this.RegisteredSpells.Add(newSpell); this.OnRegistered?.Invoke(this, new SpellRegisteredEventArgs(newSpell)); return(newSpell); }
public void Register1_Returns_ConfiguredISpellLikeAbility() { // Arrange var mockSpell = new Mock <ISpell>(); mockSpell.Setup(s => s.Level) .Returns(7); ISpell spell = mockSpell.Object; var mockAbilityScore = new Mock <IAbilityScore>(); mockAbilityScore.Setup(ab => ab.GetBonus()) .Returns(4); IAbilityScore abilityScore = mockAbilityScore.Object; var mockCharacter = new Mock <ICharacter>(); mockCharacter.Setup(c => c.Level) .Returns(19); ICharacter character = mockCharacter.Object; SpellRegistrar spellReg = new SpellRegistrar(character); // Act ICastableSpell castable = spellReg.Register(spell, abilityScore); // Assert Assert.AreSame(spell, castable.Spell); }
/// <summary> /// Adds the spell to this collection. /// </summary> /// <param name="spell">The spell to add.</param> /// <exception cref="System.ArgumentNullException">Thrown when spell argument is null.</exception> public void Add(ICastableSpell spell) { if (null == spell) { throw new ArgumentNullException($"{ nameof(spell) } argument cannot be null."); } this.Spells.Add(spell); }
/// <summary> /// Applies this feat to a spell. /// </summary> /// <param name="spell">The spell to apply this feat to.</param> /// <exception cref="System.ArgumentNullException">Thrown when the spell argument is null.</exception> private void ApplyToSpell(ICastableSpell spell) { if (null == spell) { throw new ArgumentNullException(nameof(spell), "Argument cannot be null."); } if (_school == spell.Spell.School) { spell.AddDifficultyClassBonus(1); } }
public void Constructor_NullEventICastableSpell_Throws() { // Arrange ICastableSpell castableSpell = null; // Act TestDelegate constructor = () => new SpellRegisteredEventArgs(castableSpell); // Assert Assert.Throws <ArgumentNullException>(constructor, "Null arguments are not allowed."); }
public void Add_NullICastableSpell_Throws() { // Arrange CastableSpellCollection spellCollection = new CastableSpellCollection(); ICastableSpell spell = null; // Act TestDelegate addNull = () => spellCollection.Add(spell); // Assert Assert.Throws <ArgumentNullException>(addNull, "Null arguments are not allowed."); }
public void GetSpellLikeAbilities_Register1_RoundTrip() { // Arrange var spell = Mock.Of <ISpell>(); var abilityScore = Mock.Of <IAbilityScore>(); var character = Mock.Of <ICharacter>(); SpellRegistrar spellReg = new SpellRegistrar(character); ICastableSpell castable = spellReg.Register(spell, abilityScore); // Act var result = spellReg.GetSpells(); // Assert Assert.That(result, Has.Exactly(1).Matches <ICastableSpell>(sp => castable == sp)); }
/// <summary> /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.SpellRegisteredEventArgs"/> class. /// </summary> /// <param name="spell">The spell which raised the event.</param> /// <exception cref="System.ArgumentNullException">Thrown when spell argument is null.</exception> internal SpellRegisteredEventArgs(ICastableSpell spell) { _spell = spell ?? throw new ArgumentNullException(); }