public void AddMethodOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmGenre TestItem = new clsFilmGenre(); TestItem.FilmId = 1; TestItem.GenreId = 5; AllFilmGenres.ThisFilmGenre = TestItem; AllFilmGenres.Add(); AllFilmGenres.ThisFilmGenre.Find(TestItem.FilmId, TestItem.GenreId); Assert.AreEqual(AllFilmGenres.ThisFilmGenre, TestItem); }
public void DeleteMethodOk() { clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmGenre TestItem = new clsFilmGenre(); TestItem.FilmId = 1; TestItem.GenreId = 5; AllFilmGenres.ThisFilmGenre = TestItem; AllFilmGenres.Add(); AllFilmGenres.Delete(); Boolean found = AllFilmGenres.ThisFilmGenre.Find(TestItem.FilmId, TestItem.GenreId); Assert.IsFalse(found); }
public void DeleteByFilmIdMethodOk() { bool found; clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); clsFilmCollection AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.Title = "test"; Int32 primaryKey = AllFilms.Add(); Int32 genreId = 1; AllFilmGenres.ThisFilmGenre.FilmId = primaryKey; AllFilmGenres.ThisFilmGenre.GenreId = genreId; AllFilmGenres.Add(); AllFilmGenres.DeleteByFilmId(); found = AllFilmGenres.ThisFilmGenre.Find(primaryKey, genreId); Assert.IsFalse(found); }
protected void btnActionFilm_Click(object sender, EventArgs e) { string originalTitle = ""; editFilm = Convert.ToBoolean(Session["EditFilm"]); if (editFilm) { originalTitle = Session["Title"].ToString(); } string newTitle = txtFilmTitle.Text; string tempImdbId = txtImdbId.Text; Int32 imdbId = 0; bool imdbIdOk = false; clsFilm aFilm = new clsFilm(); var filmTitleCheck = aFilm.Valid(newTitle); if (filmTitleCheck.Count != 0) { foreach (string error in filmTitleCheck) { Label lblError = new Label(); lblError.Text = "- " + error; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); } } clsLinkCollection AllLinks = new clsLinkCollection(); var imdbIdCheck = AllLinks.ThisLink.Valid(tempImdbId); if (imdbIdCheck.Count != 0) { foreach (string error in imdbIdCheck) { Label lblError = new Label(); lblError.Text = "- " + error; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); imdbIdOk = false; } pnlActionFilmError.Visible = true; } else { imdbId = Convert.ToInt32(tempImdbId); bool ImdbIdAlreadyExists = AllLinks.ImdbIdAlreadyExistsCheck(imdbId); if (ImdbIdAlreadyExists) { //if (!editFilm) //adding a new film //{ Label lblError = new Label(); lblError.Text = "- IMDBId already assigned to another film"; pnlActionFilmErrorBody.Controls.Add(lblError); pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); pnlActionFilmError.Visible = true; imdbIdOk = false; //} Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]); if (originalImdbId == imdbId) { imdbIdOk = true; } else { imdbIdOk = false; } //else //if we're editing a film //{ // Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]); // if (originalImdbId != imdbId) // { // Label lblError = new Label(); // lblError.Text = "- IMDBId already assigned to another film"; // pnlActionFilmErrorBody.Controls.Add(lblError); // pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />")); // imdbIdOk = false; // } // else // { // imdbIdOk = true; // } //} } else { imdbIdOk = true; } } newTitle = newTitle.TrimEnd(); string yearReleased = " " + "(" + ddlYear.SelectedValue + ")"; string titleAndYearReleased = newTitle + yearReleased; bool filmAlreadyExists = false; clsFilmCollection AllFilms = new clsFilmCollection(); if (AllFilms.FilmAlreadyExistsCheck(titleAndYearReleased)) { if (!editFilm) { Label lblError = new Label(); lblError.Text = "Film already exists"; pnlActionFilmErrorBody.Controls.Add(lblError); filmAlreadyExists = true; } else //if we ARE editing a film { if (newTitle != originalTitle) { Label lblError = new Label(); lblError.Text = "Film already exists"; pnlActionFilmErrorBody.Controls.Add(lblError); filmAlreadyExists = true; } else { filmAlreadyExists = false; } } } else { filmAlreadyExists = false; } if (!editFilm && !filmAlreadyExists && imdbIdOk) { AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.Title = titleAndYearReleased; Int32 filmId = AllFilms.Add(); AllLinks.ThisLink.FilmId = filmId; AllLinks.ThisLink.ImdbId = imdbId; AllLinks.Add(); clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); foreach (ListItem item in chkbxlstGenres.Items) { if (item.Selected) { AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value); AllFilmGenres.Add(); AllFilmGenres = new clsFilmGenreCollection(); } } LoadData(); pnlActionFilm.Visible = false; } if (editFilm) { AllFilms = new clsFilmCollection(); AllFilms.ThisFilm.FilmId = Convert.ToInt32(Session["FilmId"]); newTitle = titleAndYearReleased; if (newTitle == originalTitle) { AllFilms.ThisFilm.Title = originalTitle; } else { AllFilms.ThisFilm.Title = newTitle; } AllFilms.Update(); clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection(); AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.DeleteByFilmId(); foreach (ListItem item in chkbxlstGenres.Items) { if (item.Selected) { AllFilmGenres.ThisFilmGenre.FilmId = filmId; AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value); AllFilmGenres.Add(); AllFilmGenres = new clsFilmGenreCollection(); } } LoadData(); pnlActionFilm.Visible = false; } }