Advertisement
svetlyoek

Untitled

Aug 11th, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. namespace BlueOrigin.Tests
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using NUnit.Framework;
  6.  
  7. public class SpaceshipTests
  8. {
  9. private Spaceship spaceship;
  10. private List<Astronaut> astronauts;
  11.  
  12. [SetUp]
  13. public void SetUp()
  14. {
  15. this.spaceship = new Spaceship("Name", 1);
  16. this.astronauts = new List<Astronaut>();
  17. }
  18.  
  19. [Test]
  20. public void TestConstructorIfWorksCorrectly()
  21. {
  22. Assert.AreEqual("Name", this.spaceship.Name);
  23. Assert.AreEqual(1, this.spaceship.Capacity);
  24. Assert.AreEqual(0, this.astronauts.Count);
  25. }
  26.  
  27. [Test]
  28. public void TestCountShouldWorkCorrectly()
  29. {
  30. var astronaut = new Astronaut("Ivan", 20.5);
  31. this.astronauts.Add(astronaut);
  32.  
  33. Assert.AreEqual(1, this.astronauts.Count);
  34. }
  35.  
  36. [Test]
  37. public void TestSpaceshipNameShouldThrowExceptionWhenNull()
  38. {
  39. Assert.Throws<ArgumentNullException>(() =>
  40. {
  41. var spaceship = new Spaceship(null, 13);
  42.  
  43. });
  44. }
  45.  
  46. [Test]
  47. public void TestSpaceshipNameShouldThrowExceptionWhenEmpty()
  48. {
  49. Assert.Throws<ArgumentNullException>(() =>
  50. {
  51. var spaceship = new Spaceship("", 13);
  52.  
  53. });
  54. }
  55.  
  56. [Test]
  57. public void TestSpaceshipCapacityShouldThrowExceptionWhenNegative()
  58. {
  59. Assert.Throws<ArgumentException>(() =>
  60. {
  61. var spaceship = new Spaceship("Dimo", -1);
  62.  
  63. });
  64. }
  65.  
  66. [Test]
  67. public void TestAddShouldThrowExceptionWhenCapacityIsFull()
  68. {
  69. var astronaut = new Astronaut("Ivan", 20.5);
  70. this.spaceship.Add(astronaut);
  71.  
  72. Assert.Throws<InvalidOperationException>(() =>
  73. {
  74. this.spaceship.Add(new Astronaut("Svetlio", 23.5));
  75. });
  76. }
  77.  
  78. [Test]
  79. public void TestAddShouldThrowExceptionWhenAstronautExists()
  80. {
  81. this.spaceship = new Spaceship("Name2", 3);
  82. var astronaut = new Astronaut("Ivan", 20.5);
  83. this.spaceship.Add(astronaut);
  84.  
  85. Assert.Throws<InvalidOperationException>(() =>
  86. {
  87. this.spaceship.Add(astronaut);
  88. });
  89. }
  90.  
  91. [Test]
  92. public void TestAddShouldWorksCorrectly()
  93. {
  94. var spaceship = new Spaceship("Space", 3);
  95.  
  96. var astronaut = new Astronaut("Pesho", 20.5);
  97. var astronaut2 = new Astronaut("Sasho", 20.5);
  98. this.astronauts.Add(astronaut);
  99. this.astronauts.Add(astronaut2);
  100.  
  101. spaceship.Add(astronaut);
  102. spaceship.Add(astronaut2);
  103.  
  104. Assert.AreEqual(2, this.astronauts.Count);
  105.  
  106. }
  107.  
  108. [Test]
  109. public void TestRemoveShouldWorksCorrectly()
  110. {
  111. var astronaut = new Astronaut("Ivan", 20.5);
  112. this.spaceship.Add(astronaut);
  113.  
  114. Assert.IsTrue(this.spaceship.Remove(astronaut.Name));
  115.  
  116. }
  117.  
  118. [Test]
  119. public void TestRemoveShouldReturnFalseIfNoRemove()
  120. {
  121. var astronaut = new Astronaut("Ivan", 20.5);
  122. this.spaceship.Add(astronaut);
  123.  
  124. Assert.IsFalse(this.spaceship.Remove("Dimitar"));
  125.  
  126. }
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement