Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.86 KB | None | 0 0
  1. using NUnit.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4.  
  5. namespace Tests
  6. {
  7.     public class ExtendedDatabaseTests
  8.     {
  9.         private Person pesho;
  10.         private Person gosho;
  11.         private Person[] persons;
  12.         private ExtendedDatabase database;
  13.         [SetUp]
  14.         public void Setup()
  15.         {
  16.             pesho = new Person(2130931, "Pesho");
  17.             gosho = new Person(1320109, "Gosho");
  18.         }
  19.  
  20.         [Test]
  21.         public void TestIfPersonIsCreatedSuccessfully()
  22.         {
  23.             string userName = "Pesho";
  24.             long id = 23912390120;
  25.             Person person = new Person(id, userName);
  26.  
  27.             Assert.AreEqual(userName, person.UserName);
  28.             Assert.AreEqual(id, person.Id);
  29.         }
  30.  
  31.         [Test]
  32.         public void TestIfIsInitialized()
  33.         {
  34.             Assert.AreNotEqual(null, this.database);
  35.         }
  36.  
  37.         [Test]
  38.         public void TestIfCountIncreases()
  39.         {
  40.             this.persons = new Person[] { pesho, gosho };
  41.             int expectedCount = 2;
  42.             Assert.AreEqual(expectedCount, persons.Length);
  43.         }
  44.  
  45.         [Test]
  46.         public void TestIfAddThrowsExceptionWhenElementsGoOverCapacity()
  47.         {
  48.             this.persons = new Person[17];
  49.  
  50.             Assert.Throws<ArgumentException>(() =>
  51.             {
  52.                 this.database = new ExtendedDatabase(this.persons);
  53.             });
  54.         }
  55.         [Test]
  56.         public void TestIfAddThrowsExceptionWhenItHasTwoPeopleWithTheSameUserName()
  57.         {
  58.             Person newPerson = new Person(21312312, "Pesho");
  59.             this.persons = new Person[] { pesho, gosho, newPerson };
  60.             Assert.Throws<InvalidOperationException>(() =>
  61.             {
  62.                 this.database = new ExtendedDatabase(persons);
  63.             });
  64.         }
  65.  
  66.         [Test]
  67.         public void TestIfAddThrowsExceptionWhenItHasPeopleWithTheSameId()
  68.         {
  69.             Person newPerson = new Person(1320109, "Pesho");
  70.             this.persons = new Person[] { pesho, gosho, newPerson };
  71.  
  72.             Assert.Throws<InvalidOperationException>(() =>
  73.             {
  74.                 this.database = new ExtendedDatabase(persons);
  75.             });
  76.         }
  77.  
  78.         [Test]
  79.         public void TestIfRemoveDoesntExecuteEmptyCollection()
  80.         {
  81.             this.persons = new Person[] { };
  82.             this.database = new ExtendedDatabase(persons);
  83.  
  84.             Assert.Throws<InvalidOperationException>(() =>
  85.             {
  86.                 this.database.Remove();
  87.             });
  88.         }
  89.         [Test]
  90.         public void TestIfRemoveThrowsExceptionWhenCollectionBecomesEmpty()
  91.         {
  92.             this.persons = new Person[] { pesho, gosho };
  93.             this.database = new ExtendedDatabase(persons);
  94.  
  95.             this.database.Remove();
  96.             this.database.Remove();
  97.  
  98.             Assert.Throws<InvalidOperationException>(() =>
  99.             {
  100.                 this.database.Remove();
  101.             });
  102.         }
  103.         [Test]
  104.         public void TestIfItThrowsExceptionWhenCountReaches16()
  105.         {
  106.             this.persons = new Person[] { pesho, gosho, new Person(213124, "Ivan"), new Person(2166124, "sss"), new Person(90345834, "asdsa"), new Person(123456677, "azsum"), new Person(131243, "tozi"), new Person(8888888, "koito"), new Person(6960606, "vie"), new Person(230943809423234, "ne"), new Person(090909090909, "sadsadsadqwewq"), new Person(974761236123884, "Ivagxfn"), new Person(23043444444, "asdlksajdklsaWW"), new Person(213333344444, "omg"), new Person(300020209, "stammme"), new Person(3055032, "forthelast") };
  107.  
  108.             this.database = new ExtendedDatabase(persons);
  109.  
  110.             Assert.Throws<InvalidOperationException>(() =>
  111.             {
  112.                 this.database.Add(new Person(0923401, "yeet"));
  113.             });
  114.         }
  115.         [Test]
  116.         public void TestIfRemoveDecreasesCount()
  117.         {
  118.             this.persons = new Person[] { gosho, pesho };
  119.             this.database = new ExtendedDatabase(persons);
  120.             this.database.Remove();
  121.             int expectedCount = 1;
  122.  
  123.             Assert.AreEqual(expectedCount, this.database.Count);
  124.         }
  125.  
  126.         [TestCase(null)]
  127.         [TestCase("")]
  128.         public void TestIfFindByUsernameThrowsExceptionWithNullOrEmptyValues(string name)
  129.         {
  130.             this.persons = new Person[] { gosho, pesho };
  131.             this.database = new ExtendedDatabase(persons);
  132.  
  133.             Assert.Throws<ArgumentNullException>(() =>
  134.             {
  135.                 this.database.FindByUsername(name);
  136.             });
  137.         }
  138.  
  139.         [Test]
  140.         public void TestIfFindByUsernameThrowsExceptionWhenUsernameIsNotPresent()
  141.         {
  142.             this.persons = new Person[] { gosho, pesho };
  143.             this.database = new ExtendedDatabase(persons);
  144.  
  145.             Assert.Throws<InvalidOperationException>(() =>
  146.             {
  147.                 this.database.FindByUsername("Ivan");
  148.             });
  149.         }
  150.         [Test]
  151.         public void TestIfFindByUsernameReturnsCorrectPerson()
  152.         {
  153.             this.persons = new Person[] { gosho, pesho };
  154.             this.database = new ExtendedDatabase(persons);
  155.  
  156.             Person expectedPerson = pesho;
  157.             Person actualPerson = this.database.FindByUsername("Pesho");
  158.  
  159.             Assert.AreEqual(expectedPerson, actualPerson);
  160.         }
  161.         [Test]
  162.         public void FindByUsernameIsCaseSensitive()
  163.         {
  164.             this.persons = new Person[] { pesho, gosho };
  165.             this.database = new ExtendedDatabase(persons);
  166.  
  167.             Assert.Throws<InvalidOperationException>(() =>
  168.             {
  169.                 this.database.FindByUsername("GOSHO");
  170.             });
  171.         }
  172.         [Test]
  173.         public void TestIfFindByIdThrowsExceptionWithNegativeValue()
  174.         {
  175.             this.persons = new Person[] { gosho, pesho };
  176.             this.database = new ExtendedDatabase(persons);
  177.  
  178.             Assert.Throws<ArgumentOutOfRangeException>(() =>
  179.             {
  180.                 this.database.FindById(-2312321);
  181.             });
  182.         }
  183.  
  184.         [Test]
  185.         public void TestIfFindByIdThrowsExceptionWhenItDoesntContainId()
  186.         {
  187.             this.persons = new Person[] { gosho, pesho };
  188.             this.database = new ExtendedDatabase(persons);
  189.  
  190.             Assert.Throws<InvalidOperationException>(() =>
  191.             {
  192.                 this.database.FindById(213213123131232123);
  193.             });
  194.         }
  195.  
  196.         [Test]
  197.         public void TestIfFindByIdReturnsCorrectPerson()
  198.         {
  199.             this.persons = new Person[] { gosho, pesho };
  200.             this.database = new ExtendedDatabase(persons);
  201.  
  202.             Person expectedPerson = pesho;
  203.             Person actualPerson = this.database.FindById(2130931);
  204.  
  205.             Assert.AreEqual(expectedPerson, actualPerson);
  206.         }
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement