petarkobakov

RobotFactoryTests

Apr 8th, 2023 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. using NUnit.Framework;
  2.  
  3. namespace RobotFactory.Tests
  4. {
  5. public class Tests
  6. {
  7. Supplement supplement;
  8. Robot robot;
  9. Factory factory;
  10.  
  11. [SetUp]
  12. public void Setup()
  13. {
  14. supplement = new Supplement("Supplement", 3);
  15. robot = new Robot("Robot", 3.50, 5);
  16. factory = new Factory("Factory", 2);
  17. }
  18.  
  19. [TearDown]
  20. public void TearDown()
  21. {
  22. supplement = null;
  23. robot = null;
  24. factory = null;
  25. }
  26.  
  27. [Test]
  28. public void SupplementCreateTest()
  29. {
  30.  
  31. Assert.AreEqual(supplement.Name, "Supplement");
  32. Assert.AreEqual(supplement.InterfaceStandard, 3);
  33. Assert.AreEqual(supplement.ToString(), "Supplement: Supplement IS: 3");
  34. }
  35.  
  36. [Test]
  37. public void RobotCreateTest()
  38. {
  39. Assert.AreEqual(robot.Model, "Robot");
  40. Assert.AreEqual(robot.Price, 3.50);
  41. Assert.AreEqual(robot.InterfaceStandard, 5);
  42. Assert.AreEqual(robot.Supplements.Count, 0);
  43. Assert.AreEqual(robot.ToString(), "Robot model: Robot IS: 5, Price: 3.50");
  44. }
  45.  
  46. [Test]
  47. public void FactoryConstructorTest()
  48. {
  49. Assert.AreEqual(factory.Name, "Factory");
  50. Assert.AreEqual(factory.Capacity, 2);
  51. Assert.AreEqual(factory.Robots.Count, 0);
  52. Assert.AreEqual(factory.Supplements.Count, 0);
  53.  
  54. }
  55.  
  56. [Test]
  57. public void ProduceRobotValidationTest()
  58. {
  59. factory = new Factory("test", 1);
  60.  
  61. factory.ProduceRobot("test", 2.5, 2);
  62. Assert.That(() => factory.ProduceRobot("test", 2.5, 2), Is.EqualTo("The factory is unable to produce more robots for this production day!"));
  63. }
  64.  
  65. [Test]
  66. public void ProduceRobotTest()
  67. {
  68. Robot testRobot = new Robot("test", 2.5, 2);
  69. Assert.That(() => factory.ProduceRobot("test", 2.5, 2), Is.EqualTo($"Produced --> {testRobot}"));
  70. Assert.AreEqual(factory.Robots.Count, 1);
  71. }
  72.  
  73. [Test]
  74. public void ProduceSupplementTest()
  75. {
  76. Assert.That(() => factory.ProduceSupplement("test", 2), Is.EqualTo("Supplement: test IS: 2"));
  77. Assert.AreEqual(factory.Supplements.Count, 1);
  78. }
  79.  
  80. [Test]
  81. public void UpgradeRobotValidationTest()
  82. {
  83. robot.Supplements.Add(supplement);
  84. Assert.That(() => factory.UpgradeRobot(robot, supplement), Is.EqualTo(false));
  85.  
  86. robot = new Robot("test", 2.5, 5);
  87. Assert.That(() => factory.UpgradeRobot(robot, supplement), Is.EqualTo(false));
  88. }
  89.  
  90. [Test]
  91. public void UpgradeRobotTest()
  92. {
  93. supplement = new Supplement("test", 5);
  94. Assert.That(() => factory.UpgradeRobot(robot, supplement), Is.EqualTo(true));
  95. Assert.AreEqual(robot.Supplements.Count, 1);
  96. }
  97.  
  98. [Test]
  99. public void SellRobotTest()
  100. {
  101. Robot test1 = new Robot("test", 5, 5);
  102. Robot test2 = new Robot("test", 4, 5);
  103. factory.Robots.Add(robot);
  104. factory.Robots.Add(test1);
  105. factory.Robots.Add(test2);
  106.  
  107. Assert.That(() => factory.SellRobot(4), Is.EqualTo(test2));
  108. }
  109.  
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment