Advertisement
Guest User

Untitled

a guest
Jul 27th, 2020
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. namespace Robots.Tests
  2. {
  3. using NUnit.Framework;
  4. using System;
  5.  
  6. [TestFixture]
  7. public class RobotsTests
  8. {
  9. [Test]
  10. public void ConstructorShouldInitializeCorrectlyAllProperties()
  11. {
  12. int capacity = 10;
  13. var robotManager = new RobotManager(capacity);
  14.  
  15. int expectedCapacity = 10;
  16.  
  17. int actualCapacity = robotManager.Capacity;
  18.  
  19. Assert.AreEqual(expectedCapacity, actualCapacity);
  20. }
  21.  
  22. [Test]
  23. public void CapacityShouldThrowExceptionIfIsNull()
  24. {
  25. Assert.Throws<ArgumentException>(() =>
  26. new RobotManager(-1));
  27. }
  28.  
  29. [Test]
  30. public void AddRobotShouldThrowExceptionWhenCollectionContainsSameRobot()
  31. {
  32. var robotManager = new RobotManager(5);
  33. var robot = new Robot("TestName", 10);
  34.  
  35. robotManager.Add(robot);
  36.  
  37. // Assert.That(()
  38. //=> robotManager.Add(robot), Throws.InvalidOperationException);
  39.  
  40. Assert.Throws<InvalidOperationException>(()
  41. => robotManager.Add(robot));
  42. }
  43.  
  44. [Test]
  45. public void AddRobotShouldThrowExceptionWhenCapacityIsInvalid()
  46. {
  47. var robotManager = new RobotManager(0);
  48. var robot = new Robot("TestName", 10);
  49.  
  50.  
  51. Assert.Throws<InvalidOperationException>(()
  52. => robotManager.Add(robot));
  53. }
  54.  
  55. [Test]
  56. public void AddRobotShouldAddRobotnWhenCapacityIsValid()
  57. {
  58. var robotManager = new RobotManager(3);
  59. var robot = new Robot("TestName", 10);
  60.  
  61. robotManager.Add(robot);
  62.  
  63. var expectedCount = 1;
  64. var actualCount = robotManager.Count;
  65.  
  66. Assert.AreEqual(expectedCount, actualCount);
  67. }
  68.  
  69. [Test]
  70. public void RemoveRobotShouldThrowExceptionWhenRobotIsNull()
  71. {
  72. var robotManager = new RobotManager(10);
  73.  
  74. Assert.Throws<InvalidOperationException>(()
  75. => robotManager.Remove("RoboTest"));
  76. }
  77.  
  78. [Test]
  79. public void RemoveShouldRemoveRobotWhenNameIsCorrect()
  80. {
  81. var robotManager = new RobotManager(2);
  82. var robot = new Robot("TestName", 10);
  83.  
  84. robotManager.Add(robot);
  85. robotManager.Remove("TestName");
  86.  
  87. var expextedCount = 0;
  88. var actualCount = robotManager.Count;
  89.  
  90. Assert.AreEqual(expextedCount, actualCount);
  91. }
  92.  
  93. [Test]
  94. public void WorkShouldThrowExceptionWhenIsNameNotFound()
  95. {
  96. var robotManager = new RobotManager(10);
  97.  
  98. Assert.Throws<InvalidOperationException>(()
  99. => robotManager.Work("None", "Job", 5));
  100. }
  101.  
  102. [Test]
  103. public void WorkShouldThrowExceptionWhenBaterryIsLow()
  104. {
  105. var robotManager = new RobotManager(4);
  106. var robot = new Robot("TestName", 5);
  107.  
  108. Assert.Throws<InvalidOperationException>(()
  109. => robotManager.Work("TestName", "Job", 10));
  110. }
  111.  
  112. [Test]
  113. public void WorkShouldDecreaseBattery()
  114. {
  115. var robotManager = new RobotManager(10);
  116. var robot = new Robot("TestName", 10);
  117.  
  118. robotManager.Add(robot);
  119. robotManager.Work("TestName", "None", 5);
  120.  
  121. var expectedBattery = 5;
  122. var actualBattery = robot.Battery;
  123.  
  124. Assert.AreEqual(expectedBattery, actualBattery);
  125. }
  126.  
  127. [Test]
  128. public void ChargeShouldThrowExceptionWhenRobotIsNotFound()
  129. {
  130. var robotManager = new RobotManager(10);
  131.  
  132. Assert.Throws<InvalidOperationException>(()
  133. => robotManager.Charge("TestName"));
  134. }
  135.  
  136. [Test]
  137. public void ChargeShouldChargeRobot()
  138. {
  139. var robotManager = new RobotManager(10);
  140. var robot = new Robot("Test", 10);
  141.  
  142. robot.Battery = 5;
  143.  
  144. robotManager.Add(robot);
  145. robotManager.Charge("Test");
  146.  
  147. var expectedBattery = 10;
  148. var actualBattery = robot.Battery;
  149.  
  150. Assert.AreEqual(expectedBattery, actualBattery);
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement