Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using ExtendedDatabase;
- using NUnit.Framework;
- namespace Tests
- {
- public class ExtendedDatabaseTests
- {
- private ExtendedDatabase.ExtendedDatabase database;
- //private ExtendedDatabase database;
- private readonly Person person1 = new Person(1, "Pesho");
- private readonly Person person2 = new Person(2, "Gosho");
- [SetUp]
- public void Setup()
- {
- this.database = new ExtendedDatabase.ExtendedDatabase(person1, person2);
- //this.database = new ExtendedDatabase(person1, person2);
- }
- [Test]
- public void TestIfConstructorWorksCorrectliPerson()
- {
- long expId = 3;
- string expName = "Mihso";
- Person person = new Person(expId, expName);
- long acId = person.Id;
- string acName = person.UserName;
- Assert.AreEqual(expId, acId);
- Assert.AreEqual(expName, acName);
- }
- [Test]
- public void TestIfDataBaseWorkCorrectli()
- {
- Person[] persons = new Person[] { person1, person2 };
- this.database = new ExtendedDatabase.ExtendedDatabase(persons);
- //this.database = new ExtendedDatabase(persons);
- int expectedCount = persons.Length;
- int actualCount = this.database.Count;
- Assert.AreEqual(expectedCount, actualCount);
- }
- [Test]
- public void ConstructorShouldThrowExceptionWnehInitialaizingMore()
- {
- Person person1 = new Person(1, "Pesho1");
- Person person2 = new Person(2, "Pesho2");
- Person person3 = new Person(3, "Pesho3");
- Person person4 = new Person(4, "Pesho4");
- Person person5 = new Person(5, "Pesho5");
- Person person6 = new Person(6, "Pesho6");
- Person person7 = new Person(7, "Pesho7");
- Person person8 = new Person(8, "Pesho8");
- Person person9 = new Person(9, "Pesho9");
- Person person10 = new Person(10, "Pesho10");
- Person person11 = new Person(11, "Pesho11");
- Person person12 = new Person(12, "Pesho12");
- Person person13 = new Person(13, "Pesho13");
- Person person14 = new Person(14, "Pesho14");
- Person person15 = new Person(15, "Pesho15");
- Person person16 = new Person(16, "Pesho16");
- Person person17 = new Person(17, "Pesho17");
- Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
- person7, person8, person9, person10, person11, person12, person13, person14, person15,
- person16, person17 };
- Assert.Throws<ArgumentException>(() =>
- {
- this.database = new ExtendedDatabase.ExtendedDatabase(persons);
- //this.database = new ExtendedDatabase(persons);
- });
- }
- [Test]
- public void AddShoudIncraseCountWhenAddSuccessfully()
- {
- Person person3 = new Person(3, "Pesho3");
- this.database.Add(person3);
- int expectedCount = 3;
- int actualCount = this.database.Count;
- Assert.AreEqual(expectedCount, actualCount);
- }
- [Test]
- public void AddShuldThrowExceptionFullCount()
- {
- Person person1 = new Person(1, "Pesho1");
- Person person2 = new Person(2, "Pesho2");
- Person person3 = new Person(3, "Pesho3");
- Person person4 = new Person(4, "Pesho4");
- Person person5 = new Person(5, "Pesho5");
- Person person6 = new Person(6, "Pesho6");
- Person person7 = new Person(7, "Pesho7");
- Person person8 = new Person(8, "Pesho8");
- Person person9 = new Person(9, "Pesho9");
- Person person10 = new Person(10, "Pesho10");
- Person person11 = new Person(11, "Pesho11");
- Person person12 = new Person(12, "Pesho12");
- Person person13 = new Person(13, "Pesho13");
- Person person14 = new Person(14, "Pesho14");
- Person person15 = new Person(15, "Pesho15");
- Person person16 = new Person(16, "Pesho16");
- Person person17 = new Person(17, "Pesho17");
- Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
- person7, person8, person9, person10, person11, person12, person13, person14, person15,
- person16 };
- this.database = new ExtendedDatabase.ExtendedDatabase(persons);
- //this.database = new ExtendedDatabase(persons);
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.Add(person17);
- });
- }
- [Test]
- public void RemoveShoudDecreaseWhenSuccess()
- {
- int expectedCount = 1;
- this.database.Remove();
- int actualCount = this.database.Count;
- Assert.AreEqual(expectedCount, actualCount);
- }
- [Test]
- public void RemoveShouldThrowExceptionIsDataEmpty()
- {
- this.database.Remove();
- this.database.Remove();
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.Remove();
- });
- }
- [Test]
- public void TestIfPersonIdExsistThrowExspetion()
- {
- Person person = new Person(1, "Stefan");
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.Add(person);
- });
- }
- [Test]
- public void TestIfPersonNameExsistThrowExspetion()
- {
- Person person = new Person(4, "Pesho");
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.Add(person);
- });
- }
- [Test]
- public void TestFindByUserNameIfUserNoExsistThrowExseption()
- {
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.FindByUsername("Stefan");
- });
- }
- [Test]
- [TestCase(null)]
- public void TestFindByUserNameIfUserIsNullThrowExseption(string name)
- {
- Assert.Throws<ArgumentNullException>(() =>
- {
- this.database.FindByUsername(name);
- });
- }
- [Test]
- public void TestFindByUserNameIfUserIsEmptyThrowExseption()
- {
- string name = String.Empty;
- Assert.Throws<ArgumentNullException>(() =>
- {
- this.database.FindByUsername(name);
- });
- }
- [Test]
- public void TestFindByIdIfIdNoExsistThrowExseption()
- {
- long id = 5;
- Assert.Throws<InvalidOperationException>(() =>
- {
- this.database.FindById(id);
- });
- }
- [Test]
- public void TestFindByIdIfIdLessZeroThrowExseption()
- {
- long id = -2;
- Assert.Throws<ArgumentOutOfRangeException>(() =>
- {
- this.database.FindById(id);
- });
- }
- [Test]
- public void TestAddRangeIfArrayManyThrowException()
- {
- Person person1 = new Person(1, "Pesho1");
- Person person2 = new Person(2, "Pesho2");
- Person person3 = new Person(3, "Pesho3");
- Person person4 = new Person(4, "Pesho4");
- Person person5 = new Person(5, "Pesho5");
- Person person6 = new Person(6, "Pesho6");
- Person person7 = new Person(7, "Pesho7");
- Person person8 = new Person(8, "Pesho8");
- Person person9 = new Person(9, "Pesho9");
- Person person10 = new Person(10, "Pesho10");
- Person person11 = new Person(11, "Pesho11");
- Person person12 = new Person(12, "Pesho12");
- Person person13 = new Person(13, "Pesho13");
- Person person14 = new Person(14, "Pesho14");
- Person person15 = new Person(15, "Pesho15");
- Person person16 = new Person(16, "Pesho16");
- Person person17 = new Person(17, "Pesho17");
- Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
- person7, person8, person9, person10, person11, person12, person13, person14, person15,
- person16, person17 };
- Assert.Throws<ArgumentException>(() =>
- {
- this.database = new ExtendedDatabase.ExtendedDatabase(persons);
- //this.database = new ExtendedDatabase(persons);
- });
- }
- [Test]
- public void TestAddRangeAndCheckedTheCount()
- {
- Person person1 = new Person(1, "Pesho1");
- Person person2 = new Person(2, "Pesho2");
- Person person3 = new Person(3, "Pesho3");
- Person person4 = new Person(4, "Pesho4");
- Person person5 = new Person(5, "Pesho5");
- Person person6 = new Person(6, "Pesho6");
- Person person7 = new Person(7, "Pesho7");
- Person person8 = new Person(8, "Pesho8");
- Person person9 = new Person(9, "Pesho9");
- Person person10 = new Person(10, "Pesho10");
- Person person11 = new Person(11, "Pesho11");
- Person person12 = new Person(12, "Pesho12");
- Person person13 = new Person(13, "Pesho13");
- Person person14 = new Person(14, "Pesho14");
- Person[] persons = new Person[] {person1, person2, person3, person4, person5, person6,
- person7, person8, person9, person10, person11, person12, person13, person14 };
- this.database = new ExtendedDatabase.ExtendedDatabase(persons);
- //this.database = new ExtendedDatabase(persons);
- int expCount = 14;
- int actulCount = this.database.Count;
- Assert.AreEqual(expCount, actulCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement