Advertisement
gospod1978

UnitTest/Extended Database

Apr 1st, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.21 KB | None | 0 0
  1. using System;
  2. using ExtendedDatabase;
  3. using NUnit.Framework;
  4.  
  5. namespace Tests
  6. {
  7.     public class ExtendedDatabaseTests
  8.     {
  9.  
  10.         private ExtendedDatabase.ExtendedDatabase database;
  11.         //private ExtendedDatabase database;
  12.         private readonly Person person1 = new Person(1, "Pesho");
  13.  
  14.         private readonly Person person2 = new Person(2, "Gosho");
  15.  
  16.         [SetUp]
  17.         public void Setup()
  18.         {
  19.             this.database = new ExtendedDatabase.ExtendedDatabase(person1, person2);
  20.             //this.database = new ExtendedDatabase(person1, person2);
  21.         }
  22.  
  23.         [Test]
  24.         public void TestIfConstructorWorksCorrectliPerson()
  25.         {
  26.             long expId = 3;
  27.             string expName = "Mihso";
  28.  
  29.             Person person = new Person(expId, expName);
  30.  
  31.             long acId = person.Id;
  32.             string acName = person.UserName;
  33.  
  34.             Assert.AreEqual(expId, acId);
  35.             Assert.AreEqual(expName, acName);
  36.  
  37.         }
  38.  
  39.         [Test]
  40.         public void TestIfDataBaseWorkCorrectli()
  41.         {
  42.             Person[] persons = new Person[] { person1, person2 };
  43.             this.database = new ExtendedDatabase.ExtendedDatabase(persons);
  44.             //this.database = new ExtendedDatabase(persons);
  45.  
  46.             int expectedCount = persons.Length;
  47.             int actualCount = this.database.Count;
  48.  
  49.             Assert.AreEqual(expectedCount, actualCount);
  50.         }
  51.  
  52.  
  53.         [Test]
  54.         public void ConstructorShouldThrowExceptionWnehInitialaizingMore()
  55.         {
  56.             Person person1 = new Person(1, "Pesho1");
  57.             Person person2 = new Person(2, "Pesho2");
  58.             Person person3 = new Person(3, "Pesho3");
  59.             Person person4 = new Person(4, "Pesho4");
  60.             Person person5 = new Person(5, "Pesho5");
  61.             Person person6 = new Person(6, "Pesho6");
  62.             Person person7 = new Person(7, "Pesho7");
  63.             Person person8 = new Person(8, "Pesho8");
  64.             Person person9 = new Person(9, "Pesho9");
  65.             Person person10 = new Person(10, "Pesho10");
  66.             Person person11 = new Person(11, "Pesho11");
  67.             Person person12 = new Person(12, "Pesho12");
  68.             Person person13 = new Person(13, "Pesho13");
  69.             Person person14 = new Person(14, "Pesho14");
  70.             Person person15 = new Person(15, "Pesho15");
  71.             Person person16 = new Person(16, "Pesho16");
  72.             Person person17 = new Person(17, "Pesho17");
  73.  
  74.             Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
  75.             person7, person8, person9, person10, person11, person12, person13, person14, person15,
  76.             person16, person17 };
  77.  
  78.             Assert.Throws<ArgumentException>(() =>
  79.             {
  80.                 this.database = new ExtendedDatabase.ExtendedDatabase(persons);
  81.                 //this.database = new ExtendedDatabase(persons);
  82.  
  83.             });
  84.         }
  85.  
  86.         [Test]
  87.         public void AddShoudIncraseCountWhenAddSuccessfully()
  88.         {
  89.             Person person3 = new Person(3, "Pesho3");
  90.             this.database.Add(person3);
  91.             int expectedCount = 3;
  92.             int actualCount = this.database.Count;
  93.  
  94.             Assert.AreEqual(expectedCount, actualCount);
  95.         }
  96.  
  97.         [Test]
  98.         public void AddShuldThrowExceptionFullCount()
  99.         {
  100.             Person person1 = new Person(1, "Pesho1");
  101.             Person person2 = new Person(2, "Pesho2");
  102.             Person person3 = new Person(3, "Pesho3");
  103.             Person person4 = new Person(4, "Pesho4");
  104.             Person person5 = new Person(5, "Pesho5");
  105.             Person person6 = new Person(6, "Pesho6");
  106.             Person person7 = new Person(7, "Pesho7");
  107.             Person person8 = new Person(8, "Pesho8");
  108.             Person person9 = new Person(9, "Pesho9");
  109.             Person person10 = new Person(10, "Pesho10");
  110.             Person person11 = new Person(11, "Pesho11");
  111.             Person person12 = new Person(12, "Pesho12");
  112.             Person person13 = new Person(13, "Pesho13");
  113.             Person person14 = new Person(14, "Pesho14");
  114.             Person person15 = new Person(15, "Pesho15");
  115.             Person person16 = new Person(16, "Pesho16");
  116.             Person person17 = new Person(17, "Pesho17");
  117.  
  118.             Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
  119.             person7, person8, person9, person10, person11, person12, person13, person14, person15,
  120.             person16 };
  121.  
  122.             this.database = new ExtendedDatabase.ExtendedDatabase(persons);
  123.             //this.database = new ExtendedDatabase(persons);
  124.  
  125.             Assert.Throws<InvalidOperationException>(() =>
  126.             {
  127.                 this.database.Add(person17);
  128.  
  129.             });
  130.         }
  131.  
  132.         [Test]
  133.         public void RemoveShoudDecreaseWhenSuccess()
  134.         {
  135.  
  136.             int expectedCount = 1;
  137.  
  138.             this.database.Remove();
  139.  
  140.             int actualCount = this.database.Count;
  141.  
  142.             Assert.AreEqual(expectedCount, actualCount);
  143.  
  144.         }
  145.  
  146.         [Test]
  147.         public void RemoveShouldThrowExceptionIsDataEmpty()
  148.         {
  149.             this.database.Remove();
  150.             this.database.Remove();
  151.  
  152.             Assert.Throws<InvalidOperationException>(() =>
  153.             {
  154.                 this.database.Remove();
  155.  
  156.             });
  157.         }
  158.  
  159.         [Test]
  160.         public void TestIfPersonIdExsistThrowExspetion()
  161.         {
  162.             Person person = new Person(1, "Stefan");
  163.  
  164.             Assert.Throws<InvalidOperationException>(() =>
  165.             {
  166.                 this.database.Add(person);
  167.             });
  168.         }
  169.  
  170.         [Test]
  171.         public void TestIfPersonNameExsistThrowExspetion()
  172.         {
  173.             Person person = new Person(4, "Pesho");
  174.  
  175.             Assert.Throws<InvalidOperationException>(() =>
  176.             {
  177.                 this.database.Add(person);
  178.             });
  179.         }
  180.  
  181.         [Test]
  182.         public void TestFindByUserNameIfUserNoExsistThrowExseption()
  183.         {
  184.            
  185.  
  186.             Assert.Throws<InvalidOperationException>(() =>
  187.             {
  188.                 this.database.FindByUsername("Stefan");
  189.             });
  190.         }
  191.  
  192.         [Test]
  193.         [TestCase(null)]
  194.         public void TestFindByUserNameIfUserIsNullThrowExseption(string name)
  195.         {
  196.             Assert.Throws<ArgumentNullException>(() =>
  197.             {
  198.                 this.database.FindByUsername(name);
  199.             });
  200.         }
  201.  
  202.         [Test]
  203.         public void TestFindByUserNameIfUserIsEmptyThrowExseption()
  204.         {
  205.             string name = String.Empty;
  206.  
  207.             Assert.Throws<ArgumentNullException>(() =>
  208.             {
  209.                 this.database.FindByUsername(name);
  210.             });
  211.         }
  212.  
  213.         [Test]
  214.         public void TestFindByIdIfIdNoExsistThrowExseption()
  215.         {
  216.             long id = 5;
  217.  
  218.             Assert.Throws<InvalidOperationException>(() =>
  219.             {
  220.                 this.database.FindById(id);
  221.             });
  222.         }
  223.  
  224.         [Test]
  225.         public void TestFindByIdIfIdLessZeroThrowExseption()
  226.         {
  227.             long id = -2;
  228.  
  229.             Assert.Throws<ArgumentOutOfRangeException>(() =>
  230.             {
  231.                 this.database.FindById(id);
  232.             });
  233.         }
  234.  
  235.         [Test]
  236.         public void TestAddRangeIfArrayManyThrowException()
  237.         {
  238.             Person person1 = new Person(1, "Pesho1");
  239.             Person person2 = new Person(2, "Pesho2");
  240.             Person person3 = new Person(3, "Pesho3");
  241.             Person person4 = new Person(4, "Pesho4");
  242.             Person person5 = new Person(5, "Pesho5");
  243.             Person person6 = new Person(6, "Pesho6");
  244.             Person person7 = new Person(7, "Pesho7");
  245.             Person person8 = new Person(8, "Pesho8");
  246.             Person person9 = new Person(9, "Pesho9");
  247.             Person person10 = new Person(10, "Pesho10");
  248.             Person person11 = new Person(11, "Pesho11");
  249.             Person person12 = new Person(12, "Pesho12");
  250.             Person person13 = new Person(13, "Pesho13");
  251.             Person person14 = new Person(14, "Pesho14");
  252.             Person person15 = new Person(15, "Pesho15");
  253.             Person person16 = new Person(16, "Pesho16");
  254.             Person person17 = new Person(17, "Pesho17");
  255.  
  256.             Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
  257.             person7, person8, person9, person10, person11, person12, person13, person14, person15,
  258.             person16, person17 };
  259.  
  260.             Assert.Throws<ArgumentException>(() =>
  261.             {
  262.                 this.database = new ExtendedDatabase.ExtendedDatabase(persons);
  263.                 //this.database = new ExtendedDatabase(persons);
  264.             });
  265.         }
  266.  
  267.         [Test]
  268.         public void TestAddRangeAndCheckedTheCount()
  269.         {
  270.             Person person1 = new Person(1, "Pesho1");
  271.             Person person2 = new Person(2, "Pesho2");
  272.             Person person3 = new Person(3, "Pesho3");
  273.             Person person4 = new Person(4, "Pesho4");
  274.             Person person5 = new Person(5, "Pesho5");
  275.             Person person6 = new Person(6, "Pesho6");
  276.             Person person7 = new Person(7, "Pesho7");
  277.             Person person8 = new Person(8, "Pesho8");
  278.             Person person9 = new Person(9, "Pesho9");
  279.             Person person10 = new Person(10, "Pesho10");
  280.             Person person11 = new Person(11, "Pesho11");
  281.             Person person12 = new Person(12, "Pesho12");
  282.             Person person13 = new Person(13, "Pesho13");
  283.             Person person14 = new Person(14, "Pesho14");
  284.            
  285.            
  286.  
  287.             Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
  288.             person7, person8, person9, person10, person11, person12, person13, person14 };
  289.  
  290.            
  291.                 this.database = new ExtendedDatabase.ExtendedDatabase(persons);
  292.                 //this.database = new ExtendedDatabase(persons);
  293.  
  294.             int expCount = 14;
  295.             int actulCount = this.database.Count;
  296.             Assert.AreEqual(expCount, actulCount);
  297.            
  298.         }
  299.  
  300.     }
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement