softy_02

ArenaTests

Jul 5th, 2020
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using NUnit.Framework;
  5.  
  6. namespace Tests
  7. {
  8.     using FightingArena;
  9.     public class ArenaTests
  10.     {
  11.         private Arena arena;
  12.         private List<Warrior> warriors;
  13.         [SetUp]
  14.         public void Setup()
  15.         {
  16.             this.arena = new Arena();
  17.             this.warriors = new List<Warrior>
  18.             {
  19.                 new Warrior("Achilles", 120, 240),
  20.                 new Warrior("Hector", 130, 260),
  21.                 new Warrior("Thor", 180, 360)
  22.             };
  23.         }
  24.  
  25.         [Test]
  26.         public void CheckIfIReadOnlyCollectionOfWarriorsWorksProperly()
  27.         {
  28.             this.EnrollDefaultWarriors();
  29.             var expectedCollection = this.warriors;
  30.             var actualCollection = this.arena.Warriors;
  31.  
  32.             CollectionAssert.AreEqual(expectedCollection, actualCollection);
  33.         }
  34.  
  35.         [Test]
  36.         public void CheckIfEnrollWorksProperly()
  37.         {
  38.             this.EnrollDefaultWarriors();
  39.  
  40.             var expectedCount = 3;
  41.             var actualCount = this.arena.Count;
  42.  
  43.             Assert.AreEqual(expectedCount, actualCount);
  44.         }
  45.  
  46.         [TestCase("Achilles", 499, 781)]
  47.         [TestCase("Hector", 888, 292)]
  48.         [TestCase("Thor", 1282, 999)]
  49.         public void EnrollShouldThrowExceptionWhenThereIsSuchWarrior
  50.             (string name, int damage, int hp)
  51.         {
  52.             this.EnrollDefaultWarriors();
  53.  
  54.             var warrior = new Warrior(name, damage, hp);
  55.  
  56.             Assert.Throws<InvalidOperationException>(() =>
  57.             {
  58.                 this.arena.Enroll(warrior);
  59.             });
  60.         }
  61.  
  62.         [Test]
  63.         public void CheckIfAttackWorksProperly()
  64.         {
  65.             this.EnrollDefaultWarriors();
  66.             var attacker = this.arena.Warriors.First(w => w.Name == "Achilles");
  67.             var defender = this.arena.Warriors.First(w => w.Name == "Hector");
  68.  
  69.             var expectedHp = defender.HP - attacker.Damage;
  70.  
  71.             if (expectedHp < 0)
  72.             {
  73.                 expectedHp = 0;
  74.             }
  75.            
  76.             this.arena.Fight("Achilles", "Hector");
  77.  
  78.             var actualHp = defender.HP;
  79.  
  80.             Assert.AreEqual(expectedHp, actualHp);
  81.  
  82.         }
  83.  
  84.         [TestCase(null, "Hector")]
  85.         [TestCase("Achilles", null)]
  86.        
  87.         public void FightShouldThrowExceptionWhenInvalidPlayer(string attacker, string defender)
  88.         {
  89.             this.EnrollDefaultWarriors();
  90.             Assert.Throws<InvalidOperationException>(() =>
  91.             {
  92.                 this.arena.Fight(attacker, defender);
  93.             });
  94.         }
  95.         private void EnrollDefaultWarriors()
  96.         {
  97.             foreach (var warrior in this.warriors)
  98.             {
  99.                 this.arena.Enroll(warrior);
  100.             }
  101.         }
  102.     }
  103. }
Add Comment
Please, Sign In to add comment