public void GetCheckedOutCopies_OnlyReturnsCheckedoutBook() { DateTime dueDate = new DateTime(2017, 6, 1); Patron newPatron = new Patron("Joe"); newPatron.Save(); Book newBook = new Book("Gone With the Wind"); newBook.Save(); Copy copy1 = new Copy(newBook.GetId()); copy1.Save(); newPatron.Checkout(copy1.GetId(), newPatron.GetId(), dueDate); Copy copy2 = new Copy(newBook.GetId()); copy2.Save(); Checkout newCheckout = newPatron.Checkout(copy2.GetId(), newPatron.GetId(), dueDate); newCheckout.CheckIn(); DateTime currentDate = new DateTime(2017, 7, 1); List <Copy> expectedResult = new List <Copy> { copy1 }; List <Copy> actualResult = newPatron.GetCheckedOutCopies(currentDate); Assert.Equal(expectedResult, actualResult); }
public void Patron_ReturnCheckoutItems() { Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Author newAuthor = new Author("Ernest Hemingway"); newAuthor.Save(); Book newBook = new Book("Old Man and the Sea", 5); newBook.Save(); Book otherBook = new Book("Farewell to Arms", 7); otherBook.Save(); Checkout newCheckout = new Checkout("2017/03/30", newPatron.GetId(), newBook.GetId()); newCheckout.Save(newBook); Checkout otherCheckout = new Checkout("2017/01/30", newPatron.GetId(), otherBook.GetId()); otherCheckout.Save(newBook); List <Checkout> actual = newPatron.GetCheckouts(); List <Checkout> expected = new List <Checkout> { otherCheckout, newCheckout }; Assert.Equal(expected, actual); }
public void AddPatron(Patron newPatron) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO checkouts (patron_id, copy_id) VALUES (@PatronId, @CopyId);", conn); SqlParameter patronIdParameter = new SqlParameter(); patronIdParameter.ParameterName = "@PatronId"; patronIdParameter.Value = newPatron.GetId(); cmd.Parameters.Add(patronIdParameter); SqlParameter copyIdParameter = new SqlParameter(); copyIdParameter.ParameterName = "@CopyId"; copyIdParameter.Value = this.GetId(); cmd.Parameters.Add(copyIdParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
public void GetCheckedOutCopies_ReturnListOfCopies() { Patron newPatron = new Patron("Joe"); newPatron.Save(); Book newBook = new Book("Gone With the Wind"); newBook.Save(); Copy newCopy = new Copy(newBook.GetId()); newCopy.Save(); DateTime dueDate = new DateTime(2017, 6, 1); newPatron.Checkout(newCopy.GetId(), newPatron.GetId(), dueDate); DateTime currentDate = new DateTime(2017, 7, 1); List <Copy> expectedResult = new List <Copy> { newCopy }; List <Copy> actualResult = newPatron.GetCheckedOutCopies(currentDate); Assert.Equal(expectedResult, actualResult); }
public void T5_Find_FindsPatronInDatabase() { Patron testPatron = new Patron("Judy"); testPatron.Save(); Patron foundPatron = Patron.Find(testPatron.GetId()); Assert.Equal(testPatron, foundPatron); }
public void Test_Find_FindPatronInDatabase() { Patron testPatron1 = new Patron ("Jane", "Doe", "555-555-5555"); testPatron1.Save(); Patron result = Patron.Find(testPatron1.GetId()); Assert.Equal(testPatron1, result); }
public void FindById_ReturnsPatronWhenSearchedById() { Patron newPatron = new Patron("Joe"); newPatron.Save(); Patron result = Patron.FindById(newPatron.GetId()); Assert.Equal(newPatron, result); }
public void Patron_Find_3() { Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Patron foundPatron = Patron.Find(newPatron.GetId()); Assert.Equal(newPatron, foundPatron); }
public void Patron_Delete_RemoveFromDatabase_4() { Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Patron.Delete(newPatron.GetId()); Assert.Equal(0, Patron.GetAll().Count); }
public void T4_Save_AssignsIdToPatron() { Patron testPatron = new Patron("Judy"); testPatron.Save(); Patron savedPatron = Patron.GetAll()[0]; int result = savedPatron.GetId(); int testId = testPatron.GetId(); Assert.Equal(testId, result); }
public void Find_FindsPatronInDatabase_true() { //Arrange Patron testPatron = new Patron("Penny Flowers"); testPatron.Save(); //Act Patron foundPatron = Patron.Find(testPatron.GetId()); //Assert Assert.Equal(testPatron, foundPatron); }
public override bool Equals(System.Object otherPatron) { if (!(otherPatron is Patron)) { return(false); } else { Patron newPatron = (Patron)otherPatron; bool idEquality = this.GetId() == newPatron.GetId(); bool nameEquality = this.GetName() == newPatron.GetName(); return(idEquality && nameEquality); } }
public void Test_Save_AssignsIdToPatronObject() { //Arrange Patron testPatron = new Patron("Britton"); testPatron.Save(); //Act Patron savedPatron = Patron.GetAll()[0]; int result = savedPatron.GetId(); int testId = testPatron.GetId(); //Assert Assert.Equal(testId, result); }
public void Save_SavesCheckoutToDatabase_2() { Author newAuthor = new Author("Ernest Hemingway"); newAuthor.Save(); Book newBook = new Book("Old Man and the Sea", 5); newBook.Save(); newBook.AddAuthor(newAuthor.GetId()); Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Checkout newCheckout = new Checkout("2017/05/1", newPatron.GetId(), newBook.GetId()); newCheckout.Save(newBook); Assert.Equal(4, newBook.GetCopies()); }
public void Test_Find_FindsPatronInDatabase() { //Arrange Patron testPatron1 = new Patron("example patron1"); testPatron1.Save(); Patron testPatron2 = new Patron("example patron2"); testPatron2.Save(); //Act Patron result = Patron.Find(testPatron2.GetId()); //Assert Assert.Equal(testPatron2, result); }
public void T1_Checkout_CreatesACheckoutRecord() { Patron testPatron = new Patron("Judy"); testPatron.Save(); Copy testCopy = new Copy(5); testCopy.Save(); DateTime checkoutDate = new DateTime(2016,08,04); DateTime dueDate = new DateTime(2017,01,02); Checkout newCheckout = new Checkout(testCopy.GetId(), testPatron.GetId(), checkoutDate, dueDate); newCheckout.Save(); List<Checkout> result = Checkout.GetAll(); Assert.Equal(newCheckout, result[0]); }
public void Return_SpecificCheckAndAddCopyToBook() { Author newAuthor = new Author("Ernest Hemingway"); newAuthor.Save(); Book newBook = new Book("Old Man and the Sea", 5); newBook.Save(); newBook.AddAuthor(newAuthor.GetId()); Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Checkout newCheckout = new Checkout("2017/05/1", newPatron.GetId(), newBook.GetId()); newCheckout.Save(newBook); Checkout.Return(newCheckout.GetId()); int actual = Book.GetAll()[0].GetCopies(); Assert.Equal(5, actual); }
public void Update_UpdateInDatabase_true() { //Arrange Author newAuthor = new Author("Ernest Hemingway"); newAuthor.Save(); Book newBook = new Book("Old Man and the Sea", 5); newBook.Save(); newBook.AddAuthor(newAuthor.GetId()); Patron newPatron = new Patron("Johnny English", "555-555-5555"); newPatron.Save(); Checkout newCheckout = new Checkout("2017/05/1", newPatron.GetId(), newBook.GetId()); newCheckout.Save(newBook); //Act newCheckout.Update("2017/06/12"); string result = newCheckout.GetDueDate(); //Assert Assert.Equal("2017/06/12", result); // Assert.Equal(newName, result.GetName()); }
public void T1_Checkout_CreatesACheckoutRecord() { Patron testPatron = new Patron("Judy"); testPatron.Save(); Copy testCopy = new Copy(5); testCopy.Save(); DateTime checkoutDate = new DateTime(2016, 08, 04); DateTime dueDate = new DateTime(2017, 01, 02); Checkout newCheckout = new Checkout(testCopy.GetId(), testPatron.GetId(), checkoutDate, dueDate); newCheckout.Save(); List <Checkout> result = Checkout.GetAll(); Assert.Equal(newCheckout, result[0]); }
public void Test_Update_UpdatePatronInDatabase() { Patron newPatron = new Patron ("Jane", "Doe", "555-555-5555"); newPatron.Save(); newPatron.SetPhoneNumber ("111-111-1111"); newPatron.Update(); Patron updatedPatron = Patron.Find(newPatron.GetId()); Assert.Equal(newPatron.GetPhoneNumber(), updatedPatron.GetPhoneNumber()); }