Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using NUnit.Framework;
- namespace Tests
- {
- using FightingArena;
- public class WarriorTests
- {
- private Warrior warrior;
- [SetUp]
- public void Setup()
- {
- this.warrior = new Warrior("Hector", 88, 100);
- }
- [Test]
- public void CheckIfConstructorWorksProperly()
- {
- var expectedName = "Achilles";
- var expectedDamage = 92;
- var expectedHp = 108;
- this.warrior = new Warrior(expectedName, expectedDamage, expectedHp);
- var actualName = this.warrior.Name;
- var actualDamage = this.warrior.Damage;
- var actualHp = this.warrior.HP;
- Assert.AreEqual(expectedName, actualName);
- Assert.AreEqual(expectedDamage, actualDamage);
- Assert.AreEqual(expectedHp, actualHp);
- }
- //Create different test for each unit
- [TestCase(null, 55, 99)]
- [TestCase(" ", 98, 67)]
- [TestCase("", 78, 53)]
- [TestCase("Michael", 0, 34)]
- [TestCase("Pesho", -23, 39)]
- [TestCase("Nial", 55, -12)]
- public void CheckIfPropertiesThrowExceptionsWithInvalidData
- (string name, int damage, int hp)
- {
- Assert.Throws<ArgumentException>(() =>
- {
- this.warrior = new Warrior(name, damage, hp);
- });
- }
- [TestCase("Brown", 32, 31)]
- [TestCase("Brown", 32, 89)]
- public void CheckIfAttackWorksProperlyWithValidValues
- (string name, int damage, int hp)
- {
- var defender = new Warrior(name, damage, hp);
- var expectedHp = this.warrior.HP - defender.Damage;
- int expectedDefenderHp;
- if (defender.HP > this.warrior.Damage)
- {
- expectedDefenderHp = defender.HP - this.warrior.Damage;
- }
- else
- {
- expectedDefenderHp = 0;
- }
- this.warrior.Attack(defender);
- Assert.AreEqual(expectedHp, warrior.HP);
- Assert.AreEqual(expectedDefenderHp, defender.HP);
- }
- [TestCase(30)]
- [TestCase(16)]
- [TestCase(0)]
- public void AttackShouldThrowExceptionWhenAttackerHpAreLessThanMinimumHp(int hp)
- {
- var attacker = new Warrior("Silver", 90, hp);
- Assert.Throws<InvalidOperationException>(() =>
- {
- attacker.Attack(this.warrior);
- });
- }
- [TestCase(30)]
- [TestCase(13)]
- [TestCase(0)]
- public void AttackShouldThrowExceptionWhenDefenderHpAreLessThanMinimumHp(int hp)
- {
- var defender = new Warrior("Shogun", 45, hp);
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.warrior.Attack(defender);
- });
- }
- [TestCase("Achilles", 110, 120)]
- [TestCase("Thor", 400, 540)]
- [TestCase("Zeus", 250, 230)]
- public void AttackShouldThrowExceptionWhenTryingToAttackStrongerEnemy(
- string name, int damage, int hp)
- {
- var enemy = new Warrior(name, damage, hp);
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.warrior.Attack(enemy);
- });
- }
- }
- }
Add Comment
Please, Sign In to add comment