Exemplo n.º 1
0
        public void DurationInvalidData()
        {
            //Create an instance of the class we want toc reate
            clsFilm AFilm = new clsFilm();
            //String variable to store any error message
            string Error = "";
            //Create some test data to pass to the method
            string Title       = "Lawrence of Molvania";
            string Duration    = "XYZ!";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            Error = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Exemplo n.º 2
0
        public void FilmReleaseDateMin()
        {
            //create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //String Error stores any error message
            String Error = "";
            //create test data
            DateTime TestDate;

            TestDate = new DateTime(1888, 1, 1);
            string FilmReleaseDate = TestDate.ToString();

            //invoke method
            Error = AFilm.Valid(FilmName, FilmDescription, FilmCertificate, FilmReleaseDate, FilmDepartureDate);
            //test to see if result is correct
            Assert.AreEqual(Error, "");
        }
Exemplo n.º 3
0
        public void TitleMaxPlusOne()
        {
            //Create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //String variable to store any error message
            string Error = "";
            //Create some test data to pass to the method
            string Title       = "1. Letters, numbers and punctuation are accepted!!!"; //This should fail
            string Duration    = "85";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            Error = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Exemplo n.º 4
0
        public void DurationMid()
        {
            //Create an instance of the class we want toc reate
            clsFilm AFilm = new clsFilm();
            //Boolean variable to store the result of the validation
            Boolean OK = false;
            //Create some test data to pass to the method
            string Title       = "Lawrence of Molvania";
            string Duration    = "12";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            OK = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.IsTrue(OK);
        }
Exemplo n.º 5
0
        public void TitleMid()
        {
            //Create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //Boolean variable to store the result of the validation
            Boolean OK = false;
            //Create some test data to pass to the method
            string Title       = "ABCDEFGHIJKLMNOPQRSTUVWXY"; //This should pass
            string Duration    = "85";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            OK = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.IsTrue(OK);
        }
Exemplo n.º 6
0
        public void TitleMax()
        {
            //Create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //Boolean variable to store the result of the validation
            Boolean OK = false;
            //Create some test data to pass to the method
            string Title       = "1. Letters, numbers and punctuation are accepted!!"; //This should pass
            string Duration    = "85";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            OK = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.IsTrue(OK);
        }
Exemplo n.º 7
0
        public void TitleMinLessOne()
        {
            //Create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //Boolean variable to store the result of the validation
            Boolean OK = false;
            //Create some test data to pass to the method
            string Title       = ""; //This should trigger an error
            string Duration    = "85";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            OK = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.IsFalse(OK);
        }
Exemplo n.º 8
0
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
        clsFilm AFilm = new clsFilm();

        string  FilmName          = txtFilmName.Text;
        string  FilmDescription   = txtFilmDesc.Text;
        string  FilmCertificate   = txtCert.Text;
        string  FilmReleaseDate   = txtRelease.Text;
        string  FilmDepartureDate = txtDeparture.Text;
        Boolean FilmShowing       = showingCheck.Checked;
        string  Error             = "";

        Error = AFilm.Valid(FilmName, FilmDescription, FilmCertificate, FilmReleaseDate, FilmDepartureDate);
        if (Error == "")
        {
            AFilm.FilmID            = FilmId;
            AFilm.FilmName          = FilmName;
            AFilm.FilmDescription   = FilmDescription;
            AFilm.FilmCertificate   = FilmCertificate;
            AFilm.FilmReleaseDate   = Convert.ToDateTime(FilmReleaseDate);
            AFilm.FilmDepartureDate = Convert.ToDateTime(FilmDepartureDate);

            clsFilmCollection FilmList = new clsFilmCollection();

            if (FilmId == -1)
            {
                FilmList.ThisFilm = AFilm;
                FilmList.Add();
            }
            else
            {
                FilmList.ThisFilm.Find(FilmId);
                FilmList.ThisFilm = AFilm;
                FilmList.Update();
            }

            Response.Redirect("FilmViewer.aspx");

            //Session["AFilm"] = AFilm;
        }
        else
        {
            lblError.Text = Error;
        }
    }
Exemplo n.º 9
0
        public void TitleExtremeMax()
        {
            //Create an instance of the class we want to create
            clsFilm AFilm = new clsFilm();
            //String variable to store any error message
            string Error = "";
            //Create some test data to pass to the method
            string Title = "";

            Title = Title.PadRight(500, 'X'); //This should fail
            string Duration    = "85";
            string AgeRatingID = "3";
            string GenreID     = "2";

            //Invoke the method
            Error = AFilm.Valid(Title, Duration, AgeRatingID, GenreID);
            //Test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Exemplo n.º 10
0
        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;
            }
        }