예제 #1
0
        public void DatabaseFindByUsernameOrIdThrowsIOPWhenNotFound()
        {
            var db = new App.Database(this.PersonObjects);

            Assert.That(() => db.FindByUsername("Penka"), Throws.InvalidOperationException, "The database does not throw exceptions when the username is not found.");

            Assert.That(() => db.FindById(500), Throws.InvalidOperationException, "The database does not throw exceptions when the Id is not found");
        }
예제 #2
0
        public void DatabaseFindByIdThrowsArgExWhenBelowZero()
        {
            var db = new App.Database();

            try
            {
                db.FindById(-51);
            }
            catch (Exception e)
            {
                Assert.That(e is ArgumentOutOfRangeException, "The thrown exception is incorrect");

                if (e is ArgumentOutOfRangeException)
                {
                    Assert.That(e is ArgumentOutOfRangeException, "The Database.FindById accepts negative ids");
                }
            }
        }
예제 #3
0
        public void DatabaseFindByUsernameAndIdWorks()
        {
            var peopleObjects = this.PersonObjects;

            var firstPerson = peopleObjects[0];

            var db = new App.Database(peopleObjects);

            IPerson personByUsername;

            try
            {
                personByUsername = db.FindByUsername(firstPerson.Name);
                Assert.That(personByUsername, Is.EqualTo(firstPerson));
            }
            catch (Exception) { throw new AssertionException("The Database.FindByUsername() does not work properly"); }

            try
            {
                personByUsername = db.FindById(firstPerson.Id);
                Assert.That(personByUsername, Is.EqualTo(firstPerson));
            }
            catch (Exception) { throw new AssertionException("The Database.FindById() does not work properly"); }
        }