Ejemplo n.º 1
0
 public void Setup()
 {
     rentals      = Substitute.For <IRentals>();
     sut          = new VideoStore(rentals);
     TestMovie    = new Movie("Transporter", MovieGenre.Action);
     TestCustomer = new Customer("1978-06-14", "Olle Svensson");
 }
Ejemplo n.º 2
0
 private static void GetMovies(IVideoStore store)
 {
     foreach (var movie in store.GetMovies())
     {
         Console.WriteLine($"{movie.Title} - {movie.Year} - {movie.Genre}");
     }
 }
Ejemplo n.º 3
0
        private static void RentAMovie(IVideoStore store)
        {
            Console.Write("Enter title: ");
            var title = Console.ReadLine();

            Console.WriteLine("Enter social security number: ");
            var ssn = Console.ReadLine();

            try
            {
                store.RentMovie(title, ssn);
                Console.WriteLine($"{title} rented");
            }
            catch (SSNFormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (MovieException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (CustomerException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (RentalException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 4
0
        public NewMovieUI(IVideoStore vs)
        {
            UIHelper.DrawTitle("   ADD A NEW MOVIE   ");

            Console.Write("Title: ");
            string title = Console.ReadLine();

            Console.Write("Genre: ");
            string genre = Console.ReadLine();
            int    year  = InputYear("Year (1900-2017): ");

            try
            {
                //TODO: without Movie instance less dependency.. send in three attributes instead
                vs.AddMovie(new Movie(title, genre, year));
                UIHelper.DrawLine(20);
                Console.WriteLine("");
                Console.WriteLine($"Confirmation: {title}, {genre}, {year} are registrated.");
            }
            catch (TooManyCopiesOfSameMovieException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (NotValidYearException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 5
0
        public NewCustomerUI(IVideoStore vs)
        {
            UIHelper.DrawTitle("   ADD A NEW CUSTOMER   ");

            Console.Write("Name: ");
            string name = Console.ReadLine();

            Console.Write("ID number (YYYY-MM-DD): ");
            string id = Console.ReadLine();

            try
            {
                vs.RegisterCustomer(name, id);
                UIHelper.DrawLine(20);
                Console.WriteLine("");
                Console.WriteLine($"Confirmation: {name} is registrated.");
            }
            catch (RegistratedCustomerException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (BadFormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (EmptyCustomerNameException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (EmptyCustomerIDException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 6
0
        public DlgRentalViewModel(IVideoStore videoStoreService, IVideoClubRules rules)
        {
            _videoStoreService = videoStoreService;
            _rules             = rules;

            Movies       = new ObservableCollection <MovieViewModel>();
            ChosenMovies = new ObservableCollection <MovieViewModel>();
            Users        = new ObservableCollection <UserViewModel>();

            _movies = _videoStoreService.GetMovies();

            foreach (var item in _movies)
            {
                if (item.NumOfCopies > 0)
                {
                    Movies.Add(new MovieViewModel(item));
                }
            }

            foreach (var item in _videoStoreService.GetUsers())
            {
                Users.Add(new UserViewModel(item));
            }

            OkCommand          = new RelayCommand(CompleteRental, () => IsInputValid);
            AddMovieCommand    = new RelayCommand(AddMovie, () => CanAddMovie && IsRentingAllowed);
            RemoveMovieCommand = new RelayCommand(RemoveMovie, () => _selectedMovie != null);

            WarningVisibility = Visibility.Hidden;
        }
Ejemplo n.º 7
0
 public void RenderPlainTextTest(IVideoStore implementation)
 {
     Assert.AreEqual(
         "Statement for BigCo\r\n" +
         "  Hamlet: $650.00 (55 seats)\r\n  As You Like It: $580.00 (35 seats)\r\n  Othello: $500.00 (40 seats)\r\n" +
         "Amount owed is $1,730.00\r\nYou earned 47 credits",
         implementation.Statement(_invoice, _plays));
 }
Ejemplo n.º 8
0
            public void FromJsonRenderPlainTextTest(IVideoStore implementation)
            {
                string invoiceJson = JsonSerializer.Serialize(_invoice);

                string playsJson = JsonSerializer.Serialize(_plays);

                // Prove that if we worked from JSON and converted into of objects we would get same result
                Assert.AreEqual(
                    implementation.Statement(_invoice, _plays),
                    implementation.Statement(
                        JsonSerializer.Deserialize <Invoice>(invoiceJson),
                        JsonSerializer.Deserialize <IImmutableDictionary <string, Play> >(playsJson)));
            }
Ejemplo n.º 9
0
        public RentMovieUI(IVideoStore vs)
        {
            UIHelper.DrawTitle("   RENT A MOVIE   ");

            Console.Write("Title: ");
            string title = Console.ReadLine();

            Console.Write("ID number (YYYY-MM-DD): ");
            string id = Console.ReadLine();

            try
            {
                vs.RentMovie(title, id);
                UIHelper.DrawLine(20);
                Console.WriteLine("");
                Console.WriteLine("Confirmation: Rental is registrated.");
            }
            catch (TooManyCopiesOfSameMovieException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (EmptyCustomerIDException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (BadFormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (NotRegistratedMovieException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (NotRegistratedCustomerException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (NoMoreCopiesInStoreException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (NoMoreCopiesToRentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 10
0
        private static void RegisterCustomer(IVideoStore store)
        {
            Console.Write("Enter your name: ");
            var name = Console.ReadLine();

            Console.Write("Enter SSN: ");
            var ssn = Console.ReadLine();

            try
            {
                store.RegisterCustomer(name, ssn);
            }
            catch (SSNFormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (CustomerException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 11
0
        private static void ReturnMovie(IVideoStore store)
        {
            Console.Write("Enter movie title: ");
            var title = Console.ReadLine();

            Console.Write("Enter SSN: ");
            var ssn = Console.ReadLine();

            try
            {
                store.ReturnMovie(title, ssn);
                Console.WriteLine($"{title} received");
            }
            catch (SSNFormatException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (RentalException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 12
0
        private static void AddMovie(IVideoStore store)
        {
            int year = 0;
            //string genre = null;
            var movie = new Movie();

            Console.Write("Enter movie title: ");
            movie.Title = Console.ReadLine();
            Console.Write("Production year: ");
            movie.Year = int.TryParse(Console.ReadLine(), out year) ? year : 2017;
            Console.Write("Enter movie genre: ");
            movie.Genre = Console.ReadLine();

            try
            {
                store.AddMovie(movie);
            }
            catch (MovieException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 13
0
        public MainUI(IVideoStore vs)
        {
            this.vs = vs;

            bool isContinue = true;

            while (isContinue)
            {
                DrawMenu();

                bool isValidChoice = false;
                int  choice        = 0;
                while (!isValidChoice)
                {
                    Console.Write("Select an option: ");
                    isValidChoice = int.TryParse(Console.ReadLine(), out choice);
                    isValidChoice = (isValidChoice && choice > 0 && choice < 6);

                    if (!isValidChoice)
                    {
                        Console.WriteLine("Not a valid option.");
                    }
                }

                HandleMenuChoice(choice);

                bool isValidChar = false;
                while (!isValidChar)
                {
                    string text = "Continue y/n? ";
                    Console.WriteLine();
                    UIHelper.DrawLine(text.Length);
                    Console.Write(text);
                    string cont = Console.ReadLine();
                    isValidChar = (cont.ToUpper() == "N" || cont.ToUpper() == "Y") ? true : false;
                    isContinue  = (isValidChar && cont.ToUpper() == "Y") ? true : false;
                }
            }
        }
Ejemplo n.º 14
0
        public MainWindowViewModel(IDialogService dialogService, IVideoStore videoStoreService, IVideoClubRules rules)
        {
            _dialogService     = dialogService;
            _videoStoreService = videoStoreService;
            _rules             = rules;

            Rentals = new ObservableCollection <RentalViewModel>();
            Users   = new ObservableCollection <UserViewModel>();
            DateOfRentCollection = new ObservableCollection <DateTimeViewModel>();
            DueDateCollection    = new ObservableCollection <DateTimeViewModel>();

            ResetFilterCommand      = new RelayCommand(ResetFilter, () => _currentFilter != Filter.NoFilter);
            ShowRentalDialogCommand = new RelayCommand(ShowRentalDialog);
            ReturnMovieCommand      = new RelayCommand(ReturnMovie, () => Rentals.Any(r => r.IsSelected));

            _rentals = _videoStoreService.GetRentals().OrderBy(r => r.Movie.Title);

            RefreshRentals();
            RefreshUsers();
            RefreshDatesOfRental();
            RefreshDueDates();
        }
Ejemplo n.º 15
0
 public SUTVideoStoreConsole(IVideoStore _videoStore, IRentals _rentals)
 {
     this._videoStore = _videoStore;
     this._rentals    = _rentals;
 }