Ejemplo n.º 1
0
        //Create new row in Checkout table
        public void CheckoutBook(int patronId)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT TOP(1) id FROM copies WHERE books_id = @BookId AND copies.id NOT IN (SELECT copies_id FROM checkouts);", conn);

            cmd.Parameters.Add(new SqlParameter("@BookId", this.GetId()));
            SqlDataReader rdr = cmd.ExecuteReader();

            int copyId = 0;

            while (rdr.Read())
            {
                copyId = rdr.GetInt32(0);
            }

            DateTime dueDate = DateTime.Today.AddDays(14);

            Checkout newCheckout = new Checkout(dueDate, patronId, copyId);

            newCheckout.Save();

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
        }
Ejemplo n.º 2
0
        public void TestFind_FindsCheckoutInDatabase()
        {
            //Arrange
            DateTime dueDate      = new DateTime(2017, 3, 15);
            DateTime returnDate   = new DateTime(2017, 3, 7);
            Checkout testCheckout = new Checkout(dueDate, 1, 1);

            testCheckout.Save();

            //Act
            Checkout foundCheckout = Checkout.Find(testCheckout.GetId());

            //Assert
            Assert.Equal(testCheckout, foundCheckout);
        }
Ejemplo n.º 3
0
        public void TestSave_AssignIdtoObject()
        {
            //Arrange
            DateTime dueDate      = new DateTime(2017, 3, 15);
            DateTime returnDate   = new DateTime(2017, 3, 7);
            Checkout testCheckout = new Checkout(dueDate, 1, 1);

            //Act
            testCheckout.Save();
            Checkout savedCheckout = Checkout.GetAll()[0];

            //Assert
            int actualResult   = savedCheckout.GetId();
            int expectedResult = testCheckout.GetId();

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 4
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
            DateTime dueDate     = new DateTime(2017, 3, 15);
            DateTime returnDate  = new DateTime(2017, 3, 7);
            Checkout newCheckout = new Checkout(dueDate, 1, 1);

            //Act
            newCheckout.Save();

            //Assert
            List <Checkout> actualResult   = Checkout.GetAll();
            List <Checkout> expectedResult = new List <Checkout> {
                newCheckout
            };

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 5
0
        public void TestSearchDueDate_SearchSearchDueDateInDatabase()
        {
            //Arrange
            DateTime dueDate      = new DateTime(2017, 3, 15);
            DateTime returnDate   = new DateTime(2017, 3, 7);
            Checkout testCheckout = new Checkout(dueDate, 1, 1);

            testCheckout.Save();

            //Act
            List <Checkout> allDue  = Checkout.SearchDueDate(dueDate);
            List <Checkout> testDue = new List <Checkout> {
                testCheckout
            };

            //Assert
            Assert.Equal(testDue, allDue);
        }
Ejemplo n.º 6
0
        public void TestGetAll_Checkouts_ReturnsListOfCheckouts()
        {
            //Arrange
            DateTime dueDate        = new DateTime(2017, 3, 15);
            DateTime returnDate     = new DateTime(2017, 3, 7);
            Checkout firstCheckout  = new Checkout(dueDate, 1, 1);
            Checkout secondCheckout = new Checkout(dueDate, 2, 2);

            //Act
            firstCheckout.Save();
            secondCheckout.Save();

            //Assert
            List <Checkout> actualResult   = Checkout.GetAll();
            List <Checkout> expectedResult = new List <Checkout> {
                firstCheckout, secondCheckout
            };

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 7
0
        public void Test_UpdateReturnDate_UpdatesReturnDateinDB()
        {
            //Arrange
            DateTime dueDate      = new DateTime(2017, 3, 15);
            DateTime returnDate   = new DateTime(2017, 3, 7);
            Checkout testCheckout = new Checkout(dueDate, 1, 1);

            testCheckout.Save();

            DateTime newReturnDate = new DateTime(2017, 4, 7);

            //Act
            testCheckout.UpdateReturnDate(newReturnDate);


            //Assert
            DateTime actualResult   = testCheckout.GetReturnDate();
            DateTime expectedResult = newReturnDate;

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 8
0
        public void Test_DeleteThisCheckout_OneCheckoutDeletedFromDatabase()
        {
            //Arrange
            DateTime dueDate        = new DateTime(2017, 3, 15);
            DateTime returnDate     = new DateTime(2017, 3, 7);
            Checkout firstCheckout  = new Checkout(dueDate, 1, 1);
            Checkout secondCheckout = new Checkout(dueDate, 2, 2);

            firstCheckout.Save();
            secondCheckout.Save();

            //Act
            firstCheckout.DeleteCheckout();
            List <Checkout> result = Checkout.GetAll();
            List <Checkout> verify = new List <Checkout> {
                secondCheckout
            };

            //Assert
            Assert.Equal(verify, result);
        }