Ejemplo 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());
        }
Ejemplo n.º 2
0
        public void TestToString()
        {
            Dog dog = new Dog("51000", new SimpleDate(01, 05, 1997), "Peter", new SimpleDate(02, 06, 2011));
            string dogstring = dog.ToString();
            Assert.AreEqual("51000, 01-05-1997, Peter, not reserved, 350, 02-06-2011", dogstring);

            dog.IsReserved = true;
            dogstring = dog.ToString();
            Assert.AreEqual("51000, 01-05-1997, Peter, reserved, 350, 02-06-2011", dogstring);

            dog = new Dog("51000", new SimpleDate(01, 05, 1997), "", new SimpleDate(02, 06, 2011));
            dogstring = dog.ToString();
            Assert.AreEqual("51000, 01-05-1997, noname, not reserved, 350, 02-06-2011", dogstring);

            dog = new Dog("51000", new SimpleDate(01, 05, 1997), null, new SimpleDate(02, 06, 2011));
            dogstring = dog.ToString();
            Assert.AreEqual("51000, 01-05-1997, noname, not reserved, 350, 02-06-2011", dogstring);
        }
Ejemplo n.º 3
0
        public void TestConstructor()
        {
            Dog dog = new Dog("123456", new SimpleDate(01, 05, 1997), "Peter", new SimpleDate(02, 06, 2011));
            Assert.AreEqual(dog.ChipRegistrationNumber, "12345");
            Assert.AreEqual(dog.DateOfBirth.Day, 01);
            Assert.AreEqual(dog.DateOfBirth.Month, 05);
            Assert.AreEqual(dog.DateOfBirth.Year, 1997);
            Assert.AreEqual(dog.LastWalkDate.Day, 02);
            Assert.AreEqual(dog.LastWalkDate.Month, 06);
            Assert.AreEqual(dog.LastWalkDate.Year, 2011);
            Assert.AreEqual(dog.IsReserved, false);
            Assert.AreEqual(dog.Name, "Peter");
            Assert.AreEqual(dog.Price, 200);

            dog.IsReserved = true;
            Assert.AreEqual(true, dog.IsReserved);

            dog = new Dog("51000", new SimpleDate(01, 05, 1997), "Peter", new SimpleDate(02, 06, 2011));
            Assert.AreEqual(350, dog.Price);
        }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
0
 public void TestDogPrice200()
 {
     Dog dog2 = new Dog("21452", new SimpleDate(6, 7, 2005), "Tristan", "Reserved", new SimpleDate(6, 10, 2014));
     dog2.SetPrice();
     Assert.AreEqual(200, dog2.Price);
 }
Ejemplo n.º 6
0
 public void TestDogNoValuesToString()
 {
     Dog dog3 = new Dog("12334", null, null, "Reserved", new SimpleDate(6, 10, 2015));
     string s = "12334"
         + ", " + "00-00-0000"
         + ", " + "noname"
         + ", " + "Reserved"
         + ", " + "€ " + "0,00"
         + ", " + "06-10-2015";
     Assert.AreEqual(s, dog3.ToString());
 }
Ejemplo n.º 7
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
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 btnCreateDog_Click(object sender, EventArgs e)
 {
     Dog theDog = new Dog(textBoxChipRegNumb.Text, dateTimePickerBroughtIn.Value, textBoxName.Text, dateTimePickerLastWalked.Value);
 }
Ejemplo n.º 10
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");
 }
Ejemplo n.º 11
0
        public void TestAddDog()
        {
            Assert.AreEqual(lastWalk, dog.LastWalkDate, "Incorrect Last Walk Date");

            //Chipnumber of dog < 50000
            Assert.AreEqual(200, dog.Price, "Incorrect Price with chipnumber < 50000");

            //Chipnumber of dog >= 50000
            dog = new Dog("52345", simpleDate, "testdog", lastWalk);
            Assert.AreEqual(350, dog.Price, "Incorrect Price with chipnumber >= 50000");
        }