public void Test_Equal_ReturnsTrueIfNamesAndTypesAreTheSame()
        {
            //Arrange, Act
             DateTime sampleDate = new DateTime(1990,09,05);
             Animal firstAnimal = new Animal("Bob", "Male", "German Sheperd", sampleDate, 2);
             Animal secondAnimal = new Animal("Bob", "Male", "German Sheperd", sampleDate, 2);

             //Assert
             Assert.Equal(firstAnimal, secondAnimal);
        }
        public void Test_Find_FindsAnimalInDatabase()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);
              testAnimal.Save();

              //Act
              Animal foundAnimal = Animal.Find(testAnimal.GetId());

              //Assert
              Assert.Equal(testAnimal, foundAnimal);
        }
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);

              //Act
              testAnimal.Save();
              List<Animal> result = Animal.GetAll("id");
              List<Animal> testList = new List<Animal>{testAnimal};

              //Assert
              Assert.Equal(testList, result);
        }
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
              DateTime sampleDate = new DateTime(1990,09,05);
              Animal testAnimal = new Animal("Fluffy", "Female", "Persian", sampleDate, 1);

              //Act
              testAnimal.Save();
              Animal savedAnimal = Animal.GetAll("id")[0];

              int result = savedAnimal.GetId();
              int testId = testAnimal.GetId();

              //Assert
              Assert.Equal(testId, result);
        }
Beispiel #5
0
        public static Animal Find(int id)
        {
            SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM animals WHERE id=@AnimalId;", conn);
              SqlParameter animalIdParameter = new SqlParameter();
              animalIdParameter.ParameterName = "@AnimalId";
              animalIdParameter.Value = id.ToString();
              cmd.Parameters.Add(animalIdParameter);
              rdr = cmd.ExecuteReader();

              int foundAnimalId = 0;
              string foundAnimalName = null;
              string foundAnimalGender = null;
              string foundAnimalBreed = null;
              DateTime foundAdmittanceDate = new DateTime(1900, 09, 05);
              int foundAnimalTypeId = 0;

              while(rdr.Read())
              {
            foundAnimalId = rdr.GetInt32(0);
            foundAnimalName = rdr.GetString(1);
            foundAnimalGender = rdr.GetString(2);
            foundAnimalBreed = rdr.GetString(3);
            foundAdmittanceDate = rdr.GetDateTime(4);
            foundAnimalTypeId = rdr.GetInt32(5);
              }
              Animal foundAnimal = new Animal(foundAnimalName, foundAnimalGender, foundAnimalBreed, foundAdmittanceDate, foundAnimalTypeId, foundAnimalId);
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundAnimal;
        }
Beispiel #6
0
        public static List<Animal> GetAll(string orderingParameter)
        {
            List<Animal> allAnimals = new List<Animal>{};

              SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM animals ORDER BY "+orderingParameter+";", conn);
              rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int animalId = rdr.GetInt32(0);
            string animalName = rdr.GetString(1);
            string animalGender = rdr.GetString(2);
            string animalBreed = rdr.GetString(3);
            DateTime admittanceDate = rdr.GetDateTime(4);
            int animalTypeId = rdr.GetInt32(5);
            Animal newAnimal = new Animal(animalName, animalGender, animalBreed, admittanceDate, animalTypeId, animalId);
            allAnimals.Add(newAnimal);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allAnimals;
        }