public void AttackMethods_ShouldThrow_ExceptionIfLessHPThanDefender()
        {
            //Arrange
            Warrior attacker = new Warrior("Kanalin", 10, 35);
            Warrior enemy    = new Warrior("Tsolo", 40, 100);

            //Act

            //Assert
            Assert.Throws <InvalidOperationException>(() => attacker.Attack(enemy));
        }
        public void AttackMethods_ShouldThrow_ExceptionIfAttackerHasBellowMinimumHP()
        {
            //Arrange
            Warrior attacker = new Warrior("Kanalin", 10, 20);
            Warrior enemy    = new Warrior("Tsolo", 5, 45);

            //Act

            //Assert
            Assert.Throws <InvalidOperationException>(() => attacker.Attack(enemy));
        }
Example #3
0
        public void TestThatAttacerKilledEnemy()
        {
            int expectedattackerHp = 155;
            int expectedDefenderHP = 0;

            var attacker = new Warrior("Pesho", 100, 200);
            var defender = new Warrior("Gosho", 45, 40);

            attacker.Attack(defender);

            Assert.AreEqual(expectedattackerHp, attacker.HP);
            Assert.AreEqual(expectedDefenderHP, defender.HP);
        }
        public void AttackMethods_CorrectlySets_EnemyHPWhenKilledAndAttackedHP()
        {
            //Arrange
            int expectedAttackerHP = 55;
            int expectedEnemyHP    = 0;

            Warrior attacker = new Warrior("Kanalin", 50, 100);
            Warrior enemy    = new Warrior("Tsolo", 45, 40);

            //Act
            attacker.Attack(enemy);

            //Assert
            Assert.AreEqual(expectedAttackerHP, attacker.HP);
            Assert.AreEqual(expectedEnemyHP, enemy.HP);
        }
        public void AttackMethods_ShouldWork_Correctly()
        {
            //Arrange
            int expectedAttackerHp = 95;
            int expectedDefenderHp = 80;


            Warrior attacker = new Warrior("Kanalin", 10, 100);
            Warrior defender = new Warrior("Tsolo", 5, 90);

            //Act
            attacker.Attack(defender);

            //Assert
            Assert.AreEqual(expectedAttackerHp, attacker.HP);
            Assert.AreEqual(expectedDefenderHp, defender.HP);
        }
        public void Fight(string attackerName, string defenderName)
        {
            Warrior attacker = this.warriors.FirstOrDefault(w => w.Name == attackerName);
            Warrior defender = this.warriors.FirstOrDefault(w => w.Name == defenderName);

            if (attacker == null || defender == null)
            {
                string missingName = attackerName;

                if (defender == null)
                {
                    missingName = defenderName;
                }

                throw new InvalidOperationException($"There is no fighter with name {missingName} enrolled for the fights!");
            }

            attacker.Attack(defender);
        }