Advertisement
Prohause

UnitTesting

Aug 3rd, 2019
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using NUnit.Framework;
  3.  
  4. namespace Tests
  5. {
  6. public class DatabaseTests
  7. {
  8. private Database database;
  9. private readonly int[] initialData = new int[] { 1, 2 };
  10.  
  11. [SetUp]
  12. public void Setup()
  13. {
  14. database = new Database(initialData);
  15. }
  16.  
  17. [Test]
  18. public void TestCollectionLength()
  19. {
  20. int expectedLength = 2;
  21.  
  22. Assert.That(database.Count, Is.EqualTo(expectedLength));
  23. }
  24.  
  25. [Test]
  26. public void TestCorrectAddintToData()
  27. {
  28. int expectedCount = 3;
  29.  
  30. database.Add(3);
  31.  
  32. Assert.That(database.Count, Is.EqualTo(expectedCount));
  33. }
  34.  
  35. [Test]
  36. public void TestCorrectThrowingExceptionAtAdding()
  37. {
  38. int magicNumber = 16;
  39.  
  40. for (int i = database.Count; i < 16; i++)
  41. {
  42. database.Add(magicNumber);
  43. }
  44.  
  45. Assert.Throws<InvalidOperationException>(() => database.Add(magicNumber));
  46. }
  47.  
  48. [Test]
  49. public void TestCorrectRemoveFromCollection()
  50. {
  51. int expectedCount = 1;
  52.  
  53. database.Remove();
  54.  
  55. Assert.AreEqual(expectedCount, database.Count);
  56. }
  57.  
  58. [Test]
  59. public void TestRemovingFromEmptyCollection()
  60. {
  61. for (int i = database.Count - 1; i >= 0; i--)
  62. {
  63. database.Remove();
  64. }
  65.  
  66. Assert.Throws<InvalidOperationException>(() => database.Remove());
  67. }
  68.  
  69. [Test]
  70. public void TestFetchDatabaseFunction()
  71. {
  72. int[] actualResult = database.Fetch();
  73. CollectionAssert.AreEqual(initialData, actualResult);
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement