Beispiel #1
0
 public ActionResult Add()
 {
     var dvd = new DVD();
         dvd.CastMembers = new List<Cast>();
         dvd.CastMembers.Add(new Cast());
         dvd.CastMembers[0].CastRoleName = "actor";
         return View(dvd);
 }
Beispiel #2
0
 public ActionResult Add(DVD dvd)
 {
     if (ModelState.IsValid)
     {
         var repo  = new Repo();
         repo.AddDVD(dvd);
         return RedirectToAction("Index", "Home");
     }
     else
     {
         return View(dvd);
     }
 }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        public int AddDVD(DVD dvd)
        {
            List<CastRole> Roles;

            using (SqlConnection cn = new SqlConnection(ConnString))
            {
                Roles = cn.Query<CastRole>("GetAllRoles", commandType: CommandType.StoredProcedure).ToList();

                DynamicParameters p = new DynamicParameters();
                p.Add("dvdID", DbType.Int32, direction: ParameterDirection.Output);
                p.Add("Title", dvd.Title);
                p.Add("ReleaseDate", dvd.ReleaseDate?.ToString());
                p.Add("MPAA", dvd.MPAA);
                p.Add("Studio", dvd.Studio);

                cn.Query("AddDVD", p, commandType: CommandType.StoredProcedure);

                int dvdID = p.Get<int>("dvdID");

                foreach (Cast c in dvd.CastMembers)
                {
                    p = new DynamicParameters();
                    p.Add("FirstName", c.CastFirstName);
                    p.Add("LastName", c.CastLastName);
                    p.Add("CastID", DbType.Int32, direction: ParameterDirection.ReturnValue);

                    cn.Query("AddCast", p, commandType: CommandType.StoredProcedure).FirstOrDefault();

                    int castID = p.Get<int>("CastID");

                    p = new DynamicParameters();
                    p.Add("dvdID", dvdID);
                    p.Add("CastID", castID);
                    p.Add("CastRoleID", Roles.FirstOrDefault(cr => cr.CastRoleName == c.CastRoleName).CastRoleID);

                    cn.Query("AddCastDetails", p, commandType: CommandType.StoredProcedure);
                }
                return dvdID;
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        public void FillInDetails_DetailMatch_Top1_Test()
        {
            Settings set = new Settings(connectionString);
            Repo repo = new Repo();
            DVD expectedDetails = new DVD();

            using (SqlConnection cn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT TOP 1 d.*, ar.AverageRating FROM DVDs d FULL JOIN(SELECT AVG(r.DVDRating) AS AverageRating, r.dvdID FROM Ratings r GROUP BY r.dvdID) AS ar on ar.dvdID = d.dvdID WHERE Deleted IS NULL OR Deleted <> 1";
                cmd.Connection = cn;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        expectedDetails.dvdID = (int)dr["dvdID"];
                        expectedDetails.Title = dr["Title"].ToString();
                        expectedDetails.ReleaseDate = DateTime.Parse(dr["ReleaseDate"].ToString());
                        expectedDetails.MPAA = dr["MPAA"].ToString();
                        expectedDetails.Studio = dr["Studio"].ToString();
                        expectedDetails.AverageRating = (int)dr["AverageRating"];

                    }
                }
            }

            DVD dvd_detailed = repo.FillInDetails(1);

            Assert.AreEqual(expectedDetails.dvdID, dvd_detailed.dvdID);
            Assert.AreEqual(expectedDetails.AverageRating, dvd_detailed.AverageRating);
            Assert.AreEqual(expectedDetails.MPAA, dvd_detailed.MPAA);
            Assert.AreEqual(expectedDetails.ReleaseDate, dvd_detailed.ReleaseDate);
            Assert.AreEqual(expectedDetails.Studio, dvd_detailed.Studio);
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
 public void Update(DVD updatedDVD)
 {
     _DVD.RemoveAll(c => c.DvdId == updatedDVD.DvdId);
     _DVD.Add(updatedDVD);
 }