public Movie Add(Movie item)
 {
     if (item == null)
         throw new ArgumentNullException("movie is null");
     if (item.Name == null)
         throw new ArgumentException("FirstName can not be null");
     using (Context mCon = new Context())
     {
         if (item.Genres.Count > 0)
         {
             List<Genre> temp = new List<Genre>();
             bool found = false;
             foreach (var gen in item.Genres.ToList())
             {
                 found = false;
                 foreach (var item2 in mCon.Genres.ToList())
                 {
                     if (gen.Id == item2.Id)
                     {
                         temp.Add(item2);
                         found = true;
                     }
                 }
                 if (!found)
                     temp.Add(gen);
             }
             item.Genres = temp;
         }
         item = mCon.Movies.Add(item);
         mCon.SaveChanges();
     }
     return item;
 }
        public void Movie_add_will_create_new_genre_test()
        {
            Facade facade = new Facade();
            Movie temp = new Movie() { Genres = new List<Genre>() { new Genre() {Name = "test" } }, Name = "test", Price = 120d, TrailerURL = "test" };
            temp = facade.GetMovieRepo().Add(temp);

            Assert.AreEqual(facade.GetMovieRepo().Get(temp.Id).Genres.FirstOrDefault().Name, "test");
        }
 public IEnumerable<Genre> GetGenreByMovie(Movie mov)
 {
     if (mov == null)
         throw new ArgumentNullException("Movie can not be null");
     using (Context mCon = new Context())
     {
         return mCon.Movies.Include("Genres").FirstOrDefault(x => x.Id == mov.Id).Genres.ToList();
     }
 }
        public HttpResponseMessage Movie(Movie item)
        {
            item = facade.GetMovieRepo().Add(item);
            var response = Request.CreateResponse<Movie>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
        public void Movie_added_on_call_test()
        {
            Movie temp = new Movie() { Name = "test", Price = 120d, TrailerURL = "test" };
            Facade facade = new Facade();
            temp = facade.GetMovieRepo().Add(temp);
            Context context = new Context();

            Assert.IsNotNull(context.Movies.FirstOrDefault(x=>x.Id == temp.Id));
            Assert.AreNotEqual(temp.Id, 0);
        }
        public void Genre_getgenrebymovie_return_multiple_test()
        {
            Facade facade = new Facade();
            Genre genre = new Genre() { Name = "test1" };
            Genre genretwo = new Genre() { Name = "test2" };
            List<Genre> list = new List<Genre>();
            //genre = facade.GetGenreRepo().Add(genre);
            //genretwo = facade.GetGenreRepo().Add(genretwo);
            list.Add(genre);
            list.Add(genretwo);
            Movie temp = new Movie() { Genres = list, Name = "test", Price = 120d, TrailerURL = "test" };
            temp = facade.GetMovieRepo().Add(temp);

            Assert.GreaterOrEqual(facade.GetGenreRepo().GetGenreByMovie(temp).ToList().Count, 2);
        }
        public void Movie_get_all_include_genres_test()
        {
            Facade facade = new Facade();
            Genre genre = new Genre() { Name = "test" };
            List<Genre> list = new List<Genre>();
            genre = facade.GetGenreRepo().Add(genre);
            list.Add(genre);
            Movie temp = new Movie() { Genres = list, Name = "test", Price = 120d, TrailerURL = "test" };
            temp = facade.GetMovieRepo().Add(temp);
            temp = facade.GetMovieRepo().Add(temp);

            facade = new Facade();
            Assert.IsNotNull(facade.GetMovieRepo().GetAll().ElementAt(0).Genres.FirstOrDefault());
            Assert.IsNotNull(facade.GetMovieRepo().GetAll().ElementAt(1).Genres.FirstOrDefault());
        }
        public void Order_added_on_create_test()
        {
            Facade facade = new Facade();

            Customer cus = new Customer()
            {
                FirstName = "Test",
                Address = "TestAddress",
                BirthDate = DateTime.Now,
                Email = "TestEmail",
                PhoneNumber = 1234
            };
            cus = facade.GetCustomerRepo().Add(cus);
            Genre genre = new Genre() { Name = "TestGenre" };
            List<Genre> list = new List<Genre>();
            genre = facade.GetGenreRepo().Add(genre);
            list.Add(genre);
            Movie movie = new Movie()
            {
                Name = "TestName",
                Genres = list,
                Price = 123,
                TrailerURL = "TestURL"
            };
            movie = facade.GetMovieRepo().Add(movie);
            Order order = new Order()
            {
                Customer = cus,
                Date = DateTime.Now
            };
            OrderMovie om = new OrderMovie() { Movie = movie, Order = order };
            om = facade.GetOrderMovieRepo().Add(om);

            order.OrderMovie.Add(om);

            order = facade.GetOrderRepo().Add(order);

            facade = new Facade();

            Assert.AreEqual(order.Customer.FirstName, facade.GetOrderRepo().Get(order.Id).Customer.FirstName);
        }
 public void Movie(int id, Movie movie)
 {
     movie.Id = id;
     if (!facade.GetMovieRepo().Update(movie))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
 public bool Update(Movie item)
 {
     if (item == null)
         throw new ArgumentNullException("Movie is null");
     if (Get(item.Id) == null)
         return false;
     using (Context mCon = new Context())
     {
         mCon.Movies.Attach(item);
         mCon.Entry(item).State = EntityState.Modified;
         mCon.SaveChanges();
     }
     return true;
 }
        public void Movie_get_movie_by_genre_working_test()
        {
            Facade facade = new Facade();

            Movie temp = new Movie() {  Name = "test", Price = 120d, TrailerURL = "test" };
            Movie temp2 = new Movie() {Name = "test2", Price = 120d, TrailerURL = "test" };
            temp = facade.GetMovieRepo().Add(temp);
            temp2 = facade.GetMovieRepo().Add(temp2);

            List<Movie> movies = new List<Movie>() { temp, temp2 };
            Genre genre = new Genre() { Name = "test", Movies = movies };

            genre = facade.GetGenreRepo().Add(genre);

            facade = new Facade();
            Assert.AreEqual(2, facade.GetMovieRepo().GetMovieByGenre(genre).ToList().Count);
        }
 public void Movie_add_throws_expection_on_movie_name_equals_null_test()
 {
     Facade facade = new Facade();
     Movie movie = new Movie();
     facade.GetMovieRepo().Add(movie);
 }
        public void Movie_update_updates_in_database_test()
        {
            Facade facade = new Facade();

            Genre genre = new Genre() { Name = "test" };
            List<Genre> list = new List<Genre>();
            genre = facade.GetGenreRepo().Add(genre);
            list.Add(genre);
            Movie temp = new Movie() { Genres = list, Name = "test", Price = 120d, TrailerURL = "test" };
            facade.GetMovieRepo().Add(temp);

            temp.Name = "Changed";

            facade = new Facade();
            Assert.IsTrue(facade.GetMovieRepo().Update(temp));

            facade = new Facade();
            Assert.AreEqual(facade.GetMovieRepo().Get(temp.Id).Name, "Changed");
        }
 public void Movie_update_return_false_on_movie_not_exists_test()
 {
     Movie temp = new Movie() { Id = -1 };
     Facade facade = new Facade();
     Assert.AreEqual(false, facade.GetMovieRepo().Update(temp));
 }
        public void Movie_remove_removing_from_database_test()
        {
            Movie temp = new Movie() { Name = "test", Price = 120d, TrailerURL = "test" };
            Facade facade = new Facade();
            temp = facade.GetMovieRepo().Add(temp);

            facade = new Facade();
            facade.GetMovieRepo().Remove(temp.Id);

            facade = new Facade();

            Assert.IsNull(facade.GetMovieRepo().Get(temp.Id));
        }
        public void Order_getmoviesbyorder_returns_multiple_right_movies_test()
        {
            Facade facade = new Facade();
            Movie movieOne = new Movie() { Year = DateTime.Now, Name = "mov1" };
            Movie movieTwo = new Movie() { Year = DateTime.Now, Name = "mov2" };
            List<OrderMovie> list = new List<OrderMovie>();
            list.Add(new OrderMovie() { Movie = movieOne });
            list.Add(new OrderMovie() { Movie = movieTwo });
            Order order = new Order()
            {
                Date = DateTime.Now,
                OrderMovie = list,
                Customer = new Customer() { BirthDate = DateTime.Now}
            };

            order = facade.GetOrderRepo().Add(order);

            facade = new Facade();
            Assert.GreaterOrEqual(facade.GetOrderRepo().GetMoviesByOrder(order).ToList().Count, 2);
            Assert.AreEqual(facade.GetOrderRepo().GetMoviesByOrder(order).FirstOrDefault().Name, movieOne.Name);
        }
        public void Movie_get_by_id_includes_genres_test()
        {
            Facade facade = new Facade();
            Genre genre = new Genre() { Name = "test" };
            List<Genre> list = new List<Genre>();
            genre = facade.GetGenreRepo().Add(genre);
            list.Add(genre);
            Movie temp = new Movie() { Genres = list, Name = "test", Price = 120d, TrailerURL = "test" };
            temp = facade.GetMovieRepo().Add(temp);

            facade = new Facade();
            Assert.AreEqual(genre.Name, facade.GetMovieRepo().Get(temp.Id).Genres.FirstOrDefault().Name);
            Assert.AreEqual(genre.Id, facade.GetMovieRepo().Get(temp.Id).Genres.FirstOrDefault().Id);
        }
        public void Movie_get_by_id_working_test()
        {
            Movie temp = new Movie() { Name = "test", Price = 120d, TrailerURL = "test" };
            Facade facade = new Facade();
            temp = facade.GetMovieRepo().Add(temp);

            facade = new Facade();
            Assert.AreEqual(temp.Name, facade.GetMovieRepo().Get(temp.Id).Name);
            Assert.AreEqual(temp.Price, facade.GetMovieRepo().Get(temp.Id).Price);
        }