elena1234

NUnit sintax

May 7th, 2021 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. using NUnit.Framework;
  2. using System;
  3.  
  4. namespace Tests
  5. {
  6.     [TestFixture]
  7.     public class AxeTests
  8.     {
  9.         private Dummy target;
  10.  
  11.         [SetUp]
  12.        public void SetTarget()
  13.         {
  14.             target = new Dummy(20, 50); // replace with target
  15.         }
  16.  
  17.         [Test]
  18.         public void AxeShouldLosesDurabilityAfterEachAttack()
  19.         {
  20.             //Arrange
  21.             Axe axe = new Axe(30, 40);
  22.  
  23.             //Act
  24.             axe.Attack(this.target); // replace with target
  25.             var result = axe.DurabilityPoints;
  26.  
  27.             //Assert
  28.             Assert.That(result, Is.EqualTo(39), "Axe loses durability after attack.");
  29.         }
  30.  
  31.         [Test]
  32.         public void AttackingWithBrokenAxeShouldThrowExeption()
  33.         {
  34.             //Arrage
  35.             Axe axe = new Axe(10, 1);
  36.  
  37.             //Act
  38.             axe.Attack(this.target); // replace with target
  39.  
  40.             //Assert
  41.             Assert.Throws<InvalidOperationException>(() => throw new InvalidOperationException("Axe is broken"));
  42.         }
  43.     }
  44.  
  45.  
  46.     [TestFixture]
  47.     public class DummyTest
  48.     {
  49.         private Dummy aliveDummy;
  50.         private Dummy deadDummy;
  51.  
  52.         [SetUp]
  53.         public void SetUpDummies ()
  54.         {
  55.             deadDummy =  new Dummy(0, 10);
  56.             aliveDummy = new Dummy(40, 10);
  57.         }
  58.  
  59.         [Test]
  60.         public void DummyShouldLosesHealthIfAttacked()
  61.         {
  62.             // Arrange
  63.             // Act
  64.             aliveDummy.TakeAttack(30);
  65.  
  66.             // Assert
  67.             Assert.That(this.aliveDummy.Health, Is.EqualTo(10));
  68.         }
  69.  
  70.         [Test]
  71.         public void DeadDummyShouldThrowsExceptionIfAttacked()
  72.         {
  73.             // Arrange
  74.             // Act
  75.             // Assert
  76.             Assert.That(() => this.deadDummy.TakeAttack(30), Throws.InvalidOperationException.With.Message.EqualTo("Dummy is dead."), "Dead Dummy can't be attacked");
  77.         }
  78.  
  79.         [Test]
  80.         public void DeadDummyCanGiveXP()
  81.         {
  82.             // Arrange
  83.  
  84.             // Act
  85.             var experience = this.deadDummy.GiveExperience();
  86.  
  87.             // Assert
  88.             Assert.That(experience, Is.EqualTo(10), "Dead Dummy Can give experiance");
  89.         }
  90.  
  91.         [Test]
  92.         public void AliveDummyCantGiveXP()
  93.         {
  94.             // Arrange
  95.             // Act
  96.             // Assert
  97.             Assert.That(() => this.aliveDummy.GiveExperience(),Throws.InvalidOperationException.With.Message.EqualTo("Target is not dead."));
  98.         }
  99.     }
  100. }
  101.  
  102. // Assert.Throws<ArgumentOutOfRangeException>(() => extendedDatabase.FindById(-1), "Id should be a positive number!");
  103.  
  104.  Assert.Throws<ArgumentException>(()=> productStock.FindByLabel("testProduct5"),"The product does not exist in Stock")
  105.  
  106. // Assert.That(() => arena.Warriors, Has.Member(firstWarrior));
Add Comment
Please, Sign In to add comment