Ejemplo n.º 1
0
        public void TestIfFindingByIDWorksCorrectly()
        {
            int id     = 1;
            var person = extendedDatabase.FindById(id);

            Assert.That(person.UserName, Is.EqualTo("Pesho"));
        }
Ejemplo n.º 2
0
        public void FindByIdMethodWorkCorrectly()
        {
            int    idForSearch = 23;
            Person founfPerson = database.FindById(idForSearch);

            Assert.AreEqual(idForSearch, founfPerson.Id);
        }
Ejemplo n.º 3
0
        public void AddPersonAddPersonCorectly()
        {
            person = new Person(id, name);
            emptyExtendedDatabase.Add(person);

            Assert.AreEqual(person, emptyExtendedDatabase.FindById(id));
        }
 public void Test13()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         database.FindById(-1);
     });
     // Assert.That(() => database.FindById(-1), Throws.ArgumentOutOfRangeException.With.Message.EqualTo("Id should be a positive number!")) ;
 }
        public void If_Negative_Id_Is_Found_Should_Throw_Argument_Out_Of_Range_Exception(long findNegativeId)
        {
            //Arrange
            extendedDatabase.Add(person);

            //Act - Assert
            Assert.Throws <ArgumentOutOfRangeException>(() => extendedDatabase.FindById(findNegativeId));
        }
Ejemplo n.º 6
0
        public void TestIfFindByIdMethodWorksCorrectly()
        {
            Person expectedPerson = persons[0];

            Person actualPerson = database.FindById(0);

            Assert.AreEqual(expectedPerson, actualPerson);
        }
Ejemplo n.º 7
0
        public void FindByIdOperatonShouldReturnCorrectPerson()
        {
            // Act
            Person expectedPerson = firstPerson;
            Person actualPerson   = database.FindById(123);

            // Assert
            Assert.AreEqual(expectedPerson, actualPerson);
        }
Ejemplo n.º 8
0
        public void FindByIDUnableToFindID_Should_ThrowException()
        {
            database.Add(n1claren);

            Assert.Throws <InvalidOperationException>(() =>
            {
                Person somebody = database.FindById(1020304050);
            });
        }
        public void FindById()
        {
            Person person = new Person(1, "Gosho");

            db.Add(person);
            Person samePersonExpected = db.FindById(1);

            Assert.That(samePersonExpected.Id, Is.EqualTo(person.Id), "Person doesn't match real person.");
        }
Ejemplo n.º 10
0
        public void DatabaseShouldThrowExcpFindBy()
        {
            Assert.Throws <ArgumentNullException>(() => extendedDatabase.FindByUsername(""));

            Assert.Throws <InvalidOperationException>(() => extendedDatabase.FindByUsername("Bont"));

            Assert.Throws <ArgumentOutOfRangeException>(() => extendedDatabase.FindById(-1));

            Assert.Throws <InvalidOperationException>(() => extendedDatabase.FindById(100));
        }
Ejemplo n.º 11
0
        public void FindByIdShouldReturnCorrectPerson()
        {
            Person pesho = new Person(2, "Pesho");

            database.Add(pesho);

            Person personToFind = database.FindById(2);

            Assert.AreEqual(pesho, personToFind);
        }
Ejemplo n.º 12
0
        public void FindById_ThrowExeption()
        {
            var n = 3;

            for (int i = 0; i < n; i++)
            {
                extendedDatabase.Add(new Person(i, $"Name{i}"));
            }
            extendedDatabase.Remove();
            Assert.Throws <InvalidOperationException>(() => extendedDatabase.FindById(n - 1));
        }
        public void When_UseRemoveMethod_Should_CountreDecrease()
        {
            int n = 5;

            for (int i = 0; i < n; i++)
            {
                database.Add(new Person(i, $"Angel{i}"));
            }
            database.Remove();
            Assert.That(database.Count, Is.EqualTo(n - 1));
            Assert.Throws <InvalidOperationException>(() => database.FindById(n - 1));
        }
Ejemplo n.º 14
0
        public void Remove_RemoveElementFromDb()
        {
            var n = 3;

            for (int i = 0; i < n; i++)
            {
                extendedDb.Add(new Person(i, $"Fresh{i}"));
            }
            extendedDb.Remove();
            Assert.That(extendedDb.Count, Is.EqualTo(n - 1));
            Assert.Throws <InvalidOperationException>(() => extendedDb.FindById(n - 1));
        }
        public void Remove_RemovesElementFromDB()
        {
            int n = 5;

            for (int i = 0; i < n; i++)
            {
                database.Add(new Person(i, $"Username{i}"));
            }

            database.Remove();
            Assert.That(database.Count, Is.EqualTo(n - 1));
            Assert.Throws <InvalidOperationException>(() => database.FindById(n - 1));
        }
Ejemplo n.º 16
0
        public void When_RemoveIsValid_RemovesElementFromDatabase()
        {
            int n = 5;

            for (int i = 0; i < n; i++)
            {
                database.Add(new Person(i, $"username{i}"));
            }

            database.Remove();

            int expectedCount = n - 1;

            Assert.AreEqual(expectedCount, database.Count);
            Assert.Throws <InvalidOperationException>(() => database.FindById(n - 1));
        }
Ejemplo n.º 17
0
    public void RemoveOperationShouldRemoveLastElement()
    {
        const long   lastPersonId       = 13579;
        const string lastPersonUsername = "******";
        const int    expectedCount      = 2;
        //Arrange
        List <Person> persons = new List <Person>()
        {
            new Person(12345, "Ivan"),
            new Person(67890, "Asen"),
            new Person(13579, "Gosho")
        };

        ExtendedDatabase.ExtendedDatabase database = new ExtendedDatabase.ExtendedDatabase(persons.ToArray());

        //Act
        database.Remove();

        //Assert
        int actualCount = database.Count;

        Assert.AreEqual(expectedCount, actualCount);
        Assert.Throws <InvalidOperationException>(() => database.FindById(lastPersonId));
        Assert.Throws <InvalidOperationException>(() => database.FindByUsername(lastPersonUsername));
    }
Ejemplo n.º 18
0
        public void FindByIdNonExistingPersonShouldThrow()
        {
            var persons = new Person[] { pesho, gosho };
            var db      = new ExtendedDatabase.ExtendedDatabase(persons);

            Assert.That(() => db.FindById(123456789), Throws.InvalidOperationException);
        }
Ejemplo n.º 19
0
        public void FindByUsernameNegativeArgumentShouldThrow()
        {
            var persons = new Person[] { pesho, gosho };
            var db      = new ExtendedDatabase.ExtendedDatabase(persons);

            Assert.That(() => db.FindById(-5), Throws.Exception);
        }
Ejemplo n.º 20
0
        public void TestFindByNoId()
        {
            Assert.That(() => database.FindById(-15),
                        Throws.Exception.With.Message.Contains("Id should be a positive number!"));

            Assert.Throws <InvalidOperationException>(() => this.database.FindById(102));
        }
Ejemplo n.º 21
0
        public void FindByIdDoesntContainsId()
        {
            CreatePeople(5);

            ExtendedDatabase.ExtendedDatabase extendedDatabase = new ExtendedDatabase.ExtendedDatabase(people);

            Assert.Throws <InvalidOperationException>(() => extendedDatabase.FindById(100));
        }
Ejemplo n.º 22
0
        public void FindByIdTakesNegativeId()
        {
            CreatePeople(5);

            ExtendedDatabase.ExtendedDatabase extendedDatabase = new ExtendedDatabase.ExtendedDatabase(people);

            Assert.Throws <ArgumentOutOfRangeException>(() => extendedDatabase.FindById(-1));
        }
        public void Remove_RemovesElementsFromDatabase()
        {
            this.extendedDatabase.Add(new Person(1, "Momchil"));
            this.extendedDatabase.Add(new Person(2, "Emo"));

            this.extendedDatabase.Remove();

            Assert.Throws <InvalidOperationException>(() => extendedDatabase.FindById(2));
        }
Ejemplo n.º 24
0
        public void When_ProvidedDataIsValid_CtorShouldSetItCorrectly()
        {
            Person firstPerson  = new Person(1, "Angel");
            Person secondPerson = new Person(2, "Ivan");

            Person[] people = new Person[]
            {
                firstPerson,
                secondPerson
            };

            database = new ExtendedDatabase.ExtendedDatabase(people);

            Person dbFirstPerson  = database.FindById(firstPerson.Id);
            Person dbSecondPerson = database.FindById(secondPerson.Id);

            Assert.AreEqual(firstPerson, dbFirstPerson);
            Assert.AreEqual(secondPerson, dbSecondPerson);
        }
Ejemplo n.º 25
0
        public void FindById_ReturnsExpectedPersonById()
        {
            Person person = new Person(15, "Kristian");

            database.Add(person);

            Person dbPerson = database.FindById(person.Id);

            Assert.That(person, Is.EqualTo(dbPerson));
        }
Ejemplo n.º 26
0
        public void FindByIdExistingPersonShouldReturnPerson()
        {
            var persons = new Person[] { pesho, gosho };
            var db      = new ExtendedDatabase.ExtendedDatabase(persons);

            var expected = pesho;
            var actual   = db.FindById(11223344);

            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 27
0
        public void FindByIdWorksProperly()
        {
            CreatePeople(5);

            ExtendedDatabase.ExtendedDatabase extendedDatabase = new ExtendedDatabase.ExtendedDatabase(people);
            Person expectedPerson = new Person(0, "0");
            Person actualPerson   = extendedDatabase.FindById(0);

            Assert.AreEqual(expectedPerson.Id, actualPerson.Id);
            Assert.AreEqual(expectedPerson.UserName, actualPerson.UserName);
        }
Ejemplo n.º 28
0
        public void CheckFindByIdWorksCorrect()
        {
            var persons = new Person[] { new Person(1, "A"), new Person(2, "B") };

            extendedDatabase = new ExtendedDatabase(persons);
            var person   = new Person(1, "A");
            var personId = person.Id;

            var searchedPerson = extendedDatabase.FindById(personId);

            Assert.AreEqual(person.Id, searchedPerson.Id);
        }
Ejemplo n.º 29
0
        public void CheckFindByIDThrowExceptionIfIdIsNegativeNumber()
        {
            var persons = new Person[] { new Person(1, "A"), new Person(2, "B") };

            extendedDatabase = new ExtendedDatabase(persons);
            var searchedId = -1;

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                extendedDatabase.FindById(searchedId);
            });
        }
        public void FindById_ShouldThrowException_WhenNegativeIdIsProvided()
        {
            //Arrange
            var database = new ExtendedDatabase.ExtendedDatabase();
            var userOne  = new Person(1, "UserOne");

            //Act
            database.Add(userOne);

            //Assert
            Assert.Throws <ArgumentOutOfRangeException>(() => database.FindById(-1));
        }