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); }
public void Register1_NullIAbilityScore_Throws() { // Arrange byte usesPerDay = 3; var spell = Mock.Of <ISpell>(); IAbilityScore abilityScore = null; var character = Mock.Of <ICharacter>(); SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character); // Act TestDelegate registerMethod = () => slaReg.Register(usesPerDay, spell, abilityScore); // Assert Assert.Throws <ArgumentNullException>(registerMethod, "Null arguments are not allowed."); }
public void Register2_NullISpell_Throws() { // Arrange byte usesPerDay = 3; ISpell spell = null; var abilityScore = Mock.Of <IAbilityScore>(); Func <byte> casterLevel = () => 10; var character = Mock.Of <ICharacter>(); SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character); // Act TestDelegate registerMethod = () => slaReg.Register(usesPerDay, spell, abilityScore, casterLevel); // Assert Assert.Throws <ArgumentNullException>(registerMethod, "Null arguments are not allowed."); }
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)); }
public void Register1_TriggersEvent() { // Arrange byte usesPerDay = 3; var spell = Mock.Of <ISpell>(); var abilityScore = Mock.Of <IAbilityScore>(); var character = Mock.Of <ICharacter>(); SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character); bool wasCalled = false; // This tracks whether the event was fired. slaReg.OnRegistered += (sender, e) => { wasCalled = true; }; // Act slaReg.Register(usesPerDay, spell, abilityScore); // Assert Assert.IsTrue(wasCalled); }