/// <summary> /// Registers a spell-like ability. /// </summary> /// <param name="usesPerDay">The number of times per day the spell-like ability can be used.</param> /// <param name="spell">The spell this spell-like ability imitates.</param> /// <param name="keyAbilityScore">The ability score associated with the spell-like ability.</param> /// <param name="baseCasterLevel">The caster level of the spell-like ability.</param> /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception> public ISpellLikeAbility Register(byte usesPerDay, 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."); } ISpellLikeAbility existingSpell = this.RegisteredSpells.Where(rs => rs.Spell == spell) .FirstOrDefault(); if (null != existingSpell) { return(existingSpell); } ISpellLikeAbility newSpell = new SpellLikeAbility(usesPerDay, spell, keyAbilityScore, baseCasterLevel); this.RegisteredSpells.Add(newSpell); this.OnRegistered?.Invoke(this, new SpellLikeAbilityRegisteredEventArgs(newSpell)); return(newSpell); }
public void Register1_Returns_ConfiguredISpellLikeAbility() { // Arrange byte usesPerDay = 3; 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; SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character); // Act ISpellLikeAbility sla = slaReg.Register(usesPerDay, spell, abilityScore); // Assert Assert.IsNotNull(sla); Assert.AreEqual(usesPerDay, sla.UsesPerDay); Assert.AreSame(spell, sla.Spell); }
/// <summary> /// Adds the spell-like ability to this collection. /// </summary> /// <param name="spell">The spell-like ability to add.</param> /// <exception cref="System.ArgumentNullException">Thrown when spell argument is null.</exception> public void Add(ISpellLikeAbility spell) { if (null == spell) { throw new ArgumentNullException($"{ nameof(spell) } argument cannot be null."); } this.Spells.Add(spell); }
public void Constructor_NullArg_Throws() { // Arrange ISpellLikeAbility sla = null; // Act TestDelegate constructor = () => new SpellLikeAbilityRegisteredEventArgs(sla); // Assert Assert.Throws <ArgumentNullException>(constructor, "Null arguments are not allowed."); }
public void Add_NullISpellLikeAbility_Throws() { // Arrange ISpellLikeAbility sla = null; SpellLikeAbilityCollection slaCollection = new SpellLikeAbilityCollection(); // Act TestDelegate addNull = () => slaCollection.Add(sla); // Assert Assert.Throws <ArgumentNullException>(addNull, "Null arguments are not allowed."); }
public void SpellLikeAbility_Property_RoundTrip() { // Arrange ISpellLikeAbility sla = Mock.Of <ISpellLikeAbility>(); SpellLikeAbilityRegisteredEventArgs eventArgs = new SpellLikeAbilityRegisteredEventArgs(sla); // Act var result = eventArgs.SpellLikeAbility; // Assert Assert.AreSame(sla, result, "The .SpellLikeAbility property should return a reference to the same object that was passed into the constructor."); }
public void GetSpellLikeAbilities_Register1_RoundTrip() { // Arrange byte usesPerDay = 3; var spell = Mock.Of <ISpell>(); var abilityScore = Mock.Of <IAbilityScore>(); var character = Mock.Of <ICharacter>(); SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character); ISpellLikeAbility sla = slaReg.Register(usesPerDay, spell, abilityScore); // Act var result = slaReg.GetSpellLikeAbilities(); // Assert Assert.That(result, Has.Exactly(1).Matches <ISpellLikeAbility>(rSla => sla == rSla)); }
/// <summary> /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.SpellRegisteredEventArgs"/> class. /// </summary> /// <param name="spellLikeAbility">The spell which raised the event.</param> /// <exception cref="System.ArgumentNullException">Thrown when spell argument is null.</exception> internal SpellLikeAbilityRegisteredEventArgs(ISpellLikeAbility spellLikeAbility) { _spellLikeAbility = spellLikeAbility ?? throw new ArgumentNullException(); }