Exemplo n.º 1
0
        public void AnimalPropsTest()
        {
            //if chip is longer than 5 digits, just add the first 5;
            cat = new Cat("123456", simpleDate, "testAnimal", "badHabits");
            Assert.AreEqual("12345", cat.ChipRegistrationNumber, "Chip failed when more than 5 digits are inserted");

            //if chip is shorter than 5, add zeros before the chip until the chip has 5 digits
            cat = new Cat("1234", simpleDate, "testAnimal", "badHabits");
            Assert.AreEqual("01234", cat.ChipRegistrationNumber, "Chip failed when less than 5 digits were inserted");

            //Check rest of properties;
            Assert.AreEqual(simpleDate, cat.DateOfBirth, "Incorrect DateOfBirth");
            Assert.AreEqual("testAnimal", cat.Name, "Incorrect Name");
            Assert.AreEqual("01234, 06-11-1996, testAnimal, not reserved, badhabits: badHabits", cat.ToString());

            //test null birthdate for cat
            cat = new Cat("1234", null, "testAnimal", "badHabits");
            Assert.AreEqual("01234, 00-00-0000, testAnimal, not reserved, badhabits: badHabits", cat.ToString());
            //test "" badhabits
            cat = new Cat("1234", null, "testAnimal", "");
            Assert.AreEqual("01234, 00-00-0000, testAnimal, not reserved, badhabits: none", cat.ToString());

            //special dog test
            Assert.AreEqual("12345, 06-11-1996, testdog, not reserved, lastWalkDate: 06-11-1996", dog.ToString());
            dog = new Dog("12345", null, null, null);
            dog.IsReserved = true;
            Assert.AreEqual("12345, 00-00-0000, noname, reserved, lastWalkDate: 00-00-0000", dog.ToString());
        }
Exemplo n.º 2
0
        public void TestConstructor()
        {
            Cat cat = new Cat("123456", new SimpleDate(01, 05, 1997), "Gerrit", "");
            Assert.AreEqual(cat.ChipRegistrationNumber, "12345");
            Assert.AreEqual(cat.DateOfBirth.Day, 01);
            Assert.AreEqual(cat.DateOfBirth.Month, 05);
            Assert.AreEqual(cat.DateOfBirth.Year, 1997);
            Assert.AreEqual(cat.BadHabits, "");
            Assert.AreEqual(cat.IsReserved, false);
            Assert.AreEqual(cat.Name, "Gerrit");
            Assert.AreEqual(cat.Price, 60);

            cat = new Cat("123", new SimpleDate(12, 03, 2015), "Henk", "Pees everywhere");
            Assert.AreEqual(cat.ChipRegistrationNumber, "00123");
            Assert.AreEqual(cat.DateOfBirth.Day, 12);
            Assert.AreEqual(cat.DateOfBirth.Month, 03);
            Assert.AreEqual(cat.DateOfBirth.Year, 2015);
            Assert.AreEqual(cat.BadHabits, "Pees everywhere");
            Assert.AreEqual(cat.IsReserved, false);
            Assert.AreEqual(cat.Name, "Henk");
            Assert.AreEqual(cat.Price, 45);

            cat = new Cat("12345", new SimpleDate(12, 03, 2015), "Henk", "Pees everywhere. Bad cat and does not listen really well. Also bites everyone he sees");
            Assert.AreEqual(cat.BadHabits, "Pees everywhere. Bad cat and does not listen really well. Also bites everyone he sees");
            Assert.AreEqual(cat.Price, 20);

            cat.IsReserved = true;
            Assert.AreEqual(cat.IsReserved, true);
        }
Exemplo n.º 3
0
        public void TestToString()
        {
            Cat cat = new Cat("123", new SimpleDate(12, 03, 2015), "Henk", "Pees everywhere");
            string catstring = cat.ToString();
            Assert.AreEqual(catstring, "00123, 12-03-2015, Henk, not reserved, 45, Pees everywhere");

            cat = new Cat("12345", null, "", "");
            cat.IsReserved = true;
            catstring = cat.ToString();
            Assert.AreEqual(catstring, "12345, 00-00-0000, noname, reserved, 60, ");
        }
Exemplo n.º 4
0
        public void AnimalComparing()
        {
            cat = new Cat("99999", simpleDate, "testAnimal", "badHabits");
            Cat cat2 = new Cat("00000", simpleDate, "testAnimal", "badHabits");
            administration.Add(cat);
            administration.Add(cat2);

            administration.Animallist.Sort();

            Assert.AreEqual(cat2, administration.Animallist[0]);
        }
Exemplo n.º 5
0
 public void TestChipNumberFromCatTooShort()
 {
     Cat cat3 = new Cat("9876", new SimpleDate(8, 1, 2005), "Reserved", "Sven", "");
     Assert.AreEqual("09876", cat3.ChipRegistrationNumber);
 }
Exemplo n.º 6
0
 public void TestCatPrice20()
 {
     Cat cat2 = new Cat("98765", new SimpleDate(8, 1, 2005), "Sven", "Reserved", "Sloopt gordijnen en gooit plantenbakken van de vensterbank af");
     cat2.SetPrice();
     Assert.AreEqual(20, cat2.Price);
 }
Exemplo n.º 7
0
 public void Initialize()
 {
     cat = new Cat("98765", new SimpleDate(8, 1, 2005), "Sven", "not reserved", "");
     dog = new Dog("65432", new SimpleDate(6, 7, 2006), "Tristan", "not reserved", new SimpleDate(6, 10, 2015));
     dog.SetPrice();
 }
Exemplo n.º 8
0
        public void ReadAnimals(bool local)
        {
            if (local)
            {
                try
                {
                    using (FileStream FS = new FileStream("objects.bin", FileMode.Open, FileAccess.Read))
                    {
                        BinaryFormatter BF = new BinaryFormatter();
                        animals = (List<Animal>)BF.Deserialize(FS);
                    }
                }
                catch (FileNotFoundException FNFE)
                {
                    Console.WriteLine(FNFE.Message);
                }
            }
            else
            {
                using (OracleConnection connection = Database.Connection)
                {
                    string sqlquery = "SELECT CHIPREGISTRATIONNUMBER, DATEOFBIRTH, NAME, RESERVED, PRICE, LASTWALKDATE, BADHABITS FROM ANIMALS";
                    OracleCommand OC = new OracleCommand(sqlquery, connection);
                    OracleDataReader ODR = OC.ExecuteReader();

                    string ChipRegistrationNumber = "";
                    string Name = "";
                    string BadHabits = "";
                    SimpleDate DateOfBirth = null;
                    SimpleDate LastWalkDate = null;
                    bool Reserved = false;
                    decimal Price = 0;

                    //List<Animal> animal = new List<Animal>();

                    while (ODR.Read())
                    {
                        ChipRegistrationNumber = ODR["CHIPREGISTRATIONNUMBER"].ToString();
                        Name = ODR["NAME"].ToString();
                        BadHabits = ODR["BADHABITS"].ToString();

                        DateTime DT = DateTime.Parse(ODR["DATEOFBIRTH"].ToString());
                        DateOfBirth = new SimpleDate(DT.Day, DT.Month, DT.Year);
                        if (ODR["LASTWALKDATE"].ToString() != "")
                        {
                            DT = DateTime.Parse(ODR["LASTWALKDATE"].ToString());
                        }
                        LastWalkDate = new SimpleDate(DT.Day, DT.Month, DT.Year);

                        Reserved = Convert.ToBoolean(ODR["RESERVED"]);
                        Price = Convert.ToDecimal(ODR["PRICE"]);

                        if (BadHabits != "")
                        {
                            Cat cat = new Cat(ChipRegistrationNumber, DateOfBirth, Name, BadHabits);
                            cat.IsReserved = Reserved;
                            animals.Add(cat);

                        }
                        else
                        {
                            Dog dog = new Dog(ChipRegistrationNumber, DateOfBirth, Name, LastWalkDate);
                            dog.IsReserved = Reserved;
                            animals.Add(dog);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Insert a new animal into the database
        /// </summary>
        /// <param name="animal"></param>
        /// <returns></returns>
        public bool InsertAnimal(Animal animal)
        {
            using (SQLiteConnection connection = Database.Connection)
            {
                string query = "INSERT INTO Animal (Chipnumber, Type, DateOfBirth, Name, IsReserved, LastWalkDate, BadHabits)" +
                    " VALUES (:Chipnumber, :Type, :DateOfBirth, :Name, :IsReserved, :LastWalkDate, :BadHabits)";
                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    if(animal is Dog)
                    {
                        var dog = animal as Dog;

                        command.Parameters.AddWithValue("Chipnumber", animal.ChipRegistrationNumber);
                        command.Parameters.AddWithValue("Type", "Dog");
                        command.Parameters.AddWithValue("DateOfBirth", animal.DateOfBirth);
                        command.Parameters.AddWithValue("Name", animal.Name);
                        command.Parameters.AddWithValue("IsReserved", animal.IsReserved);
                        command.Parameters.AddWithValue("LastWalkDate", dog.LastWalkDate);
                        command.Parameters.AddWithValue("BadHabits", null);
                    }
                    else
                    {
                        var cat = animal as Cat;

                        command.Parameters.AddWithValue("Chipnumber", animal.ChipRegistrationNumber);
                        command.Parameters.AddWithValue("Type", "Cat");
                        command.Parameters.AddWithValue("DateOfBirth", animal.DateOfBirth);
                        command.Parameters.AddWithValue("Name", animal.Name);
                        command.Parameters.AddWithValue("IsReserved", animal.IsReserved);
                        command.Parameters.AddWithValue("BadHabits", cat.BadHabits);
                        command.Parameters.AddWithValue("LastWalkDate", null);
                    }

                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SQLiteException e)
                    {
                        // If a PK constraint was violated, handle the exception
                        if (e.ResultCode == SQLiteErrorCode.Constraint)
                        {
                            return false;
                        }

                        // Unexpected error: rethrow to let the caller handle it
                        throw;
                    }
                }

                // Retrieve the id of the inserted row to create a new student object
                query = "SELECT last_insert_rowid()";
                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    if(animal is Dog)
                    {
                        var dog = animal as Dog;

                        dog = new Dog(dog.ChipRegistrationNumber, dog.DateOfBirth, dog.Name, dog.IsReserved, dog.LastWalkDate);
                    }
                    else
                    {
                        var cat = animal as Cat;

                        cat = new Cat(cat.ChipRegistrationNumber, cat.DateOfBirth, cat.Name, cat.IsReserved, cat.BadHabits);
                    }
                }
            }

            return true;
        }
 private void btnCreateCat_Click(object sender, EventArgs e)
 {
     Cat theCat = new Cat(textBoxChipRegNumb.Text, dateTimePickerBroughtIn.Value, textBoxName.Text, textBoxBadHabits.Text);
 }
Exemplo n.º 11
0
 public void Initialize()
 {
     simpleDate = new SimpleDate(06, 11, 1996);
     lastWalk = new SimpleDate(06, 11, 1996);
     administration = new Administration();
     dog = new Dog("12345", simpleDate, "testdog", lastWalk);
     cat = new Cat("12345", simpleDate, "testcat", "0123456789");
 }
Exemplo n.º 12
0
        public void TestAddCat()
        {
            //60-badhabits.length = price of cat
            Assert.AreEqual((60 - 10), cat.Price, "Incorrect Price");

            //badhabits <= 20 : price = 20
            cat = new Cat("12345", simpleDate, "testcat", "12345678901234567890123456789012345678901");
            Assert.AreEqual(20, cat.Price);
        }