Example #1
0
        public void AttackMethod_AppropriatelyCorrectlyCalculatesDamage()
        {
            var expectedDamageDone = _factoryFighter.Strength;

            _enemy.SetDefense(0);
            _enemy.SetHealth(_factoryFighter.Strength + 1);
            var damageDone = _factoryFighter.Attack(_enemy);

            Assert.AreEqual(_enemy.MaxHealth - (expectedDamageDone), _enemy.CurrentHealth);
            Assert.AreEqual(_enemy.MaxHealth - damageDone, _enemy.CurrentHealth);

            _armoredEnemy.SetDefense(_factoryFighter.Strength - 1);
            _armoredEnemy.SetHealth(2);
            damageDone         = _factoryFighter.Attack(_armoredEnemy);
            expectedDamageDone = 1;

            Assert.AreEqual(_armoredEnemy.MaxHealth - (expectedDamageDone), _armoredEnemy.CurrentHealth);
            Assert.AreEqual(expectedDamageDone, damageDone);

            _superArmoredEnemy.SetDefense(_factoryFighter.Strength + 2);
            damageDone         = _factoryFighter.Attack(_superArmoredEnemy);
            expectedDamageDone = 0;

            Assert.AreEqual(_superArmoredEnemy.MaxHealth, _superArmoredEnemy.CurrentHealth);
            Assert.AreEqual(expectedDamageDone, damageDone);
        }
Example #2
0
        public void AttackMethod_AppropriatelyRaisesEvents_WhenEnemySurvives()
        {
            var expectedDamage = _fighter.Strength - _enemy.Defense;

            _enemy.SetHealth(expectedDamage + 1);

            _fighter.Attack(_enemy);

            var logs = _logger.Logs;

            Assert.AreEqual(2, logs.Count);

            Assert.AreEqual(EventType.DamageTaken, logs[0].Type);
            Assert.AreEqual(_enemy, logs[0].Sender);
            PhysicalDamageTakenEventArgs e1 = logs[0].E as PhysicalDamageTakenEventArgs;

            Assert.NotNull(e1);
            Assert.AreEqual(expectedDamage, e1.Damage);

            Assert.AreEqual(EventType.AttackSuccessful, logs[1].Type);
            Assert.AreEqual(_fighter, logs[1].Sender);
            AttackSuccessfulEventArgs e2 = logs[1].E as AttackSuccessfulEventArgs;

            Assert.NotNull(e2);
            Assert.AreEqual(expectedDamage, e2.DamageDealt);
        }
Example #3
0
        public void AttackMethod_AppropriatelyRaisesEvents_WhenEnemyDies()
        {
            _fighter = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "Ted");
            _logger.SubscribeAll(_fighter);

            _fighter.SetStrength(_enemy.MaxHealth + 1);

            _fighter.Attack(_enemy);

            var logs = _logger.Logs;

            Assert.AreEqual(4, logs.Count);

            //first event, damage taken
            Assert.AreEqual(EventType.DamageTaken, logs[0].Type);
            Assert.AreEqual(_enemy, logs[0].Sender);
            PhysicalDamageTakenEventArgs e1 = logs[0].E as PhysicalDamageTakenEventArgs;

            Assert.NotNull(e1);
            Assert.AreEqual(_fighter.Strength, e1.Damage);

            //second event, killed - fired by enemy
            Assert.AreEqual(EventType.Killed, logs[1].Type);
            Assert.AreEqual(_enemy, logs[1].Sender);
            KilledEventArgs e2 = logs[1].E as KilledEventArgs;

            Assert.That(e2, Is.Not.Null);

            //third event, damageDealt to enemy
            Assert.AreEqual(EventType.AttackSuccessful, logs[2].Type);
            Assert.AreEqual(_fighter, logs[2].Sender);
            AttackSuccessfulEventArgs e3 = logs[2].E as AttackSuccessfulEventArgs;

            Assert.NotNull(e3);
            Assert.AreEqual(_enemy.MaxHealth, e3.DamageDealt);

            //fourth event, killed enemy
            Assert.AreEqual(EventType.EnemyKilled, logs[3].Type);
            Assert.AreEqual(_fighter, logs[3].Sender);
            EnemyKilledEventArgs e4 = logs[3].E as EnemyKilledEventArgs;

            Assert.NotNull(e4);
            Assert.AreEqual(_enemy, e4.Enemy);
        }