public ActionResult Add(DVD dvd) { if (ModelState.IsValid) { var repo = new Repo(); repo.AddDVD(dvd); return RedirectToAction("Index", "Home"); } else { return View(dvd); } }
public void AddDVD_AddSucceeds_Test(string test_title) { DVD expected = new DVD() { Title = test_title, CastMembers = new List<Cast>() { new Cast() {CastFirstName = "Dolan", CastLastName = "Dcuk", CastRoleName = "actor" }, new Cast() {CastFirstName = "Uncel", CastLastName = "Scroge", CastRoleName = "actor" }, new Cast() {CastFirstName = "Blue", CastLastName = "Meanie", CastRoleName = "actor" } }, ReleaseDate = new DateTime(2001, 1, 1), MPAA = "PG", Studio = "Balooney Pictures", }; Settings set = new Settings(connectionString); Repo repo = new Repo(); int newID = repo.AddDVD(expected); string title = ""; using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = $"SELECT TOP 1 * FROM DVDs WHERE Title = '{test_title}' AND dvdID = {newID}"; cmd.Connection = cn; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { title = dr["Title"].ToString(); } } Assert.AreEqual(expected.Title, title); DynamicParameters p = new DynamicParameters(); p.Add("dvdID", newID); cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure); } }
public void AddRating_NotBoundToBorrowHistory(int userID, int rating, string note) { DVD toRate = new DVD() { Title = "RateThis", CastMembers = new List<Cast>() }; Settings set = new Settings(connectionString); Repo repo = new Repo(); int newID = repo.AddDVD(toRate); repo.AddRating(newID, userID, rating, note); DVD result = repo.FillInDetails(newID); Assert.AreEqual(rating, result.History[0].DVDRating); Assert.AreEqual(note, result.History[0].DVDNote); using (SqlConnection cn = new SqlConnection(connectionString)) { DynamicParameters p = new DynamicParameters(); p.Add("dvdID", newID); cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure); } }
public void SearchByTitle_FullMatch(string fakeTitle) { DVD searchMe = new DVD() { Title = fakeTitle, CastMembers = new List<Cast>(), }; Settings set = new Settings(connectionString); Repo repo = new Repo(); int newID = repo.AddDVD(searchMe); int wantedID = 0; using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = $"SELECT TOP 1 * FROM DVDs WHERE Title = '{fakeTitle}' AND dvdID = {newID}"; cmd.Connection = cn; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { wantedID = (int)dr["dvdID"]; } } List<DVD> results = repo.SearchForDVDTitle(fakeTitle); Assert.AreEqual(wantedID, results.FirstOrDefault().dvdID); DynamicParameters p = new DynamicParameters(); p.Add("dvdID", newID); cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure); } }
public void Borrow_And_Return_DVDs(bool borrow) { DVD toBorrow = new DVD() { Title = "BorrowThis", CastMembers = new List<Cast>() }; Settings set = new Settings(connectionString); Repo repo = new Repo(); int newID = repo.AddDVD(toBorrow); repo.DVD_BorrowReturn(1, newID, true); List<DVD> dvds = repo.GetList(); Assert.IsTrue(!dvds.FirstOrDefault(d => d.Title == "BorrowThis" && d.dvdID == newID).Available); if (!borrow) { repo.DVD_BorrowReturn(1, newID, false); dvds = repo.GetList(); Assert.IsTrue(dvds.FirstOrDefault(d => d.Title == "BorrowThis" && d.dvdID == newID).Available); } using (SqlConnection cn = new SqlConnection(connectionString)) { DynamicParameters p = new DynamicParameters(); p.Add("dvdID", newID); cn.Query("EraseDVDRecord", p, commandType: CommandType.StoredProcedure); } }