public void Dispose()
 {
     Authors.DeleteAll();
     Copies.DeleteAll();
     Patrons.DeleteAll();
     Books.DeleteAll();
 }
        public void Copies_AddBook_AddCopiesToPatrons()
        {
            Copies newCopies = new Copies(1, DateTime.Now, 1);

            newCopies.Save();
            Books newBook = new Books("Of mice and men", 1);

            newBook.Save();

            Patrons newPatrons1 = new Patrons("Jerry");

            newPatrons1.Save();
            Patrons newPatrons2 = new Patrons("Jerry");

            newPatrons2.Save();

            newCopies.AddPatrons(newPatrons1);
            newCopies.AddPatrons(newPatrons2);

            List <Patrons> testList    = newCopies.GetPatronCopies();
            List <Patrons> controlList = new List <Patrons> {
                newPatrons1, newPatrons2
            };

            Assert.Equal(controlList, testList);
        }
Exemple #3
0
        public static List <Copies> GetAll()
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand    cmd = new SqlCommand("SELECT * FROM copies", conn);
            SqlDataReader rdr = cmd.ExecuteReader();

            List <Copies> copies = new List <Copies> {
            };

            while (rdr.Read())
            {
                int id         = rdr.GetInt32(0);
                int testcopies = rdr.GetInt32(1);

                Copies newBook = new Copies(testcopies, id);
                copies.Add(newBook);
            }

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return(copies);
        }
        public void Patrons_AddCopies_AddsCopiesToPatron()
        {
            Patrons newPatron = new Patrons("Jenny", 1);

            newPatron.Save();

            Books newBooks = new Books("Of Mice and Men", 1);

            newBooks.Save();

            Copies newCopies1 = new Copies(1, DateTime.Now, 1);

            newCopies1.Save();
            Copies newCopies2 = new Copies(1, DateTime.Now, 1);

            newCopies2.Save();

            newCopies1.AddPatrons(newPatron);
            newCopies2.AddPatrons(newPatron);

            List <Patrons> testList    = newCopies1.GetPatronCopies();
            List <Patrons> controlList = new List <Patrons> {
                newPatron
            };

            Assert.Equal(controlList, testList);
        }
Exemple #5
0
        public void Copies_AddBook_AddCopiesToPatrons()
        {
            Copies newCopies = new Copies(1);

            newCopies.Save();
            Books newBook = new Books("Of mice and men", "John Steinbeck", new DateTime(2017, 05, 06), 1);

            newBook.Save();

            Patrons newPatrons1 = new Patrons("Jerry", 1);

            newPatrons1.Save();
            Patrons newPatrons2 = new Patrons("Jerry", 2);

            newPatrons2.Save();

            // Console.WriteLine(newCopies.GetId());
            // Console.WriteLine(testCopies.GetId());

            newCopies.AddPatrons(newPatrons1);
            newCopies.AddPatrons(newPatrons2);


            List <Patrons> testList    = newCopies.GetPatronCopies();
            List <Patrons> controlList = new List <Patrons> {
                newPatrons1, newPatrons2
            };

            Assert.Equal(controlList, testList);
        }
        public void Copies_GetAll_DatabaseEmpty()
        {
            List <Copies> newCopies  = Copies.GetAll();
            List <Copies> testCopies = new List <Copies> {
            };

            Assert.Equal(newCopies, testCopies);
        }
        public void Copies_Save_SaveCopiesToDatabase()
        {
            Copies newCopy = new Copies(1, DateTime.Now, 1);

            newCopy.Save();

            List <Copies> controlList = Copies.GetAll();
            List <Copies> testList    = new List <Copies> {
                newCopy
            };

            Assert.Equal(controlList, testList);
        }
Exemple #8
0
        public override bool Equals(System.Object otherCopies)
        {
            if (!(otherCopies is Copies))
            {
                return(false);
            }
            else
            {
                Copies newCopies        = (Copies)otherCopies;
                bool   copiesIdEquality = this.GetCopiesId() == newCopies.GetCopiesId();
                bool   idEquality       = this.GetId() == newCopies.GetId();

                return(copiesIdEquality && idEquality);
            }
        }
Exemple #9
0
        public void Copies_Save_SaveCopiesToDatabase()
        {
            Copies newCopy = new Copies(10, 1);

            newCopy.Save();

            List <Copies> controlList = Copies.GetAll();

            Console.WriteLine(controlList[0].GetCopiesId());
            List <Copies> testList = new List <Copies> {
                newCopy
            };

            Console.WriteLine("copiestestline36", controlList[0]);

            Assert.Equal(controlList, testList);
            Console.WriteLine("copiestestline36", controlList[0]);
        }
        public void Copies_Delete_DeleteSingleCopy()
        {
            Patrons newPatrons = new Patrons("David", 1);

            newPatrons.Save();
            Books newBook = new Books("Of mice and men", 1);

            newBook.Save();
            Copies newCopies = new Copies(1, DateTime.Now, 1);

            newCopies.Save();

            newCopies.AddPatrons(newPatrons);

            newCopies.Delete();

            List <Copies> testCopies    = Copies.GetAll();
            List <Copies> controlCopies = new List <Copies> {
            };

            Assert.Equal(controlCopies, testCopies);
        }