public void Customer(int id, Customer customer)
 {
     customer.Id = id;
     if (!facade.GetCustomerRepo().Update(customer))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
 public IEnumerable<Order> GetOrdersByCustomer(Customer item)
 {
     if (item == null)
         throw new ArgumentNullException("Customer can not be null");
     using (Context mCon = new Context())
     {
         return mCon.Orders.Include("Customer").Include("OrderMovie").Where(x => x.Customer.Id == item.Id).ToList();
     }
 }
        public HttpResponseMessage Customer(Customer item)
        {
            item = facade.GetCustomerRepo().Add(item);
            var response = Request.CreateResponse<Customer>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
        public void Login_get_customer_by_login_returns_right_customer_test()
        {
            Facade facade = new Facade(); Customer cusOne = new Customer()
            {
                FirstName = "Jonas Olesen",
                Address = "Møbelvej 3",
                BirthDate = DateTime.Now.AddYears(-20),
                Email = "*****@*****.**",
                PhoneNumber = 22755692
            };
            cusOne = facade.GetCustomerRepo().Add(cusOne);

            Login login = new Login() { Customer = cusOne, Password = "******", Username = "******"+Id++ };
            login = facade.GetLoginRepo().Add(login);

            Assert.AreEqual(facade.GetLoginRepo().GetCustomerByLoginUsername(login.Username).FirstName, login.Customer.FirstName);
        }
        public void Customer_get_all_return_many_test()
        {
            Customer temp = new Customer()
            {
                FirstName = "Test Olesen",
                Address = "Testvej 3",
                BirthDate = DateTime.Now.AddYears(-1),
                Email = "*****@*****.**",
                PhoneNumber = 12345678
            };

            Facade facade = new Facade();
            facade.GetCustomerRepo().Add(temp);
            facade.GetCustomerRepo().Add(temp);

            facade = new Facade();
            Assert.GreaterOrEqual(facade.GetCustomerRepo().GetAll().ToList().Count,2);
        }
        public void Customer_added_on_call_test()
        {
            Customer temp = new Customer()
            {
                FirstName = "Test Olesen",
                Address = "Testvej 3",
                BirthDate = DateTime.Now.AddYears(-1),
                Email = "*****@*****.**",
                PhoneNumber = 12345678
            };

            Facade facade = new Facade();
            temp = facade.GetCustomerRepo().Add(temp);

            facade = new Facade();
            Assert.IsNotNull(facade.GetCustomerRepo().Get(temp.Id));
            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).FirstName, temp.FirstName);
        }
        public void Login_add_creates_on_call_using_get_test()
        {
            Facade facace = new Facade();
            Customer cusOne = new Customer()
            {
                FirstName = "Jonas Olesen",
                Address = "Møbelvej 3",
                BirthDate = DateTime.Now.AddYears(-20),
                Email = "*****@*****.**",
                PhoneNumber = 22755692
            };
            cusOne = facace.GetCustomerRepo().Add(cusOne);
            Login login = new Login() { Customer = cusOne, Password = "******", Username = "******" + Id++ };
            login = facace.GetLoginRepo().Add(login);

            facace = new Facade();
            Assert.AreEqual(facace.GetLoginRepo().Get(login.Username).Password, login.Password);
        }
        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 Customer_get_by_id_working_test()
        {
            Customer temp = new Customer()
            {
                FirstName = "Test Olesen",
                Address = "Testvej 3",
                BirthDate = DateTime.Now.AddYears(-1),
                Email = "*****@*****.**",
                PhoneNumber = 12345678
            };

            Facade facade = new Facade();
            temp = facade.GetCustomerRepo().Add(temp);

            facade = new Facade();

            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).FirstName, temp.FirstName);
            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).Address, temp.Address);
            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).Email, temp.Email);
            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).PhoneNumber, temp.PhoneNumber);
        }
        public void Login_getall_returns_multiple_test()
        {
            Facade facade = new Facade();
            Customer cusOne = new Customer()
            {
                FirstName = "Jonas Olesen",
                Address = "Møbelvej 3",
                BirthDate = DateTime.Now.AddYears(-20),
                Email = "*****@*****.**",
                PhoneNumber = 22755692
            };
            cusOne = facade.GetCustomerRepo().Add(cusOne);

            Login login = new Login() { Customer = cusOne, Password = "******", Username = "******"+Id++ };
            facade.GetLoginRepo().Add(login);
            Login login2 = new Login() { Customer = cusOne, Password = "******", Username = "******"+Id++ };
            facade.GetLoginRepo().Add(login2);

            facade = new Facade();
            Assert.GreaterOrEqual(facade.GetLoginRepo().GetAll().ToList().Count, 2);
        }
        public void Customer_remove_removes_from_database_test()
        {
            Customer temp = new Customer()
            {
                FirstName = "Test Olesen",
                Address = "Testvej 3",
                BirthDate = DateTime.Now.AddYears(-1),
                Email = "*****@*****.**",
                PhoneNumber = 12345678
            };

            Facade facade = new Facade();
            temp = facade.GetCustomerRepo().Add(temp);

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

            facade = new Facade();
            Assert.IsNull(facade.GetCustomerRepo().Get(temp.Id));
        }
        public void Customer_update_works_test()
        {
            Customer temp = new Customer()
            {
                FirstName = "Test Olesen",
                Address = "Testvej 3",
                BirthDate = DateTime.Now.AddYears(-1),
                Email = "*****@*****.**",
                PhoneNumber = 12345678
            };

            Facade facade = new Facade();
            temp = facade.GetCustomerRepo().Add(temp);

            facade = new Facade();
            temp.FirstName = "Changed";

            Assert.IsTrue(facade.GetCustomerRepo().Update(temp));

            facade = new Facade();
            Assert.AreEqual(facade.GetCustomerRepo().Get(temp.Id).FirstName, "Changed");
        }
        public void Order_getorderbycustomer_returns_multiple_test()
        {
            Facade facade = new Facade();
            Customer cus = new Customer()
            {
                BirthDate = DateTime.Now,
                FirstName = "jonas",
                Address ="hest",
                Email = "hest"
            };
            cus = facade.GetCustomerRepo().Add(cus);
            Order orderOne = new Order() { Customer = cus, Date = DateTime.Now, OrderMovie = new List<OrderMovie>() };
            Order orderTwo = new Order() { Customer = cus, Date = DateTime.Now, OrderMovie = new List<OrderMovie>() };

            orderOne = facade.GetOrderRepo().Add(orderOne);
            orderTwo = facade.GetOrderRepo().Add(orderTwo);

            facade = new Facade();

            Assert.GreaterOrEqual(facade.GetOrderRepo().GetOrdersByCustomer(cus).ToList().Count, 2);
        }
        public void Login_remove_removes_from_db_test()
        {
            Facade facade = new Facade();
            Customer cusOne = new Customer()
            {
                FirstName = "Jonas Olesen",
                Address = "Møbelvej 3",
                BirthDate = DateTime.Now.AddYears(-20),
                Email = "*****@*****.**",
                PhoneNumber = 22755692
            };
            cusOne = facade.GetCustomerRepo().Add(cusOne);

            Login login = new Login() { Customer = cusOne, Password = "******", Username = "******" + Id++ };
            login = facade.GetLoginRepo().Add(login);

            facade = new Facade();
            facade.GetLoginRepo().Remove(login.Username);

            facade = new Facade();
            Assert.IsNull(facade.GetLoginRepo().Get(login.Username));
        }