public void ResetCurrentDefense_WhenApplyWhenDefendingRoundsGetTo0()
        {
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(2);

            var creaturesInBattle = new CreaturesInBattle(new Angel(), 1);

            doubleDefenseWhenDefending.ApplyWhenDefending(creaturesInBattle, creaturesInBattle);
            doubleDefenseWhenDefending.ApplyWhenDefending(creaturesInBattle, creaturesInBattle);
            doubleDefenseWhenDefending.ApplyWhenDefending(creaturesInBattle, creaturesInBattle);

            Assert.AreEqual(80, creaturesInBattle.CurrentDefense);
        }
Exemple #2
0
        public void ApplyWhenDefending_WhenEffectHasNotExpired_ShouldDoubleCurrentDefenceForEachCall()
        {
            var def          = new DoubleDefenseWhenDefending(3);
            var defenderMock = new Mock <ICreaturesInBattle>();

            defenderMock.SetupAllProperties();
            defenderMock.Object.CurrentDefense = 1;
            var attackerMock = new Mock <ICreaturesInBattle>();

            def.ApplyWhenDefending(defenderMock.Object, attackerMock.Object);
            def.ApplyWhenDefending(defenderMock.Object, attackerMock.Object);
            def.ApplyWhenDefending(defenderMock.Object, attackerMock.Object);

            defenderMock.VerifySet(x => x.CurrentDefense = 8);
        }
Exemple #3
0
        public void ApplyWhenDefending_WhenAttackerIsNull_ShouldThrowArgumentNullException()
        {
            var def = new DoubleDefenseWhenDefending(3);
            var mockedICreaturesInBattle = new Mock <ICreaturesInBattle>();

            Assert.Throws <ArgumentNullException>(() => def.ApplyWhenDefending(mockedICreaturesInBattle.Object, null));
        }
        public void ThrowArgumentNullException_WhenApplyWhenDefendingIsCalledWithNullAttackerWithSpecialty()
        {
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(1);

            var creaturesInBattle = new CreaturesInBattle(new Angel(), 1);

            Assert.Throws <ArgumentNullException>(() =>
                                                  doubleDefenseWhenDefending.ApplyWhenDefending(creaturesInBattle, null));
        }
        public void ApplyWhenDefending_ShouldNotDecrementFieldRounds_WhenRoundsIsEqualToZero()
        {
            var defenderWithSpecialty = new Mock <ICreaturesInBattle>();
            var attacker = new Mock <ICreaturesInBattle>();

            var rounds = 1;
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(rounds);

            var doubleDefenseWhenDefendingAsPrivateObject = new MSTest.PrivateObject(doubleDefenseWhenDefending);
            var initialNumberOfRounds = doubleDefenseWhenDefendingAsPrivateObject.GetField("rounds");

            doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecialty.Object, attacker.Object);
            doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecialty.Object, attacker.Object);
            doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecialty.Object, attacker.Object);
            var actualNumberOfRounds = doubleDefenseWhenDefendingAsPrivateObject.GetField("rounds");

            Assert.AreEqual(0, actualNumberOfRounds);
        }
        public void ReturnCorrectMultipliedDefense_WhenApplyWhenDefendingIsCalled()
        {
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(1);

            var creaturesInBattle = new CreaturesInBattle(new Angel(), 1);

            doubleDefenseWhenDefending.ApplyWhenDefending(creaturesInBattle, creaturesInBattle);

            Assert.AreEqual(40, creaturesInBattle.CurrentDefense);
        }
        public void ApplyWhenDefending_ShouldThrowArgumentNullException_IfAttackerIsNull()
        {
            var rounds    = 5;
            var specialty = new DoubleDefenseWhenDefending(rounds);

            var defender = new Mock <ICreaturesInBattle>();

            Assert.Throws <ArgumentNullException>(() =>
                                                  specialty.ApplyWhenDefending(defender.Object, null));
        }
        public void ApplyWhenDefending_ShouldThrowTheCorrectErrorMessage_IfAttackerParameterIsNull()
        {
            var defenderWithSpecialty   = new Mock <ICreaturesInBattle>();
            ICreaturesInBattle attacker = null;
            var rounds = 5;

            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(rounds);

            var resultingException = Assert.Throws <ArgumentNullException>(() => doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecialty.Object, attacker));

            Assert.IsTrue(resultingException.Message.Contains("attacker"));
        }
        public void ApplyWhenDefending_ShouldNotApplyEffectToAttacker()
        {
            var defenderWithSpecilty = new Mock <ICreaturesInBattle>();
            var attacker             = new Mock <ICreaturesInBattle>(MockBehavior.Strict);

            var rounds = 5;
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(rounds);

            defenderWithSpecilty.SetupGet(mock => mock.CurrentDefense).Returns(0);
            defenderWithSpecilty.SetupSet(mock => mock.CurrentDefense = It.IsAny <int>());

            doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecilty.Object, attacker.Object);

            attacker.Verify();
        }
        public void ApplyWhenDefending_ShouldApplyEffectToICreaturesInBattleDefenderWithSpecialtyCurrentDefense()
        {
            var defenderWithSpecilty = new Mock <ICreaturesInBattle>();
            var attacker             = new Mock <ICreaturesInBattle>();

            var rounds = 5;
            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(rounds);

            defenderWithSpecilty.SetupGet(mock => mock.CurrentDefense).Returns(0);
            defenderWithSpecilty.SetupSet(mock => mock.CurrentDefense = It.IsAny <int>());

            doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecilty.Object, attacker.Object);

            defenderWithSpecilty.VerifySet(mock => mock.CurrentDefense = It.IsAny <int>(), Times.Once());
        }
        public void AppleWhenDefending_ShouldApplyEffect_AsManyTimesAsSPecifiedByTheRoundsParameter(int rounds)
        {
            var defenderWithSpecialty = new Mock <ICreaturesInBattle>();
            var attacker = new Mock <ICreaturesInBattle>();

            defenderWithSpecialty.SetupGet(creature => creature.CurrentDefense).Returns(0);
            defenderWithSpecialty.SetupSet(creature => creature.CurrentDefense = 0);

            var doubleDefenseWhenDefending = new DoubleDefenseWhenDefending(rounds);

            for (var i = 0; i <= rounds * 2; i++)
            {
                doubleDefenseWhenDefending.ApplyWhenDefending(defenderWithSpecialty.Object, attacker.Object);
            }

            defenderWithSpecialty.VerifySet(creature => creature.CurrentDefense = It.IsAny <int>(), Times.Exactly(rounds));
        }
        public void ApplyWhenDefending_ShouldReturnAndNotChangeCurrentDefenseProperty_WhenTheEffectIsExpired(int rounds)
        {
            var specialty = new DoubleDefenseWhenDefending(rounds);

            var attacker = new Mock <ICreaturesInBattle>();

            var defender = new Mock <ICreaturesInBattle>();

            defender.Setup(x => x.CurrentDefense).Returns(It.IsAny <int>());

            for (int i = 0; i < rounds * 2; i++)
            {
                specialty.ApplyWhenDefending(defender.Object, attacker.Object);
            }

            defender.VerifySet(x => x.CurrentDefense = It.IsAny <int>(), Times.Exactly(rounds));
        }
        public void ApplyWhenDefending_ShouldMultiplyByTwoCurrentDefenseProperty_WhenEffectHasNotExpired()
        {
            var rounds    = 5;
            var defense   = 10;
            var specialty = new DoubleDefenseWhenDefending(rounds);

            var attacker = new Mock <ICreaturesInBattle>();

            var defender = new Mock <ICreaturesInBattle>();

            defender.SetupGet(x => x.CurrentDefense).Returns(defense);

            var currDefense = defender.Object.CurrentDefense;

            specialty.ApplyWhenDefending(defender.Object, attacker.Object);

            defender.VerifySet(x => x.CurrentDefense = defense * 2);
        }