public void Get_ShowTimes_by_MovieID()
        {
            //Insert a movie:
            IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper {
                Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png"
            });
            //Create some showtimes:
            IShowTimesMapper showtime1 = new ShowTimesMapper {
                ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05)
            };
            IShowTimesMapper showtime2 = new ShowTimesMapper {
                ShowingDateTime = new DateTime(2016, 01, 20, 13, 01, 05)
            };
            IShowTimesMapper showtime3 = new ShowTimesMapper {
                ShowingDateTime = new DateTime(2015, 01, 20, 13, 01, 05)
            };

            //Insert the showtimes:
            movies_bll.InsertShowTime(movie1, showtime1);
            movies_bll.InsertShowTime(movie1, showtime2);
            movies_bll.InsertShowTime(movie1, showtime3);
            //Get the showtimes back out of the database:
            List <IShowTimesMapper> found_showtimes = movies_bll.Get_ShowTimes_by_MovieID(movie1);

            //Assert
            Assert.IsTrue(found_showtimes.Count == 3);
        }
 public void InsertShowTime_missing_movieId()
 {
     IMovieMapper movie1 = new MovieMapper {
         Id = 0
     };
     IShowTimesMapper showtime1 = new ShowTimesMapper {
         ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05)
     };
     IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1);
 }
 public void InsertShowTime_missing_ShowingDateTime()
 {
     //Insert a movie:
     IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper {
         Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png"
     });
     IShowTimesMapper showtime1 = new ShowTimesMapper {
         ShowingDateTime = new DateTime()
     };                                                                                     //Try to insert minValue DateTime (empty datetime).
     IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1);
 }
        public void InsertShowTime()
        {
            //Insert a movie:
            IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper {
                Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png"
            });
            IShowTimesMapper showtime1 = new ShowTimesMapper {
                ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05)
            };
            IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1);

            Assert.IsNotNull(returned_showtime);
            Assert.IsTrue(returned_showtime.Id > 0);
        }
Пример #5
0
        public List <IShowTimesMapper> Get_ShowTimes_by_MovieID(IMovieMapper movie)
        {
            List <IShowTimesMapper> output = new List <IShowTimesMapper>();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand("select_all_showtimes_by_movie_id", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        //Add input parameters:
                        command.Parameters.Add("@MovieID", SqlDbType.Int).Value = movie.Id;

                        command.Prepare();
                        SqlDataReader showtimes = command.ExecuteReader();

                        while (showtimes.Read())
                        {
                            //Create a new showtime object:
                            ShowTimesMapper showtime = new ShowTimesMapper();
                            showtime.Id = (int)showtimes["Id"];
                            showtime.ShowingDateTime = (DateTime)showtimes["ShowingDateTime"];
                            showtime.MovieId         = (int)showtimes["MovieId"];

                            //Add this new object to a collection:
                            output.Add(showtime);
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                throw new SqlDALException("There was a problem with SQL.  Please provide valid data.  The MovieId field must be provided, and must exist in the database.", e);
            }
            return(output);
        }
Пример #6
0
        //CRUD functionality for 'ShowTimes' table:

        //Create:
        public IShowTimesMapper InsertShowTime(IMovieMapper movie, IShowTimesMapper showtime)
        {
            IShowTimesMapper output = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand("insert_ShowTime", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        //Add input parameters:
                        command.Parameters.Add("@ShowingDateTime", SqlDbType.DateTime).Value = showtime.ShowingDateTime;
                        command.Parameters.Add("@MovieId", SqlDbType.Int).Value = movie.Id;

                        //Setup output parameter for the returned Movie.Id:
                        SqlParameter IdentityOutput = command.Parameters.Add("@IdentityOutput", SqlDbType.Int);
                        IdentityOutput.Value     = null;
                        IdentityOutput.Direction = ParameterDirection.Output;

                        command.Prepare();
                        command.ExecuteNonQuery(); //Run the query.

                        //Return the user that was created:
                        output    = new ShowTimesMapper();
                        output.Id = (int)IdentityOutput.Value;
                        output.ShowingDateTime = (DateTime)showtime.ShowingDateTime;
                        output.MovieId         = (int)movie.Id;
                    }
                }
            }
            catch (SqlException e)
            {
                throw new SqlDALException("There was a problem with SQL.  Please provide valid data.  The ShowingDateTime and MovieId fields must be provided.", e);
            }
            return(output);
        }