krasizorbov

ExtendedDatabase

Aug 3rd, 2019
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.38 KB | None | 0 0
  1. using ExtendedDatabase;
  2. using NUnit.Framework;
  3. using System;
  4. using System.Linq;
  5.  
  6. namespace Tests
  7. {
  8.     public class ExtendedDatabaseTests
  9.     {
  10.         private Person pesho;
  11.         private Person gosho;
  12.         [SetUp]
  13.         public void Setup()
  14.         {
  15.             pesho = new Person(11223344, "Pesho");
  16.             gosho = new Person(55667788, "Gosho");
  17.         }
  18.  
  19.         [Test]
  20.         public void ConstructorPersonShouldInitializeCollection()
  21.         {
  22.             Assert.IsNotNull(pesho);
  23.         }
  24.         [Test]
  25.         public void ConstructorExtendedDBShouldInitializeCollection()
  26.         {
  27.             var expected = new Person[] { pesho, gosho };
  28.  
  29.             var db = new ExtendedDatabase.ExtendedDatabase(expected);
  30.  
  31.             Assert.IsNotNull(db);
  32.         }
  33.         [Test]
  34.         public void TestAddRangeMoreThan15()
  35.         {
  36.             var persons = new Person[16];
  37.  
  38.             Assert.Throws<ArgumentException>(() =>
  39.             {
  40.                 var db = new ExtendedDatabase.ExtendedDatabase(persons);
  41.             });
  42.         }
  43.         [Test]
  44.         public void TestAddRangeNormalConditions()
  45.         {
  46.             var persons = new Person[] {pesho, gosho };
  47.  
  48.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  49.  
  50.             int expectedCount = 2;
  51.  
  52.             Assert.AreEqual(expectedCount, db.Count);
  53.         }
  54.         [Test]
  55.         public void TestShouldAddPerson()
  56.         {
  57.             var persons = new Person[] { pesho, gosho };
  58.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  59.             var newPerson = new Person(123456789, "Stamat");
  60.             db.Add(newPerson);
  61.  
  62.             int expectedCount = 3;
  63.  
  64.             Assert.AreEqual(expectedCount, db.Count);
  65.         }
  66.         [Test]
  67.         public void AddSameUsernameShouldThrow()
  68.         {
  69.             var persons = new Person[] { pesho, gosho };
  70.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  71.             var newPerson = new Person(11223344, "Gosho");
  72.  
  73.             Assert.That(() => db.Add(newPerson), Throws.InvalidOperationException);
  74.         }
  75.         [Test]
  76.         public void AddSameIdShouldThrow()
  77.         {
  78.             var persons = new Person[] { pesho, gosho };
  79.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  80.             var newPerson = new Person(11223344, "Stamat");
  81.  
  82.             Assert.That(() => db.Add(newPerson), Throws.InvalidOperationException);
  83.         }
  84.        
  85.         [Test]
  86.         public void RemoveShouldRemove()
  87.         {
  88.             var persons = new Person[] { pesho, gosho };
  89.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  90.             db.Remove();
  91.  
  92.             var expectedCount = 1;
  93.  
  94.             Assert.AreEqual(expectedCount, db.Count);
  95.         }
  96.         [Test]
  97.         public void RemoveEmptyCollectionShouldThrow()
  98.         {
  99.             var persons = new Person[] { };
  100.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  101.  
  102.             Assert.That(() => db.Remove(), Throws.InvalidOperationException);
  103.         }
  104.         [Test]
  105.         public void FindByUsernameExistingPersonShouldReturnPerson()
  106.         {
  107.             var persons = new Person[] { pesho, gosho };
  108.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  109.  
  110.             var expected = pesho;
  111.             var actual = db.FindByUsername("Pesho");
  112.  
  113.             Assert.That(actual, Is.EqualTo(expected));
  114.         }
  115.         [Test]
  116.         public void FindByUsernameNonExistingPersonShouldThrow()
  117.         {
  118.             var persons = new Person[] { pesho, gosho };
  119.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  120.  
  121.             Assert.That(() => db.FindByUsername("Stamat"), Throws.InvalidOperationException);
  122.         }
  123.         [Test]
  124.         public void FindByUsernameNullArgumentShouldThrow()
  125.         {
  126.             var persons = new Person[] { pesho, gosho };
  127.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  128.  
  129.             Assert.That(() => db.FindByUsername(null), Throws.ArgumentNullException);
  130.         }
  131.         [Test]
  132.         public void FindByUsernameIsCaseSensitive()
  133.         {
  134.             var persons = new Person[] { pesho, gosho };
  135.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  136.  
  137.             Assert.That(() => db.FindByUsername("GOSHO"), Throws.InvalidOperationException);
  138.         }
  139.         [Test]
  140.         public void FindByIdExistingPersonShouldReturnPerson()
  141.         {
  142.             var persons = new Person[] { pesho, gosho };
  143.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  144.  
  145.             var expected = pesho;
  146.             var actual = db.FindById(11223344);
  147.  
  148.             Assert.That(actual, Is.EqualTo(expected));
  149.         }
  150.         [Test]
  151.         public void FindByIdNonExistingPersonShouldThrow()
  152.         {
  153.             var persons = new Person[] { pesho, gosho };
  154.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  155.  
  156.             Assert.That(() => db.FindById(123456789), Throws.InvalidOperationException);
  157.         }
  158.         [Test]
  159.         public void FindByUsernameNegativeArgumentShouldThrow()
  160.         {
  161.             var persons = new Person[] { pesho, gosho };
  162.             var db = new ExtendedDatabase.ExtendedDatabase(persons);
  163.  
  164.             Assert.That(() => db.FindById(-5), Throws.Exception);
  165.         }
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment