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); }
//Returns a book to the library and sets the return date in Checkout object public void ReturnBook(int patronId) { SqlConnection conn = DB.Connection(); conn.Open(); DateTime today = DateTime.Today; SqlCommand cmd = new SqlCommand("UPDATE checkouts SET date_returned = @ReturnDate WHERE patrons_id = @PatronId AND copies_id IN (SELECT id FROM copies WHERE books_id = @BookId);", conn); cmd.Parameters.Add(new SqlParameter("@PatronId", patronId)); cmd.Parameters.Add(new SqlParameter("@BookId", this.GetId())); cmd.Parameters.Add(new SqlParameter("@ReturnDate", today)); SqlDataReader rdr = cmd.ExecuteReader(); int myCheckoutId = 0; while (rdr.Read()) { myCheckoutId = rdr.GetInt32(0); Checkout myCheckout = Checkout.Find(myCheckoutId); Console.WriteLine("MYCHECKOUT: " + myCheckout.GetReturnDate()); myCheckout.UpdateReturnDate(today); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } }