예제 #1
0
        public void RentMovie(string movieTitle, string idNumber)
        {
            if (string.IsNullOrEmpty(movieTitle) || string.IsNullOrWhiteSpace(movieTitle))
            {
                throw new EmptyMovieTitleException("Missing title.");
            }

            CheckIDFormat(idNumber);

            var films = movies.Where(m => m.Title == movieTitle);

            if (films == null || films.Count() == 0)
            {
                throw new NotRegistratedMovieException("Movie is not in the store.");
            }

            var cust = customers.Where(c => c.IdNumber == idNumber);

            if (cust == null || cust.Count() == 0)
            {
                throw new NotRegistratedCustomerException("Customer is not in the register.");
            }

            //TODO: Refactor
            var tmp    = rentals.GetRentalsForTitle(movieTitle);
            var rented = tmp == null ? 0 : tmp.Count();

            if ((films.Count() - rented) <= 0)
            {
                throw new NoMoreCopiesInStoreException("All copies are rented.");
            }

            rentals.AddRental(movieTitle, idNumber);
        }
예제 #2
0
        public void RentMovie(string customermane, string movietile)
        {
            Customer thec = Customers.Find(x => x.Customer_name.Equals(customermane));

            if (thec == null)
            {
                throw new CustomerDoseNotExistExeption();
            }

            Movie them = Stock.FirstOrDefault(y => y.Title.Equals(movietile));

            if (them == null)
            {
                throw new MovieDoseNotExistExeption();
            }

            List <Rental> custrentals = Rentals.GetRentalsFor(thec.socialSecurityNumber);

            if (custrentals.Count == 3)
            {
                throw new NoMoreThan3Exeption();
            }

            foreach (Rental r in custrentals)
            {
                if (r.Movie_Title.Equals(movietile))
                {
                    throw new No2CoppiesForRenting();
                }
            }


            Rentals.AddRental(movietile, thec.socialSecurityNumber);
        }
예제 #3
0
        public void RentMovie(string movieTitle, string socialSecurityNumber)
        {
            //var checkC = _iRentals.GetRentalsFor(socialSecurityNumber);
            var checkCust  = Customers.Count(c => c.SSn == socialSecurityNumber);
            var checkMovie = Movies.Count(m => m.MovieTitle == movieTitle);

            if (checkMovie == 0)
            {
                throw new NullExceptionMovie();
            }
            else if (checkCust == 0)
            {
                throw new NullExceptionCustomerNotRegistered();
            }
            _iRentals.AddRental(movieTitle, socialSecurityNumber);
        }
예제 #4
0
        public void RentMovie(string movieTitle, string socialSecurityNumber)
        {
            if (string.IsNullOrEmpty(movieTitle))
            {
                throw new MovieException("Movie title is empty");
            }
            checkSsnFormat(socialSecurityNumber);
            if (!Customers.Any(x => x.Ssn.Equals(socialSecurityNumber)))
            {
                throw new CustomerException("Need to be registered");
            }
            if (!Movies.ContainsKey(movieTitle))
            {
                throw new MovieException("Movie doesn't exit");
            }

            Rentals.AddRental(movieTitle, socialSecurityNumber);
        }
예제 #5
0
        public void RentMovie(string movieTitle, string socialSecurityNumber)
        {
            var customer = Listcustomers.FirstOrDefault(x => x.SSN == socialSecurityNumber);
            var movie    = ListMovies.FirstOrDefault(x => x.Title == movieTitle);

            if (customer == null)
            {
                throw new NoCustomerInOurSystem();
            }
            //Om filmen inte existerar
            else if (movie == null)
            {
                //throw exception
                throw new CantRentNonExistingMovie();
            }
            //if (!ListMovies.Any(x => x.Title == movieTitle))
            //{

            //}
            rentals.AddRental(movieTitle, socialSecurityNumber);
        }
예제 #6
0
        public void CanAddRental()
        {
            sut.AddRental("Amelie", "1975-11-07");
            sut.AddRental("Vukk", "1975-11-07");

            var result = sut.GetRentalsFor("1975-11-07");

            Assert.That(result.Count == 2);
        }
예제 #7
0
        public void TrueIfAbleToAddRental()
        {
            sut.AddRental(TestMovie.Title, TestCustomer.SSN);
            var rentals = sut.GetRentalsFor(TestCustomer.SSN);

            Assert.AreEqual(1, rentals.Count);
        }
예제 #8
0
        public void TrueIfAbleToAddRental()
        {
            sut.AddRental("Die hard", "19880606");
            var rentals = sut.GetRentalsFor("19880606");

            Assert.AreEqual(1, rentals.Count);
        }