public void AnimalConstructorTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     AnimalTypes.animalTypes type = new AnimalTypes.animalTypes(); // TODO: Initialize to an appropriate value
     Animal target = new Animal(name, type);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
 public void getNameTest()
 {
     IAnimal target = new Animal("Bob", AnimalTypes.animalTypes.Cat);
     string expected = "Bob";
     string actual;
     actual = target.getName();
     Assert.AreEqual(expected, actual);
 }
 public void getImageTest()
 {
     IAnimal target = new Animal("Bob", AnimalTypes.animalTypes.Cat);
     Bitmap expected = target.getImage();
     Bitmap actual;
     actual = target.getImage();
     Assert.AreEqual(expected, actual);
 }
 public void AnimalToStringTest()
 {
     IAnimal target = new Animal("Barry", AnimalTypes.animalTypes.Cat);
     string expected = "Barry: Cat";
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual);
 }
 public bool Add(Animal animal)
 {
     if(animals.Exists(a => a.ChipRegistrationNumber == animal.ChipRegistrationNumber))
     {
         return false;
     }
     animals.Add(animal);
     return true;
 }
 public void getImageTest1()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     AnimalTypes.animalTypes type = new AnimalTypes.animalTypes(); // TODO: Initialize to an appropriate value
     Animal target = new Animal(name, type); // TODO: Initialize to an appropriate value
     Bitmap expected = null; // TODO: Initialize to an appropriate value
     Bitmap actual;
     actual = target.getImage();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public bool Add(Animal animal)
 {
     if (animal != null)
     {
         if (FindAnimal(animal.ChipRegistrationNumber) == null)
         {
             animalList.Add(animal);
             return true;
         }
     }
     return false;
 }
        /// <summary>
        /// Find an animal by the given Chipnumber
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Animal GetAnimal(Animal animal)
        {
            using (SQLiteConnection connection = Database.Connection)
            {
                string query = "SELECT * FROM Animal WHERE Chipnumber=:id";
                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    command.Parameters.AddWithValue("Chipnumber", animal.ChipRegistrationNumber);
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            return CreateAnimalFromReader(reader);
                        }
                    }
                }
            }

            return null;
        }
 public void getTypeTest()
 {
     IAnimal target = new Animal("Bob", AnimalTypes.animalTypes.Cat);
     AnimalTypes.animalTypes expected = AnimalTypes.animalTypes.Cat; // TODO: Initialize to an appropriate value
     AnimalTypes.animalTypes actual;
     actual = target.getType();
     Assert.AreEqual(expected, actual);
 }
Beispiel #10
0
 /// <summary>
 /// Insert an animal into the database
 /// </summary>
 /// <param name="animal"></param>
 /// <returns></returns>
 public bool InsertAnimal(Animal animal)
 {
     return context.InsertAnimal(animal);
 }
Beispiel #11
0
 /// <summary>
 /// Get an animal by id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Animal GetAnimal(Animal animal)
 {
     return context.GetAnimal(animal);
 }
        /// <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;
        }
Beispiel #13
0
        //Methods
        public bool Add(Animal animal)
        {
            dieren.Add(animal);

            return true;
        }
 public void ToStringTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     AnimalTypes.animalTypes type = new AnimalTypes.animalTypes(); // TODO: Initialize to an appropriate value
     Animal target = new Animal(name, type); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void setImageTest()
 {
     string name = string.Empty; // TODO: Initialize to an appropriate value
     AnimalTypes.animalTypes type = new AnimalTypes.animalTypes(); // TODO: Initialize to an appropriate value
     Animal target = new Animal(name, type); // TODO: Initialize to an appropriate value
     string animalImageName = string.Empty; // TODO: Initialize to an appropriate value
     target.setImage(animalImageName);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }